Dual Booting NetBSD-stable and NetBSD-current
Disklabels are Not Subservient
I searched everywhere for an example of how to dual-boot NetBSD and NetBSD, but couldn't find anything on the topic. Either it was a trade secret of an elite collection of hard-core insiders, or it was too simple to require documentation. In the end it was simple, but definately not trivial.
In FreeBSD, BSD disklabels are grouped logically inside of x86 BIOS partitions, so accessing information on another BIOS-partition/disklabel-partition is as easy as specifyting the slice (BIOS partition) and partition (BSD disklabel):
/dev/ad0s1b # First Disk, First Slice, Second Partition /dev/ad0s2a # First Disk, Second Slice, First Partition
Compare this with NetBSD/OpenBSD's device references:
/dev/wd0b # First Disk, Partition B /dev/ad0e # First Disk, Partition E
It doesn't seem that BIOS partitions are even recognized in this environment. When I started defining disklabels manually, it also became apparent that the order of the partition letters does not have to reflect the order on the disk. Partition Z can also be the first or only partition defined in the disklabel.
Great, Let's Forget about Slices
Slices aren't required by NetBSD itself, but i386 bootmanagers only know about BIOS partitions, so dual-booting requires 2 partitions. On my laptop I set up all four partitions: 1) NetBSD-release 2) NetBSD-current 3) FreeBSD-release 4) Data. I didn't have to set up a fourth slice for data, but it makes the partition automatically available to FreeBSD. From the perspective of NetBSD the Data slice is just (also?) the last partition on the disk.
Planning
You can make this very complicated if you want to, but on a personal computer I would keep this simple. I prefer to define two FFSv2 partitions for each NetBSD install. I recommend sketching it out on paper so you know what your goal is first.
slice 1 / 470M
/usr 5.8G
slice 2 / 470M
/usr 5.7G
The swap partition is second by tradition, and I think it's a good one, so I'll put that one after the first NetBSD root partition. The letter c is reserved for whole disk and only in NetBSD d is for netbsd disk, which makes my first /usr mount-point land on e.
slice 1 a / 470M
b swap 768M
c whole disk 20G
d netbsd disk 20G
e /usr 5.8G
slice 2 f / 470M
g /usr 5.7G
slice 3 h freebsd 2G
slice 4 i /home ~3.2G
The last slice will occupy all of the remaining space, wich worked out to be between 3 and 3-1/2 G when I worked it out on paper.
We only need one swap partition on this disk because both installations of NetBSD will share the same disklabel, and FreeBSD is capable of mounting any drive/slice/partition. I could get away with less swap--the BSD's don't dig into swap without cause as readily as Linux seems too.Before running fdisk, add up the lengths of all the partitions within each slice.
slice 1 7268MB slice 2 6470MB slice 3 2000MB slice 4 ~3300MB
After Running fdisk -u wd0, this is what I ended up with:
Disk: /dev/rwd0d
NetBSD disklabel disk geometry:
cylinders: 38760, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 39070080
BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 39070080
Partition table:
0: NetBSD (sysid 169)
bootmenu: NetBSD
start 63, size 14885136 (7268 MB, Cyls 0-926/143/1)
1: NetBSD (sysid 169)
bootmenu: NetBSD2
start 14885199, size 13250160 (6470 MB, Cyls 926/143/1-1751/88/1)
2: FreeBSD or 386BSD or old NetBSD (sysid 165)
bootmenu: FreeBSD
start 28135359, size 4096512 (2000 MB, Cyls 1751/88/1-2006/87/1)
3: NetBSD (sysid 169)
bootmenu: FreeBSD
start 32231871, size 6838209 (3339 MB, Cyls 2006/87/1-2432)
Bootselector enabled, timeout 10 seconds.
Editing the Disklabel
Everything in your disklabel should be calculated in secors (512 bytes) since that is the basic storage unit of fixed disks. If you're trying to dual-boot Linux and NetBSD this is more difficult because Linux expects partitions to start and end on cylinder bounderies. BSD doesn't care, so just add up the secors listed by fdisk to get start, end, and size info in sectors.
slice start end size ----- --------- ---------- ----------- 0: 63 14885199 (14885136 ) 1: 14885199 28135359 (13250160 ) 2: 28135359 32231871 (4096512 ) 3: 32231871 39070080 (6838209 )
From here you you just have to do a lot of number crunching. My finished disklabel looks like this:
# disklabel -i -I wd0 partition> P 16 partitions: # size offset fstype [fsize bsize cpg/sgs] a: 1024128 63 4.2BSD 1024 8192 46552 # (Cyl. 0*- 1016*) b: 1573488 1024191 swap # (Cyl. 1016*- 2577*) c: 14885136 63 unused 0 0 # (Cyl. 0*- 14767*) d: 39070080 0 unused 0 0 # (Cyl. 0 - 38759) e: 12287520 2597679 4.2BSD 1024 8192 46544 # (Cyl. 2577*- 14767*) f: 962560 14885199 4.2BSD 1024 8192 43760 # (Cyl. 14767*- 15721*) g: 12287600 15847759 4.2BSD 2048 16384 27552 # (Cyl. 15721*- 27912*) h: 4096512 28135359 4.2BSD 2048 16384 27568 # (Cyl. 27912*- 31976*) i: 6838209 32231871 4.2BSD 2048 16384 24448 # (Cyl. 31976*- 38759)
Notice that almost none of this is lining up on cylinder bounderies. That's fine with me--this excercise required enough number crunching as it is. You do not have to reboot after editing disklabels; you can go on ahead and run newfs to format each partition.
Installing Your Second Copy
Before you copy or unpack your second installation, mount the second root partition and copy /netbsd to it. You should be able to boot that kernel by choosing choosing 2 from the boot menu. If that works, then go on ahead and set up your mountpoints and begin copying. Here is /dev/wd0a/etc/fstab on my laptop:
/dev/wd0a / ffs rw,softdep 1 1 /dev/wd0b none swap sw 0 0 /dev/wd0b /tmp mfs rw,-s=263088 /dev/wd0e /usr ffs rw,softdep 1 2 /dev/wd0f /mnt/current ffs rw,softdep 1 2 /dev/wd0g /mnt/current/usr ffs rw,softdep 1 2 /dev/wd0i /home ffs rw,softdep 1 2 kernfs /kern kernfs rw ...
Mount the new file systems using mount -a. The easiest way to get started is just to copy your existing installation with pax.
# pax -rw -p e -x / /mnt/current # pax -rw -p e -x /usr /mnt/current
The parameter -p e instructs pax to copy every special attirbute that it can, and -x prevents it from traversing file systems.
Now edit /mnt/current/etc/fstab so that it looks something like this:
/dev/wd0a /mnt/release/ ffs rw,softdep 1 1 /dev/wd0b none swap sw 0 0 /dev/wd0b /tmp mfs rw,-s=263088 /dev/wd0e /mnt/release/usr ffs rw,softdep 1 2 /dev/wd0f / ffs rw,softdep 1 2 /dev/wd0g /usr ffs rw,softdep 1 2 /dev/wd0i /home ffs rw,softdep 1 2 kernfs /kern kernfs rw ...
Now you can make your new mount points for /mnt/release. I added a "c" for current and "r" for release to my hostname, but you don't have to.