# Add FreeBSD (dual boot) to a SSD with existing Kubuntu on ZFS root



## RoGeorge (Oct 20, 2022)

> 2.6.4. Guided Partitioning Using Root-on-ZFS​This partitioning mode only works with whole disks and will erase the contents of the entire disk. The main ZFS configuration menu offers a number of options to control the creation of the pool.


From the above quote from the Handbook, I understand the installer wants an entire disk for Root-on-ZFS.

My SSD already has a Kubuntu Root-on-ZFS installed, so the disk already has a ZFS partition.  I'm using UEFI boot and GPT partitions, single SSD disk, no arrays, no encryption:

```
# parted run from the installed Kubuntu w ZFS on root
sudo parted -l /dev/hda

Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sda: 512GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name                  Flags
 1      1049kB  538MB   537MB   fat32           EFI System Partition  boot, esp
 2      538MB   2685MB  2147MB  linux-swap(v1)                        swap
 3      2685MB  4833MB  2147MB  zfs   <---  this is bpool in Linux
 4      4833MB  512GB   507GB   zfs   <---  this is rpool in Linux
```

I need to keep the existing Kubuntu while adding a new FreeBSD install with Root-on-ZFS as a dual boot.

Please note that Ubuntu w ZFS-on-root has some in-house made tools (ZSys by Ubuntu) to take ZFS snapshots automatically (for Ubuntu pools only) after each install in Linux, then adds OS recovery/restore points inside the GRUB boot menus (so it changes the GRUB menus/files).

How do I install FreeBSD with root-on-ZFS on the same disk, near an existing install of (K)ubuntu 22.04 LTS with ZFS-on-root?


----------



## SirDice (Oct 20, 2022)

RoGeorge said:


> How do I install FreeBSD with root-on-ZFS on the same disk, near an existing install of (K)ubuntu 22.04 LTS with ZFS-on-root?


Set up the partitions and the ZFS filesystems by hand (custom install). Then exit the shell to return to the installer, which will then install all the required files in the filesystems you just created.

You can use the same EFI partition for the FreeBSD UEFI bootloader. Just copy /boot/loader.efi to ${EFI}/EFI/FreeBSD/loader.efi, then use efibootmgr(8) to create an additional boot configuration.


----------



## T-Daemon (Oct 20, 2022)

RoGeorge said:


> How do I install FreeBSD with root-on-ZFS on the same disk, near an existing install of (K)ubuntu 22.04 LTS with ZFS-on-root?


Alternatively to what SirDice suggested install all manually.

Boot the FreeBSD installer media, drop to "Shell", gpart(8) freebsd-swap, freebsd-zfs partitions, and use zpool and dataset creation below (copied from zpool-history(8) of my system and edited):


```
zpool create -o altroot=/mnt -O compress=lz4 -O atime=off -m none -f zroot <device>
zfs create -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=/ zroot/ROOT/default
zfs create -o mountpoint=/tmp -o exec=on -o setuid=off zroot/tmp
zfs create -o mountpoint=/usr -o canmount=off zroot/usr
zfs create zroot/usr/home
zfs create -o setuid=off zroot/usr/ports
zfs create zroot/usr/src
zfs create -o mountpoint=/var -o canmount=off zroot/var
zfs create -o exec=off -o setuid=off zroot/var/audit
zfs create -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/log
zfs create -o atime=on zroot/var/mail
zfs create -o setuid=off zroot/var/tmp
zfs set mountpoint=/zroot zroot
zpool set bootfs=zroot/ROOT/default zroot
mkdir -p /mnt/boot/zfs
zpool set cachefile=/mnt/boot/zfs/zpool.cache zroot
zfs set canmount=noauto zroot/ROOT/default

cd /usr/freebsd-dist
tar xfC base.txz /mnt
tar xfC kernel.txz /mnt

chroot /mnt

vi /boot/loader.conf

kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
zfs_load="YES"

vi /etc/rc.conf

hostname="xxx"
keymap="xxx"
sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
zfs_enable="YES"
ifconfig_<interface>="DHCP"

/etc/fstab
# Device        Mountpoint    FStype    Options        Dump    Pass#
/dev/<device>        none        swap    sw        0    0

Set root password:
passwd

exit chroot:
exit

mount_msdosfs /dev/<ESP device> /mnt/
mkdir /mnt/efi/freebsd
cp /boot/loader.efi /mnt/freebsd

Create UEFI boot variable (entry):
efibootmgr -c -a -L FreeBSD -l /mnt/efi/freebsd/loader.efi

Eventually set UEFI boot order: efibootmgr -o  x,y,z,...

umount /mnt

reboot system
```


----------



## _martin (Oct 20, 2022)

I have it installed this way (Ubuntu and FreeBSD on the same disk):

```
# gpart show ada0
=>       40  976773088  ada0  GPT  (466G)
         40       2008        - free -  (1.0M)
       2048    1048576     1  efi  (512M)                  ; efi partition managed by Ubuntu
    1050624  209715200     2  linux-data  (100G)           ; LVM/vg00
  210765824       1024     3  freebsd-boot  (512K)         ; legacy boot partition for FreeBSD in case I want to legacy boot FreeBSD
  210766848       1024        - free -  (512K)
  210767872  209715200     4  freebsd-zfs  (100G)          ; rpool
  420483072  556290056        - free -  (265G)
```
I manually installed FreeBSD but installer is capable of doing that too as SirDice said. To avoid issues under FreeBSD I specified `/boot/efi` in fstab as noauto: 
	
	



```
/dev/ada0p1        /boot/efi    msdosfs rw,noauto 0 0
```

The last step I did was I copied the boot1.efi to the EFI/FreeBSD and let grub chainload the boot (hence no loader.efi): grub.cfg

```
menuentry FreeBSD {
    chainloader (hd0,gpt1)/efi/freebsd/boot1.efi
    boot +1
}
```


----------

