Subject: Changing the NetBSD partition identifier ...
To: None <port-i386@NetBSD.ORG>
From: Robert.V.Baron <rvb@gluck.coda.cs.cmu.edu>
List: port-i386
Date: 02/13/1998 09:18:00
Occasionally I have the need to run two different OS's on one machine
that both use the same 0xa5 (165) to identify the DOS partition, (for
example NetBSD 1.2 and NetBSD 1.3 or NetBSD and FreeBSD). Below I have
included patches that let 0xa3 (163) be the "prefered" partition for
NetBSD 1.3. The booter and label code search first for a 163 paritition
and then if they fail, for a 165 partition.
To use it you:
1. go to arch/i386/stand and make install.
2. installboot with this new boot.
3. build a new kernel and install it.
4. Now you must change the partition from 165 to 163.
4a. I've rebooted to a dos floppy with pfdisk and editted the MBR.
4b. I presume that fdisk should work equally well.
Maybe people will find this feature useful and possibly include it in -current
Index: src/sys/arch/i386/i386/disksubr.c
diff -c src/sys/arch/i386/i386/disksubr.c:1.1.1.1 src/sys/arch/i386/i386/disksubr.c:1.2
*** src/sys/arch/i386/i386/disksubr.c:1.1.1.1 Thu Jun 26 07:20:13 1997
--- src/sys/arch/i386/i386/disksubr.c Fri Feb 13 04:10:01 1998
***************
*** 123,128 ****
--- 123,151 ----
pp->p_fstype = FS_MSDOS;
}
+ }
+ for (i = 0, dp = osdep->dosparts; i < NDOSPART; i++, dp++) {
+ /* is this ours? */
+ if (dp->dp_size && dp->dp_typ == 0xa3
+ && dospartoff == 0) {
+ /* need sector address for SCSI/IDE,
+ cylinder for ESDI/ST506/RLL */
+ dospartoff = dp->dp_start;
+ cyl = DPCYL(dp->dp_scyl, dp->dp_ssect);
+
+ /* update disklabel with details */
+ lp->d_partitions[2].p_size =
+ dp->dp_size;
+ lp->d_partitions[2].p_offset =
+ dp->dp_start;
+ lp->d_ntracks = dp->dp_ehd + 1;
+ lp->d_nsectors = DPSECT(dp->dp_esect);
+ lp->d_secpercyl =
+ lp->d_ntracks * lp->d_nsectors;
+ }
+ }
+ if (!dospartoff)
+ for (i = 0, dp = osdep->dosparts; i < NDOSPART; i++, dp++) {
/* is this ours? */
if (dp->dp_size && dp->dp_typ == DOSPTYP_386BSD
&& dospartoff == 0) {
***************
*** 309,315 ****
/* XXX how do we check veracity/bounds of this? */
bcopy(bp->b_data + DOSPARTOFF, dp,
NDOSPART * sizeof(*dp));
! for (i = 0; i < NDOSPART; i++, dp++)
/* is this ours? */
if (dp->dp_size && dp->dp_typ == DOSPTYP_386BSD
&& dospartoff == 0) {
--- 332,349 ----
/* XXX how do we check veracity/bounds of this? */
bcopy(bp->b_data + DOSPARTOFF, dp,
NDOSPART * sizeof(*dp));
! for (i = 0; i < NDOSPART; i++, dp++) {
! /* is this ours? */
! if (dp->dp_size && dp->dp_typ == 0xa3
! && dospartoff == 0) {
! /* need sector address for SCSI/IDE,
! cylinder for ESDI/ST506/RLL */
! dospartoff = dp->dp_start;
! cyl = DPCYL(dp->dp_scyl, dp->dp_ssect);
! }
! }
! if (!dospartoff)
! for (i = 0, dp = osdep->dosparts; i < NDOSPART; i++, dp++) {
/* is this ours? */
if (dp->dp_size && dp->dp_typ == DOSPTYP_386BSD
&& dospartoff == 0) {
***************
*** 318,323 ****
--- 352,358 ----
dospartoff = dp->dp_start;
cyl = DPCYL(dp->dp_scyl, dp->dp_ssect);
}
+ }
}
}
Index: src/sys/arch/i386/stand/lib/biosdisk.c
diff -c src/sys/arch/i386/stand/lib/biosdisk.c:1.1.1.1 src/sys/arch/i386/stand/lib/biosdisk.c:1.2
*** src/sys/arch/i386/stand/lib/biosdisk.c:1.1.1.1 Mon Oct 13 08:25:56 1997
--- src/sys/arch/i386/stand/lib/biosdisk.c Fri Feb 13 04:10:02 1998
***************
*** 195,205 ****
}
dptr = (struct dos_partition *) & d->buf[DOSPARTOFF];
sector = -1;
! for (i = 0; i < NDOSPART; i++, dptr++)
! if (dptr->dp_typ == DOSPTYP_NETBSD) {
sector = dptr->dp_start;
break;
}
if (sector == -1) {
/*
* One of two things:
--- 195,215 ----
}
dptr = (struct dos_partition *) & d->buf[DOSPARTOFF];
sector = -1;
! for (i = 0; i < NDOSPART; i++, dptr++) {
! if (dptr->dp_typ == 0xa3) {
sector = dptr->dp_start;
break;
}
+ }
+ if (sector == -1) {
+ dptr = (struct dos_partition *) & d->buf[DOSPARTOFF];
+ for (i = 0; i < NDOSPART; i++, dptr++) {
+ if (dptr->dp_typ == DOSPTYP_NETBSD) {
+ sector = dptr->dp_start;
+ break;
+ }
+ }
+ }
if (sector == -1) {
/*
* One of two things:
Index: src/sys/arch/i386/stand/lib/crt/bootsect/start_bootsect.S
diff -c src/sys/arch/i386/stand/lib/crt/bootsect/start_bootsect.S:1.1.1.1 src/sys/arch/i386/stand/lib/crt/bootsect/start_bootsect.S:1.2
*** src/sys/arch/i386/stand/lib/crt/bootsect/start_bootsect.S:1.1.1.1 Thu Sep 18 07:54:12 1997
--- src/sys/arch/i386/stand/lib/crt/bootsect/start_bootsect.S Fri Feb 13 04:10:02 1998
***************
*** 70,75 ****
--- 70,76 ----
NUMPART = 4 # number of partitions in partition table
PARTSZ = 16 # each partition table entry is 16 bytes
BSDPART = 0xA5 # value of boot_ind, means bootable partition
+ BSD3PART = 0xA3 # value of boot_ind, means bootable partition
BOOTABLE = 0x80 # value of boot_ind, means bootable partition
.text
***************
*** 130,135 ****
--- 131,152 ----
movl $PARTSTART, %ebx
data32
movl $NUMPART, %ecx
+ again3:
+ addr32
+ movb %es:4(%ebx), %al
+ cmpb $BSD3PART, %al
+ data32
+ je found
+ data32
+ addl $PARTSZ, %ebx
+ data32
+ loop again3
+
+ /***# find the first 386BSD partition *****/
+ data32
+ movl $PARTSTART, %ebx
+ data32
+ movl $NUMPART, %ecx
again:
addr32
movb %es:4(%ebx), %al
***************
*** 140,145 ****
--- 157,163 ----
addl $PARTSZ, %ebx
data32
loop again
+
data32
movl $enoboot, %esi
data32