ONLamp.com    
 Published on ONLamp.com (http://www.onlamp.com/)
 See this if you're having trouble printing code examples


Big Scary Daemons Dual-Booting FreeBSD and FreeBSD

by Michael W. Lucas
05/16/2002

I'm one of those people who is sacrificing a small portion of their mental health to the greater good, by testing FreeBSD-current. Now that we're approaching FreeBSD 5.0, the FreeBSD Project needs people to test -current in a wide variety of installations and environments.

This leads to a conflict between supporting FreeBSD and supporting my family. I need a working UNIX system at all times. While I can make -current work after some skull sweat, I don't always have the time to do this. If I go to work one morning and say "Uh, my laptop is completely hosed because FreeBSD-current went sideways on me last night," the client will hear "Michael's taking the day off." This means that I don't get paid, and this is bad. A quick reinstall isn't the answer, as I need to have my data as well as my OS.

Backing up my data each night is a pain, and usually overkill. I decided to dual-boot FreeBSD-stable and FreeBSD-current. If -current blows up, I can boot into -stable and get on with life. I need to do this in such a way that I can easily reinstall both operating systems without risking my personal data. This is actually easy enough to do, if you spend a little time planning beforehand. While this won't eliminate the need for backups, it can make life just a little more sane.

First, we need to be sure that the system can actually run both -stable and -current. I've had laptops that would not run particular versions of -current, and it's possible that a system might not run some versions of -release. So do a test boot of both the -current and the -stable install media. If we can reach sysinstall with both sets of install media, consider the machine usable.

My system has a rather large hard drive. I'm dedicating 5GB each to -stable and -current, and the remainder to my personal data. I also want an MSDOS suspend partition. (While I've never gotten this particular laptop's video card to resume after a suspend, I keep hoping.) So, my plan is to divide up the hard drive into the following slices:

ad0s1 MSDOS suspend partition (400MB)
ad0s2 -stable install partition (5GB)
ad0s3 -current install partition (5GB)
ad0s4 shared data (everything else)

Now that we have this, we're ready to begin. Install -stable first. When you get to the slice creation menu, create all four of the slices decided on earlier. Install -stable entirely in ad0s2. Tell sysinstall to create a single large partition inside ad0s4, and mount it as /shared.

I recommend not installing any further ports or packages or customizing the install at all. Get the system up and booting both operating systems before wasting any time customizing them.

When finished, boot into -stable. Be sure it works before proceeding. Once you can get a -stable command prompt, reboot with the -current installation media. The install processes for -stable and -current are nearly identical, so you shouldn't have any trouble.

Related Reading

Free as in Freedom [Paperback]
Richard Stallman's Crusade for Free Software
By Sam Williams

When you get to the portion where you can create mount points, be sure to ignore the -stable and shared partitions! I tried to mount these and not newfs them, to save me the trouble of editing /etc/fstab later, but a typo resulted in sysinstall newfs-ing the existing -stable installation. It's much simpler to be safe. You can re-use the existing swap space in the -stable partition, however.

Be sure to install the FreeBSD Boot Manager! This will let you decide which OS to boot into.

Once the -current install finishes, reboot your computer. You should get the boot loader screen, offering you a choice between FreeBSD versions. Confirm that both -stable and -current boot and run, and you're all set!

Now you can do some specific customizations. Install your preferred software (X, window managers, IDEs, etc.) separately under each version. For maximum stability, don't use -stable software under -current. And you won't have much luck at all running -current software under -stable.

I might have to format and reinstall my -current installation at any time, so I don't want to keep any personal data there. My home directory needs to be installed under /shared. I usually create the home directory as /shared/home/username.

If you have a large shared partition, you can take advantage of it to move a variety of files there. For example, the Ports Collection is identical in -stable and -current. You could install it as /shared/usr/ports, and save a large chunk of disk space. You'll have to be certain to do a make clean. Similarly, the massive Linux compatibility ports are identical; you can move them to /shared/usr/compat. Finally, /tmp can be moved to /shared/tmp.

For all of these, you'll want to use symlinks to map the old locations to the new ones.

Finally, you might want to edit /etc/fstab on both installs to include the other. Here's what my system looks like now when I boot -current.

# df -h
Filesystem    Size   Used  Avail Capacity  Mounted on
/dev/ad0s3a   197M    65M   117M    36%    /
devfs         1.0K   1.0K     0B   100%    /dev
/dev/ad0s3f   4.5G   2.2G   2.0G    52%    /usr
/dev/ad0s3e   246M    11M   215M     5%    /var
/dev/ad0s2a   246M    39M   187M    17%    /stable
/dev/ad0s2f   4.4G   1.6G   2.5G    39%    /stable/usr
/dev/ad0s2e   246M    27M   200M    12%    /stable/var
/dev/ad0s4e    26G   8.0G    16G    33%    /shared
#

After this, I'm ready to work no matter what happens to -current today. I can reformat and reinstall either operating system with impunity, because my data is stored elsewhere on the disk. The only way I should have to recover my data from backup is if someone introduces a filesystem bug. That's quite rare compared to temporary problems where, for example, X won't start. And best of all, I can wait until the weekend to fix the problem rather than missing either work or dinner.

Michael W. Lucas


Read more Big Scary Daemons columns.

Return to the BSD DevCenter.


Copyright © 2009 O'Reilly Media, Inc.