FreeBSD and ATA disks
October 21, 2006 (as amended)

(this issue might apply to the other BSDs, Linux, Solaris etc as well)

FreeBSD automatically names ATA hard disks like this:

primarymaster->drive 0ad0
primaryslave->drive 1ad1
secondarymaster->drive 2ad2
secondaryslave->drive 3ad3

On boot, the FreeBSD boot loader tries to mount the root partition; the location of the root partition is indexed using the drive number it is installed on (for example, ad0s1a or ad2s1a). However in the following circumstances, the FreeBSD boot loader will be unable to locate the root partition, and display a 'trying to mount root' message, followed by a prompt to mount manually:

These actions cause the FreeBSD drive to be renumbered. As the root partition is indexed by drive number, if the drive number changes, the root partition will no longer be where FreeBSD expects it to be.

The fix is as follows:

  1. boot into a live filesystem

    1. boot from installation CD (note: in FreeBSD 8, boot from the live filesystem CD, not the installation CD, this is a separate download)
    2. from the first screen, select option 1 - boot FreeBSD (default)
    3. select country and keymap if prompted
    4. from the sysinstall main menu, select Fixit/Repair mode
    5. select "CD/DVD - use the live filesystem"

  2. mount the drive (change the device and mountpoint name as appropriate):

    1. cd /mnt
    2. mkdir mypoint
    3. mount /dev/ad2s1a mypoint

  3. tweak fstab:

    1. ee mypoint/etc/fstab
    2. change each entry mentioning the old drive number to mention the new drive number instead - eg. ad0s1a is changed to ad2s1a for /usr, /var etc.
    3. save and exit

  4. exit Repair mode and the installer and reboot (don't forget to eject the CD)

Note: the above problem can also occur if, for example, FreeBSD is installed on a drive in a USB enclosure, then the drive is removed from the enclosure and placed into a machine (connected directly to a hard drive controller). In this example, the drive would be named da0 while it was connected to the USB enclosure, but named ad0 when it was connected to the primary IDE channel. The fix is identical - in /etc/fstab, change every mention of da0 to ad0, using the procedure above.