# Dual boot Freebsd and Linux mint



## neilms (Aug 8, 2021)

I have tried to follow the tutorial but it seems that some of the commands do not work anymore. I have linux mint installed on half of my hard disk (roughly 50GB). The other half was empty space reserved for freebsd - another 50GB.

The first problem was:



> gpart add -a 4k -l swap0 -s 4G -t freebsd-swap ada0


I got an error which said unknown geom ada0. I found that my hard disc is no longer named ada0 but nvd0, so I used this to get around the problem.

The second problem was:


> zfs create -o mountpoint=none zroot/ROOT


I got the error unable to create zroot/Root. After this I could go no further. I am wondering if this tutorial is now out of date for freebsd 13? Can anyone help me to install freebsd 13 alongside linux?


----------



## Alain De Vos (Aug 8, 2021)

Dual booting linux & freebsd is a piece of cake and easy.
But explaining how is a bit more difficult.
First and foreall grub is a fantastic peace of software and I use it to chainload freebsd.
This means you use the freebsd loader.
This is an example of my 40_custom grub file for a loader on zfs

```
menuentry "ZFS ON ROOT CHAINLOADING" {
 insmod part_msdos
 insmod part_gpt
 insmod zfs
 search -s -l ZT
 kfreebsd /ROOT/default/@/boot/zfsloader
}
```

Or for a loader on ufs (where root can be zfs),

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


----------



## neilms (Aug 8, 2021)

Grub is to boot after install. How do you install freebsd from a usb memory stick onto the hard drive with Linux?


----------



## Alain De Vos (Aug 8, 2021)

It's advisable that your "small" Linux partition is on your first drive, so that you can always boot.
Then you must decide do you want to use uefi boot vs legacy. I find legacy boot easier to configure.
A freebsd usb-stick gives you the option to install freebsd on a free partition or drive.
Personally i did it manually, that is create a partition, zpool/zfs hierarchy extract .txz files, but there easier ways. Sometimes a bit of experiment.
The most tricky part is the booting.
One way is using freebsd boot0 and boot1.
I think boot0 goes into the master boot record and boot1 in a boot partition.
"man gpart" explains this.
The fun part is with grub you don't need boot0 and boot1. You just tell grub where to find the freebsd loader file and your done.


----------



## scottro (Aug 8, 2021)

Doesn't your machine boot from a USB stick?  If so, you can boot from the install USB and partition during installation. I can't remember seeing a machine that isn't really old, that can't boot from a USB stick.
In general, boot from the FreeBSD install, install FreeBSD, then boot into LInux and setup grub. A little different with UEFI, but not drastically so.  There is a tutorial on this forum about installing FreeBSD in a multiboot situation, using ZFS for the FreeBSD drive, with instructions on setting up Linux grub to boot it for UEFI setup. 








						[UEFI/GPT] [Dual-Boot] How to install FreeBSD (with ZFS) alongside another OS (sharing the same disk)
					

Important notes: 1) This tutorial assumes you have the OS you want to dual-boot with already installed on your drive, and that you already have freed up some disk space. Essentially, you will be installing FreeBSD with root-on-ZFS on the remaining free space of the disk, instead of using the...




					forums.freebsd.org


----------



## neilms (Aug 8, 2021)

Thanks, I've tried this tutorial but it doesn't seem to work anymore. If I boot the freebsd USB stick the installer wants to use the whole drive for freebsd.


----------



## Alain De Vos (Aug 8, 2021)

Yep, that's the problem. And that was also my problem when I tried to install on zfs.
For ufs there is however no problem.
For zfs i did not used the "installer" so I went to the console command line and it manually.
Explaining to someone is , "hmm, impossible,difficult".


----------



## Alain De Vos (Aug 8, 2021)

An easy way is to download base.txz kernel.txz lib32.txz manually and just extract these tree files via tar xpf. That's what I did.
No "installer" needed. 
Maybe someone written a guide how to do it?


----------



## neilms (Aug 8, 2021)

Is it easier then to install freebsd on whole drive and then resize the partition to make space for Linux? I'm lost in what to do now


----------



## Alain De Vos (Aug 8, 2021)

The best is first install a small linux on a small partition on your first drive.
Then boot with a freebsd-usb stick and install freebsd on a free place on a free disk-partition "somehow", because there are many ways.
Resizing freebsd is mostly not possible.
You cannot shrink a zfs-zpool.
Nor can you shrink a ufs partition. With "growfs" you can increase the ufs size.


----------



## Vull (Aug 8, 2021)

Can't you use manual partitioning to create smaller partitions that don't use up the whole drive? I've never tried this with zfs but I've done it many times using ufs. First I partition a portion of the disk to install FreeBSD, then I use another portion for Linux. Then I boot Linux and reconfigure grub2 so it will optionally also boot FreeBSD.


----------



## Alain De Vos (Aug 8, 2021)

i think it's best to install freebsd first on ufs.
And when you learn more about it and get used to it you do it create a zfs partition learn about zfs.
And when you are more "skilled", you install it on zfs with your likings.


----------



## T-Daemon (Aug 8, 2021)

neilms, you can install root-on-ZFS with a modified installation script which allows to set the zroot partition size, for example to 50G in your case. FreeBSD must be installed first, Linux Mint afterwards. The script would overwrite any other partitions when present.

Steps:

Download modified root-on-ZFS script, zfsboot
Mount the USB installer media for examples on mount point /mnt
Remove /mnt/usr/libexec/bsdinstall/zfsboot
Copy downloaded zfsboot to /mnt/usr/libexec/bsdinstall/
`chmod 555 /mnt/usr/libexec/bsdinstall/zfsboot`
`umount /mnt`
Boot installation media, set in "ZFS Configuration" menu "ZROOT pool Size" to desired size


----------



## scottro (Aug 8, 2021)

Going back to that tutorial, when it comes to partitoning, it tells you to exit, manually partition, then go back to the installer.  At partitioning, you should be given an option to use the shell.


----------



## rhysday (Aug 9, 2021)

Alain De Vos said:


> Dual booting linux & freebsd is a piece of cake and easy.
> But explaining how is a bit more difficult.
> First and foreall grub is a fantastic peace of software and I use it to chainload freebsd.
> This means you use the freebsd loader.
> ...


When I try this my computer just locks up at a blank screen when I select it in the grub menu. Maybe something to do with my UEFI?


----------



## Vull (Aug 9, 2021)

rhysday said:


> When I try this my computer just locks up at a blank screen when I select it in the grub menu. Maybe something to do with my UEFI?


For UEFI with Linux Mint (or Ubuntu), I had to copy loader_4th.efi from my FreeBSD partition's /boot directory into my EFI partition's /efi/freebsd directory: 

From FreeBSD's root prompt: # `cp -p /boot/loader_4th.efi /boot/efi/efi/freebsd/loader_4th.efi`

Then, in Ubuntu, I added this menuentry to /etc/grub.d/40_custom before running `update-grub`:
	
	



```
menuentry "FreeBSD-13.0-RELEASE" {
  root=(hd0,gpt1)
  chainloader /efi/freebsd/loader_4th.efi
}
```
For Debian, I suspect it would be simpler, and I could simply use this (but I haven't tried it yet):
	
	



```
menuentry "FreeBSD-13.0-RELEASE" {
  root=(hd0,gpt1)
  chainloader /efi/freebsd/loader.efi
}
```
In other words, with Debian, I probably wouldn't have to copy any files into my EFI partition. The file loader.efi should already be there if the FreeBSD installation was done correctly. This is because Debian 10 uses a slightly different, older version of grub2 than Ubuntu 20.04 or Linux Mint 20.1 is now using. I have no idea what might be required for other distributions of Linux.

Note that (hd0,gpt1) represents the partition number of my EFI partition, and not my freebsd-zfs partition.


----------



## Vull (Aug 9, 2021)

T-Daemon said:


> neilms, you can install root-on-ZFS with a modified installation script which allows to set the zroot partition size, for example to 50G in your case. FreeBSD must be installed first, Linux Mint afterwards. The script would overwrite any other partitions when present.
> 
> Steps:
> 
> ...


Thanks for this. This script worked great at limiting the size of my freebsd-zfs partition, but it didn't get the UEFI configuration quite right, so I had to modify it slightly by combining it with the zfsboot file that came with my FreeBSD-13.0-RELEASE-amd64-memstick.img installer. Here's a copy of the modified script in case anybody is interested: https://termbin.com/ppoh7


----------



## neilms (Aug 9, 2021)

T-Daemon said:


> neilms, you can install root-on-ZFS with a modified installation script which allows to set the zroot partition size, for example to 50G in your case. FreeBSD must be installed first, Linux Mint afterwards. The script would overwrite any other partitions when present.
> 
> Steps:
> 
> ...


Thank you I will try this.


----------



## T-Daemon (Aug 9, 2021)

neilms, if your system is UEFI take Vull's zfsboot script. I've checked the modified zfsboot from reviews only on BIOS based system, but not on UEFI systems.

Attached Vull's zfsboot to last for possible future users, https://termbin.com will hold the paste only one month.


----------



## Michael.Hmich (Sep 25, 2021)

T-Daemon said:


> neilms, if your system is UEFI take Vull's zfsboot script. I've checked the modified zfsboot from reviews only on BIOS based system, but not on UEFI systems.
> 
> Attached Vull's zfsboot to last for possible future users, https://termbin.com will hold the paste only one month.


no offense but I think you're complicating things ...
starting with the grub entry for FBSD you can reduce to the following it works, just set your hard drive number instead of mine, this goes into grub.cfg of grub2

```
menuentry "sdc-zfs ... FreeBSD 13-p3 Kde Plasma 5.24" --class freebsd --class bsd --class os {
        insmod zfs
        set root=(hd2)
        chainloader (hd2)+1
}
```
you should install linux first because install later FreeBSD 13 on ZRoot is a 5 minute deal following the installer instructions

what didn't came clear is if you want to install Linux on ZFS also or not


----------



## T-Daemon (Sep 25, 2021)

Michael.Hmich said:


> you should install linux first because install later FreeBSD 13 on ZRoot is a 5 minute deal following the installer instructions


If you mean by "following the installer instructions" the FreeBSD Installer dialog, that won't work. 

The official FreeBSD installer doesn't allow a "Auto (ZFS) Guided Root-on-ZFS" installation besides Linux partitions on the same disk. It allows a installation on the entire disk only. What you propose would destroy the previously installed Linux.

Either FreeBSD Root-on-ZFS is installed on the same disk after Linux manually, or for convenience, the modified installation script can be used.

The modified installation script allows to set the zroot partition size, but FreeBSD must be installed first, otherwise it would destroy and overwrite any previous installations.


----------



## Michael.Hmich (Sep 25, 2021)

you poked me nice until the point I will check that this days
I have Linux and Freebsd 13 installed on the same disk, on two partitions and am pretty sure that the Linux installation is a year long on that disk and Freebsd a couple of month now
what do you mean with " the modified installation script can be used", modified by yourself?


----------



## scottro (Sep 25, 2021)

My post towards the beginning of the thread points to a tutorial about putting a FreeBSD ZFS install on a disk shared with Linux.  In that case (if you're using ZFS) you exit to shell when it gets to the partitioning part, make the ZFS partition, then go back to the installer. If using UFS, it's even easier. The partition dialog shows you what is on the disk and enables you to create  a FreeBSD partition (or partitions).


----------



## T-Daemon (Sep 26, 2021)

Michael.Hmich said:


> what do you mean with " the modified installation script can be used", ...


By  "the modified installation script can be used" I mean the script in question, /usr/libexec/bsdinstall/zfsboot, on the FreeBSD installation medium can be replaces with the one attached to post # 19.


Michael.Hmich said:


> ... modified by yourself?


No, not by me. The original author of the patched version of zfsboot is _wjw_digiware.nl_ on FreeBSD differential reviews "bsdinstall: Allow to set ZROOT partition size", and second patched  to work on UEFI systems (the one in post # 19) by Vull.

To illustrate what this all is about with the original and modified zfsboot script:

Original zfsboot script:




Modified zfsboot script:


----------



## T-Daemon (Sep 26, 2021)

scottro said:


> My post towards the beginning of the thread points to a tutorial about putting a FreeBSD ZFS install on a disk shared with Linux.


For inexperienced users that tutorial may not be suitable, as it can be seen in case of the OP. The patched zfsboot offers an alternative to install FreeBSD easily side by side besides other OS's on the same disk. In particular if encrypted disk is desired it would make the installation considerably easier, for experienced users as well.

Assuming in the first place this is a fresh multi OS installation of all systems, or a present OS can be sacrificed and reinstalled. If a previously installed OS should remain then there is no other option than to install FreeBSD manually (semi automated).


----------



## Michael.Hmich (Oct 11, 2021)

now I understand what you meant, but don't know if a partition shrink after install wouldn't do the same, it's quite fast an easy on zfs


----------

