How does loader find root partition?

I've been running a dual boot machine with Windows XP on slice 2 and FreeBSD 7.0 on slice 3 without trouble for some time. I recently decided to split my XP slice to make room for installing Vista. I used gparted-live to split the XP slice, installed Vista on the new slice, and then used the FreeBSD-live CD to rewrite boot0 and recover my boot menu.

All seemed fine until I tried to boot into FreeBSD, and the process hung when it looked for the root partition on slice 3. I hadn't thought about the fact that splitting slice 2 would name the new slice 3, and rename my FreeBSD slice from 3 to 4.

I have managed to work around the problem by adding

vfs.root.mountfrom="ufs:ad4s4a"

to /boot/loader.conf and modifying /etc/fstab to change all the devices from slice 3 to slice 4.

What I'd like to know is how the loader determines the root partition location if I don't specify the vfs.root.mountfrom option in loader.conf, and is there a way to set it to slice 4?

I'd also like to know if my "solution" seems like valid approach, or is it more of a superficial solution with a catastrophe around the corner?

Thanks very much for any help.
 
The loader actually looks for /etc/fstab and tries to find the root filesystem. Here's the comment from src/sys/boot/common/boot.c

Code:
/*
 * Try to find the /etc/fstab file on the filesystem (rootdev),
 * which should be be the root filesystem, and parse it to find
 * out what the kernel ought to think the root filesystem is.
 *
 * If we're successful, set vfs.root.mountfrom to <vfstype>:<path>
 * so that the kernel can tell both which VFS and which node to use
 * to mount the device.  If this variable's already set, don't
 * overwrite it.
 */
 
The loader actually looks for /etc/fstab and tries to find the root filesystem. Here's the comment from src/sys/boot/common/boot.c

Code:
/*
 * Try to find the /etc/fstab file on the filesystem (rootdev),
 * which should be be the root filesystem, and parse it to find
 * out what the kernel ought to think the root filesystem is.
 *
 * If we're successful, set vfs.root.mountfrom to <vfstype>:<path>
 * so that the kernel can tell both which VFS and which node to use
 * to mount the device.  If this variable's already set, don't
 * overwrite it.
 */
I have installed 15.1 to a UFS (GPT) formatted drive with multiple partitions for containing the rootfs in an attempt to utilize a set up similar to https://forums.freebsd.org/threads/ufs-boot-environments.79628/

Code:
=>       40  468862048    ada0  GPT  (224G)
         40       1024  ada0p1  freebsd-boot  (512K)
       1064  104856576  ada0p2  freebsd-ufs  (50G)
  104857640  104857600  ada0p3  freebsd-ufs  (50G)
  209715240  251658240  ada0p4  freebsd-ufs  (120G)
  461373480    7488608  ada0p5  freebsd-swap  (3.6G)

I plan to restore a backup tarball of the rootfs presently on ada0p2 to ada0p3 for the purpose of
1. verifying my backup
2. day to day use
3. and later on, performing and testing updates as needed.

when I am happy with the updates, I will reverse course and restore an new tarball back to ada0p2.

Since I will have two possible bootable installs on the same disk, what is the best boot configuration file to adjust so that the bootloader does not have to search? Or should I just edit /etc/fstab each time I want to switch partitions?
(None of the files in /boot seem to have been modified on the date of the install)
 
I have installed 15.1 to a UFS (GPT) formatted drive with multiple partitions for containing the rootfs in an attempt to utilize a set up similar to https://forums.freebsd.org/threads/ufs-boot-environments.79628/

Code:
=>       40  468862048    ada0  GPT  (224G)
         40       1024  ada0p1  freebsd-boot  (512K)
       1064  104856576  ada0p2  freebsd-ufs  (50G)
  104857640  104857600  ada0p3  freebsd-ufs  (50G)
  209715240  251658240  ada0p4  freebsd-ufs  (120G)
  461373480    7488608  ada0p5  freebsd-swap  (3.6G)

I plan to restore a backup tarball of the rootfs presently on ada0p2 to ada0p3 for the purpose of
1. verifying my backup
2. day to day use
3. and later on, performing and testing updates as needed.

when I am happy with the updates, I will reverse course and restore an new tarball back to ada0p2.

Since I will have two possible bootable installs on the same disk, what is the best boot configuration file to adjust so that the bootloader does not have to search? Or should I just edit /etc/fstab each time I want to switch partitions?
(None of the files in /boot seem to have been modified on the date of the install)
I recently had installed the same setup and been using it for days.

If it's UEFI booting, use /boot/gptboot.efi file instead of /boot/loader.efi and use gpart to set bootme flag for a partition. You can also edit fstab for proper partitions. Actually vermaden's guide explains it well.

Code:
yusuf@freebsd:~ $ gpart show -l nda0
=>       40  500118119  nda0  GPT  (238G)
         40     532480     1  (null)  (260M)
     532520   16777216     2  (null)  (8G)
   17309736   41943040     3  ufsbe/3  (20G)
   59252776   41943040     4  ufsbe/4  [bootme]  (20G)
  101195816   41943040     5  ufsbe/5  (20G)
  143138856  356979296     6  userdata  (170G)
  500118152          7        - free -  (4K)
 
If you want to choose boot pool among multiple Root on ZFS pools, boot1.efi patched with my variant at PR 207940 would be usable.

This patched boot1.efi looks for ZFS pools / UFS partitions containing /boot/loader.efi and lists found ones as bootable candidates.

The search order is ZFS to UFS per physical drive, from the drive boot1.efi is kicked from, then, all drives reported by UEFI firmwares in the reported order.

For example, if ada0, ada1 and ada2 exist and all contains independent Root on ZFS pools and UFS partitions, with 2 UFS bootable partitions in ada1 only (for convenience, UFS1 and UFS2 respectively), then, boot from ada2 by specifying UEFI boot device menu, searched in the order below.
  1. ada2 ZFS
  2. ada2 UFS
  3. ada0 ZFS
  4. ada0 UFS
  5. ada1 ZFS
  6. ada1 UFS1
  7. ada1 UFS2
Note that loader.efi preferres UFS over ZFS, if I recall correctly.
 
Back
Top