# Load any kernel , mount any filesystem as root , with a small ufs boot partition



## Alain De Vos (Jun 12, 2021)

Using a small ufs partition you have the flexibility to boot almost anything.
How.
Create a small ufs partition.

```
gpart  add  -t freebsd-ufs  -a 4k  -s SIZE  -l LABEL   GEOM
```
This creates a new device.
Format to ufs:

```
newfs  -O 2  -U  -j  -L VOLNAME  DEVICE
```

mount the DEVICE,

```
mkdir /mnt/bootpartition
mount DEVICE  /mnt/bootpartition
```

Copy over the /boot folder

```
cp -axfvR /boot /mnt/bootpartition
```

Now edit the /mnt/bootpartition/boot/loader.conf file.
Three settings are important.

The partition where to boot from e.g., (the loader is intelligent so it can mostly be omited)

```
loaddev="disk2p9:"
```

The default device to load the kernel from e.g.,

```
currdev="zfs:MYZPOOL/ROOT/default:"
```

The root partition to mount, e.g. for booting on zpool MYZPOOL

```
vfs.root.mountfrom="zfs:MYZPOOL/ROOT/default"
```

When you load a kernel not located on the bootpartition the bootpartion itself does not need to have kernel.
So you can

```
rm -vfR /mnt/bootpartition/kernel
rm -vfR /mnt/bootpartition/kernel.old
```

Done

```
umount /mnt/bootpartition
```

The freebsd bootloader resided on this bootpartition can now very easily be loaded via linux-grub using chainloading. For instance if the freebsd bootpartition is the first partition of the first disk with gpt,
Edit on the linux system /etc/grub.d/40_custom and add,

```
menuentry "FreeBSD" {
    insmod part_bsd
    insmod part_gpt
    insmod part_msdos
    insmod ufs2
    insmod chain
    root=(hd0,gpt1)
    kfreebsd /boot/loader
}
```


```
update-grub
```


----------

