From 1a05cb57ed14273ec2b6e28de88e4e094463184e Mon Sep 17 00:00:00 2001 From: krw Date: Sun, 11 Jun 2023 14:00:04 +0000 Subject: [PATCH] No need to check for DTYPE_FLOPPY. If there is neither a GPT nor an MBR then install biosboot in sector 0. Without the check for DTYPE_FLOPPY there is no need for FSDISKTYPE=floppy3 and therefore flip the last two Makefiles to the "echo '/ *' | disklabel -wAT-" idiom. Feedback/fix from kn@ --- distrib/amd64/ramdiskA/Makefile | 5 ++-- distrib/i386/ramdisk/Makefile | 5 ++-- usr.sbin/installboot/i386_installboot.c | 35 +++++++++++++++---------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/distrib/amd64/ramdiskA/Makefile b/distrib/amd64/ramdiskA/Makefile index b4e5a950f73..c060ece7e71 100644 --- a/distrib/amd64/ramdiskA/Makefile +++ b/distrib/amd64/ramdiskA/Makefile @@ -1,8 +1,7 @@ -# $OpenBSD: Makefile,v 1.20 2023/04/28 18:14:59 krw Exp $ +# $OpenBSD: Makefile,v 1.21 2023/06/11 14:00:04 krw Exp $ FS= floppy${OSrev}.img FSSIZE= 2880 -FSDISKTYPE= floppy3 MOUNT_POINT= /mnt MTREE= ${UTILS}/mtree.conf RAMDISK= RAMDISK @@ -17,7 +16,7 @@ all: ${FS} ${FS}: bsd.gz dd if=/dev/zero of=${FS} bs=512 count=${FSSIZE} vnconfig -v ${FS} > vnd - disklabel -w `cat vnd` ${FSDISKTYPE} + echo '/ *' | disklabel -wAT- `cat vnd` newfs -O 1 -m 0 -o space -i 524288 -c ${FSSIZE} -b 4096 -f 512 /dev/r`cat vnd`a mount /dev/`cat vnd`a ${MOUNT_POINT} objcopy -S -R .comment ${DESTDIR}/usr/mdec/fdboot ${.OBJDIR}/boot diff --git a/distrib/i386/ramdisk/Makefile b/distrib/i386/ramdisk/Makefile index db488151a16..46321bb1088 100644 --- a/distrib/i386/ramdisk/Makefile +++ b/distrib/i386/ramdisk/Makefile @@ -1,8 +1,7 @@ -# $OpenBSD: Makefile,v 1.21 2023/04/28 18:14:59 krw Exp $ +# $OpenBSD: Makefile,v 1.22 2023/06/11 14:00:04 krw Exp $ FS= floppy${OSrev}.img FSSIZE= 2880 -FSDISKTYPE= floppy3 MOUNT_POINT= /mnt MTREE= ${UTILS}/mtree.conf RAMDISK= RAMDISK @@ -15,7 +14,7 @@ all: ${FS} ${FS}: bsd.gz dd if=/dev/zero of=${FS} bs=512 count=${FSSIZE} vnconfig -v ${FS} > vnd - disklabel -w `cat vnd` ${FSDISKTYPE} + echo '/ *' | disklabel -wAT- `cat vnd` newfs -O 1 -m 0 -o space -i 524288 -c ${FSSIZE} -b 4096 -f 512 /dev/r`cat vnd`a mount /dev/`cat vnd`a ${MOUNT_POINT} objcopy -S -R .comment ${DESTDIR}/usr/mdec/fdboot ${.OBJDIR}/boot diff --git a/usr.sbin/installboot/i386_installboot.c b/usr.sbin/installboot/i386_installboot.c index 110530186c3..277ef92f848 100644 --- a/usr.sbin/installboot/i386_installboot.c +++ b/usr.sbin/installboot/i386_installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i386_installboot.c,v 1.45 2023/04/26 18:04:21 kn Exp $ */ +/* $OpenBSD: i386_installboot.c,v 1.46 2023/06/11 14:00:04 krw Exp $ */ /* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */ /* @@ -196,7 +196,7 @@ write_bootblocks(int devfd, char *dev, struct disklabel *dl) { struct stat sb; u_int8_t *secbuf; - u_int start = 0; + u_int start; /* Write patched proto bootblock(s) into the superblock. */ if (fstat(devfd, &sb) == -1) @@ -214,18 +214,15 @@ write_bootblocks(int devfd, char *dev, struct disklabel *dl) } /* - * Find OpenBSD partition. Floppies are special, getting an - * everything-in-one /boot starting at sector 0. + * Find bootstrap sector. */ - if (dl->d_type != DTYPE_FLOPPY) { - start = findopenbsd(devfd, dl); - if (start == (u_int)-1) - errx(1, "no OpenBSD partition"); - } - - if (verbose) + start = findopenbsd(devfd, dl); + if (verbose) { + if (start == 0) + fprintf(stderr, "no MBR, "); fprintf(stderr, "%s will be written at sector %u\n", stage1, start); + } if (start + (blksize / dl->d_secsize) > BOOTBIOS_MAXSEC) warnx("%s extends beyond sector %u. OpenBSD might not boot.", @@ -437,6 +434,12 @@ rmdir: exit(1); } +/* + * a) For media w/o an MBR use sector 0. + * b) For media with an MBR and an OpenBSD (A6) partition use the first + * sector of the OpenBSD partition. + * c) For media with an MBR and no OpenBSD partition error out. + */ u_int findopenbsd(int devfd, struct disklabel *dl) { @@ -453,7 +456,7 @@ again: if (verbose) fprintf(stderr, "Traversed more than %d Extended Boot " "Records (EBRs)\n", DOS_MAXEBR); - return ((u_int)-1); + goto done; } if (verbose) @@ -469,9 +472,12 @@ again: bcopy(secbuf, &mbr, sizeof(mbr)); free(secbuf); - if (mbr.dmbr_sign != DOSMBR_SIGNATURE) + if (mbr.dmbr_sign != DOSMBR_SIGNATURE) { + if (mbroff == DOSBBSECTOR) + return 0; errx(1, "invalid boot record signature (0x%04X) @ sector %u", mbr.dmbr_sign, mbroff); + } nextebr = 0; for (i = 0; i < NDOSPART; i++) { @@ -505,7 +511,8 @@ again: goto again; } - return ((u_int)-1); + done: + errx(1, "no OpenBSD partition"); } /* -- 2.20.1