# How does loader find root partition?



## jtl (Apr 22, 2009)

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.


----------



## gordon@ (Apr 22, 2009)

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


```
/*
 * 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.
 */
```


----------



## jtl (Apr 22, 2009)

Thank you - that's exactly the information I was looking for.


----------

