# Dual booting Linux and FreeBSD on a single drive



## sudobsd (Aug 17, 2022)

Hello, i wanted to dualboot FreeBSD and Linux. I don't know how to do it. I already have Xubuntu installed on my machine.

I'm pretty sure it would be straightforward.
My harddrive is formatted as GPT (UEFI)
I'll might choose GhostBSD, but i've still have chosed between FreeBSD and GhostBSD.

Any ideas ?

Thanks !


----------



## _al (Aug 17, 2022)

If you have grub installed, install FreeBSD on a free partition, reboot into Linux, find out the uuid of the partition you installed freebsd on, create the file
/etc/grub.d/40_custom with the following content:

```
menuentry "freebsd" {
insmod part_gpt
insmod ufs2
search --no-floppy --fs-uuid 624ff8c1090d8148 --set root
chainloader /boot/loader_4th.efi
}
```
where fs-uuid is uuid of your partition freebsd is installed on.
And then (in root terminal):
`# export PATH=$PATH:/sbin`
`# update-grub`
`# reboot`


----------



## sudobsd (Aug 17, 2022)

i can't use ZFS ?


----------



## sudobsd (Aug 17, 2022)

> where fs-uuid is uuid of your partition freebsd is installed on.


You mean like every partition in Linux has its own UUID ?


----------



## _al (Aug 17, 2022)

sudobsd said:


> i can't use ZFS ?


Not sure. I don't use zfs. The text above implies the use of UFS. And you specify the uuid of the root (/) partition.


sudobsd said:


> You mean like every partition in Linux has its own UUID ?


If I understood correctly, you have a GPT partition with Linux installed. I mean the grub is also installed.
You may check your disk partitions by `ls -lha /dev/disk/by-uuid`.


----------



## _al (Aug 17, 2022)

Let's say I installed freebsd on sdi2 (linux notation).  Find the uuid of this partition:

```
lanin@debian2:/$ ls -lha /dev/disk/by-uuid |grep sdi2
lrwxrwxrwx 1 root root  10 aug 17 14:06 62584cb57671f408 -> ../../sdi2
```
In gnome-disk-utility it looks like this


----------



## sudobsd (Aug 17, 2022)

Ah ok thanks, i'll post an message here if it works, i've decided to install GhostBSD.


----------



## sudobsd (Aug 17, 2022)

So i can't install GhostBSD, since it seems to lock up on setting up amdgpu, im gonna try to use the dd command instead of balena etcher. and if it the live usb still can't boot i'll just use FreeBSD, and set it up by myself, i've never got that problem since i already did a mono boot with ghostbsd and it worked absoutely fine.


----------



## sudobsd (Aug 17, 2022)

Ok so it seems that, GhostBSD does not wanna work, so i'll use FreeBSD, isn't there a script to install a desktop environnement quickly ?


----------



## _al (Aug 17, 2022)

sudobsd said:


> isn't there a script to install a desktop environnement quickly ?


I don't know. I installed FreeBSD from (UEFI) DVD with interactive installer. The main thing is to choice manual disk partitioning, create GPT partition for '/' ,  and install FreeBSD there.


----------



## sudobsd (Aug 17, 2022)

I choose the auto option and its created an freebsd partition and swap whitout i have to do something ! now let me change my grub configuration and it should boot


----------



## sudobsd (Aug 17, 2022)

Andrey Lanin said:


> export PATH=$PATH:/sbin



is this a command of i have to put it on the 40_custom file ?


----------



## _al (Aug 17, 2022)

sudobsd said:


> is this a command of i have to put it on the 40_custom file ?


This is a command. After the file is created, run these commands in root terminal.


----------



## sudobsd (Aug 17, 2022)

"export: command not found"


----------



## _al (Aug 17, 2022)

Sorry. I use bash. Look 'export' command for your shell.


----------



## sudobsd (Aug 17, 2022)

I also use bash, but i don't have the export command.


----------



## sudobsd (Aug 17, 2022)

Also there 40_custom file already exists actually in my installation


----------



## bsduck (Aug 17, 2022)

sudobsd said:


> isn't there a script to install a desktop environnement quickly ?


Yes: sysutils/desktop-installer


----------



## sudobsd (Aug 17, 2022)

Ah thanks !, now im trying to find a way to make GRUB recognize my FreeBSD install


----------



## _al (Aug 17, 2022)

sudobsd said:


> Also there 40_custom file already exists actually in my installation


Add there what is posted in post 2. With your uuid, of course


----------



## sudobsd (Aug 17, 2022)

so ok, here is my 40_custom file:

`#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "freebsd" {
insmod part_gpt
insmod ufs2
search --no-floppy --fs-uuid 62fcecf90e518464 --set root
chainloader /boot/loader_4th.efi`


----------



## _al (Aug 17, 2022)

Closing '}' ?


----------



## _al (Aug 17, 2022)

sudobsd said:


> I also use bash, but i don't have the export command.



This does not work ?

```
lanin@debian2:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
lanin@debian2:~$ export PATH=$PATH:/sbin
lanin@debian2:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin
lanin@debian2:~$
```


----------



## sudobsd (Aug 17, 2022)

> Closing '}'


Yeah its actually there i just didn't copy it




the echo command does work actually but still not the export one.


----------



## sudobsd (Aug 17, 2022)

Yeah the export command does not work, idk how can i fix that


----------



## _al (Aug 17, 2022)

1. Create script, let's say a.sh with the following content:

```
declare -x PATH=$PATH:/sbin
update-grub
```

2. Change permissions:
`chmod +x a.sh`

3. open root terminal, and run this script: 
`./a.sh`


----------



## sudobsd (Aug 17, 2022)

and now what do i do ? 

update-grub says: "Warning: os-prober will not be executed to detect other bootable partitions."

Is it normal ?


----------



## _al (Aug 17, 2022)

Hmm, no.
Normal output looks like this:

```
root@debian2:/home/lanin# ./a.sh
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-5.10.0-16-amd64
...
Found Windows Boot Manager on /dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi
Found Debian GNU/Linux 10 (buster) on /dev/sda6
Found FreeBSD 13.1-RELEASE-p1 on /dev/sdf4
Found FreeBSD 13.1-RELEASE-p1 on /dev/sdi2
Adding boot menu entry for EFI firmware configuration
done
```


----------



## sudobsd (Aug 17, 2022)

Here is what it shows.


----------



## sudobsd (Aug 17, 2022)

Andrey Lanin said:


> Hmm, no.
> Normal output looks like this:
> 
> ```
> ...


Hmmmmm...... weird that not normal, So i don't know whats happening ? is FreeBSD installed the EFI file correctly ? FreeBSD failed at the end when i choosed the exit option.


----------



## _al (Aug 17, 2022)

sudobsd said:


> ... will not be executed ....


'declare' not found. Hm, very strange bash.


----------



## _al (Aug 17, 2022)

sudobsd said:


> i don't know whats happening ?


Path to program (which is used by 'update-grub') not found. This program - 'grub-mkconfig' (look into /sbin/update-grub).


----------



## sudobsd (Aug 17, 2022)

Yeah..... idk i didn't touched bash actually.


----------



## sudobsd (Aug 17, 2022)

ok i have an idea, im gonna put `#!/bin/bash` in the sh file, might work.


----------



## sudobsd (Aug 17, 2022)

Ok adding the #!/bin/bash line in the sh file fixes the declare not found issue. but GRUB still does not find FreeBSD.


----------



## _al (Aug 17, 2022)

cd to /sbin, edit update-grub (insert './' before grub-mkconfig'), and run `./update-grub` from here


----------



## sudobsd (Aug 17, 2022)

Nope still not finding FreeBSD.


----------



## _al (Aug 17, 2022)

sudobsd said:


> ...but GRUB still does not find FreeBSD.


What the output ?

Add what the output of `ls -lha /dev/disk/by-uuid` ?


----------



## sudobsd (Aug 17, 2022)




----------



## _al (Aug 17, 2022)

Andrey Lanin said:


> cd to /sbin, edit update-grub (insert './' before grub-mkconfig'), and run `./update-grub` from here


It is wrong advice - don't use it.


----------



## sudobsd (Aug 17, 2022)

so i remove the ./ of grub-mkconfig ?


----------



## _al (Aug 17, 2022)

Yes


----------



## sudobsd (Aug 17, 2022)

hmmm so i don't know what can i do to fix this ?


----------



## _al (Aug 17, 2022)

Can you put here text output (not images!) of  `ls -lha /dev/disk/by-uuid`
and content of your 40_custom file ? May be 'typo' somewhere ?


----------



## sudobsd (Aug 17, 2022)

`adam@adam-HP-Notebook:~$ ls -lha /dev/disk/by-uuid
total 0
drwxr-xr-x 2 root root 140 août  17 15:36 .
drwxr-xr-x 8 root root 160 août  17 15:36 ..
lrwxrwxrwx 1 root root   9 août  17 15:36 2022-05-12-09-09-46-00 -> ../../sdb
lrwxrwxrwx 1 root root  10 août  17 15:36 2BE6-B6DD -> ../../sda1
lrwxrwxrwx 1 root root  10 août  17 15:36 62fcecf90e518464 -> ../../sda3
lrwxrwxrwx 1 root root  10 août  17 15:36 C501-10EF -> ../../sdb2
lrwxrwxrwx 1 root root  10 août  17 15:36 ea8a99d3-6971-47e8-8ae0-33e62122633a -> ../../sda2`

Here is the 40_custom file:

`#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "freebsd" {
insmod part_gpt
insmod ufs2
search --no-floppy --fs-uuid 62fcecf90e518464 --set root
chainloader /boot/loader_4th.efi }`


----------



## _al (Aug 17, 2022)

Looks good. I'm out of ideas...
And what the output from ./a.sh
Does it run from *root* terminal ?

Transfer closing '}' on its own line.


----------



## sudobsd (Aug 17, 2022)

Same thing as running it with sudo. Doesn't detect FreeBSD.


----------



## _al (Aug 17, 2022)

sudobsd said:


> Same thing as running it with sudo. Doesn't detect FreeBSD.


Only if the environment is inherited


----------



## sudobsd (Aug 17, 2022)

I could check if the EFI file are in my efi partition ?


----------



## sudobsd (Aug 17, 2022)

Andrey Lanin said:


> Only if the environment is inherited


Oh and how do i do that ?


----------



## _al (Aug 17, 2022)

sudobsd said:


> I could check if the EFI file are in my efi partition ?


`cat /boot/grub/grub.cfg | grep freebsd`


----------



## sudobsd (Aug 17, 2022)

`root@adam-HP-Notebook:/home/adam# cat /boot/grub/grub.cfg | grep freebsd
menuentry "freebsd" {`


----------



## _al (Aug 17, 2022)

sudobsd said:


> Oh and how do i do that ?


In some cases (depend of Linux OS) `sudo -E ...`, but better run in root terminal


sudobsd said:


> `root@adam-HP-Notebook:/home/adam# cat /boot/grub/grub.cfg | grep freebsd
> menuentry "freebsd" {`


Ok. Try reboot.


----------



## sudobsd (Aug 17, 2022)

ok, im gonna reboot, and im gonna see if i can boot to freebsd or grub wants to reboot the machine so it can detect freebsd.


----------



## sudobsd (Aug 17, 2022)

Ok so i rebooted the computer, and it seems to only boot to linux, no selection screen.


----------



## _al (Aug 17, 2022)

sudobsd said:


> and now what do i do ?
> 
> update-grub says: "Warning: os-prober will not be executed to detect other bootable partitions."
> 
> Is it normal ?


add GRUB_DISABLE_OS_PROBER=false to /etc/default/grub and run ./a.sh again, and then reboot


----------



## sudobsd (Aug 17, 2022)

"Found unknown linux distrbution at /dev/sda3"

That actually a good sign, i was also thinking about mounting the freebsd partition but it fails miserably.


----------



## sudobsd (Aug 17, 2022)

I could try to reboot maybe ?


----------



## _al (Aug 17, 2022)

Yes


----------



## sudobsd (Aug 17, 2022)

Ok so GRUB may have detected FreeBSD, but the menu to select what OS to boot does not appear, its boots back to Linux.


----------



## sudobsd (Aug 17, 2022)

Hmm, i don't know, i guess i could try to mount the freebsd partition, and try to do update-grub


----------



## _al (Aug 17, 2022)

sudobsd said:


> "Found unknown linux distrbution at /dev/sda3"


Instea, it should output something like this

```
Found FreeBSD 13.1-RELEASE-p1 on /dev/sda3
```


----------



## sudobsd (Aug 17, 2022)

Andrey Lanin said:


> Instea, it should output something like this
> 
> ```
> Found FreeBSD 13.1-RELEASE-p1 on /dev/sda3
> ```


Yeah i don't know, its really weird.


----------



## _al (Aug 17, 2022)

sudobsd said:


> i guess i could try to mount the freebsd partition,


No.


sudobsd said:


> try to do update-grub


Yes

Did you add GRUB_DISABLE_OS_PROBER=false to /etc/default/grub ?
If yes, run ./a.sh and reboot


----------



## sudobsd (Aug 17, 2022)

so how can i show GRUB selection menu, because this confuses me.


----------



## sudobsd (Aug 17, 2022)

Yes i did


----------



## sudobsd (Aug 17, 2022)

I think that the EFI file is not the same i have as yours. It probably has a different file name.


----------



## sudobsd (Aug 17, 2022)

i could try this: 
`menuentry "FreeBSD" {
    insmod ufs2
    search --file --set root --no-floppy /boot/loader.efi
    chainloader /boot/loader.efi`

Maybe it would work ?


----------



## sudobsd (Aug 17, 2022)

ok no its doesnt work: plus it shows that:


----------



## sudobsd (Aug 17, 2022)

Welp, i guess this is going nowhere, i can't configure GRUB. im gonna try to boot to FreeBSD from the BIOS which means spamming the ESC key when booting the computer, or when i wanna boot to FreeBSD


----------



## _al (Aug 17, 2022)

What the output of `lsblk -f /dev/sda3` ?


----------



## sudobsd (Aug 17, 2022)




----------



## _al (Aug 17, 2022)

It is correct. I give up.
I can suggest to try edit 40_custom  as follows (but that is bad idea):

```
menuentry "freebsd" {
    insmod part_gpt
    insmod ufs2
    set root='hdX,gptY'
    chainloader /boot/loader_4th.efi
}
where X count from 0, Y count from 1
gptY - where FreeBSD's '/' is placed
```


----------



## sudobsd (Aug 17, 2022)

Welp,  its the end then.

Thanks for helping me anyways, i'll probably migrate to Arch Linux.


----------



## _al (Aug 17, 2022)

Is /dev/sda3 mounted? umount it and try again


----------



## sudobsd (Aug 17, 2022)

No, its not mounted


----------



## scottro (Aug 17, 2022)

There is a howto on the forums on creating and using a zfs partition in multiboot by patovm04 . I've used it successfully. 









						[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


----------



## sudobsd (Aug 17, 2022)

Im gonna try it, even though i think im gonna migrate to a new distro.


----------



## _al (Aug 17, 2022)

sudobsd said:


> No, its not mounted


Hmm, `lsblk -f /dev/sda3` output in post 72 looks different.


----------



## _al (Aug 17, 2022)

Anyway, sorry I couldn't help


----------



## sudobsd (Aug 17, 2022)

No problems, I'll just use a other laptop for FreeBSD, if i get one anyways. Thanks for helping me guys !


----------



## _al (Aug 17, 2022)

Regarding post 66.
Edit /etc/default/grub:

```
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
# GRUB_TIMEOUT_STYLE=hidden - comment out it
```
*Leaving all other variables as is*

I don't think that it helps a lot, at least will show the grub menu.
Still worth trying to run ./a.sh (without mounting /dev/sda3 !) and reboot


----------



## sudobsd (Aug 17, 2022)

I'm might gonna try to have an mono boot for FreeBSD, even though whats actually concern me if the amdgpu driver works.


----------



## fscorrea (Sep 12, 2022)

If you want to boot FreeBSD UEFI mode, an EFI System Partition is supposed to exist. I would have created one anew, even if just to make things easier, during `bsdinstall`: choose "manual" partitioning when asked, create a new partition, replace whatever is written as default (usually "freebsd-ufs") type with "efi", size it 512MB and set its mount point to, say, /boot/efi. After install, run a shell instead of immediately rebooting and see for yourself that /boot/efi is there, with loader.efi somewhere inside (e.g. I have /boot/efi/efi/freebsd/loader.efi here). Then reboot.

GRUB2 numbers your disks from 0 and partitions from 1. You'll need to find out these for FreeBSD root (the one you set to mount on "/" back in `bsdinstall`). (trial and error works fine here, just Google a bit to find out how to drop in a GRUB Shell intentionally, then try `ls (hd0,gpt1)/` increasing the numbers until getting your answer).

Avoid relying on `os-prober`. Edit /etc/grub/40_custom as follows:

```
menuentry "FreeBSD" {
insmod part_gpt
insmod fat
insmod ufs2
set root=(hdX,gptY)
chainloader +1
boot
}
```
Replacing X and Y with the numbers figured out in previous step.

GRUB will have the right disk and partition set as root then chainload whatever is on it. If you did everything right, FreeBSD is there and will proceed with its own bootloader, there you'll have it.

Even if "+1" fails to do the trick, you must have had boot listed by `ls (hdX,gptY)/` while in GRUB Rescue. Just `chainloader /boot/efi/efi/freebsd/loader.efi` and delete the last line ("boot") in /etc/grub/40_custom. BTW, `# grubmkconfig -o /boot/grub/grub.cfg` after every time you edit this file. Ignore `$ update-grub` for a while, though (i.e. until you have your dual-boot working).

If you didn't create the ESP and relied on the one which was already there, you'll have to check if `bsdinstall` behaved as I think you expected (to have put a subdirectory "freebsd" and the loader.efi there inside). That being the case, just find the partition and disk number related, set as root, and chainload the whole path to loader.efi

e.g. let's say you had a /boot/efi as ESP for xubuntu: just reapply the above logic for it (get disk and partition number, edit /etc/grub/40_custom with `set root=(hdX,gptY)`, then `chainloader /boot/efi/path/to/freebsd/loader.efi`).


----------



## fscorrea (Sep 12, 2022)

_al "Root terminal" can be a bit imprecise when environment is involved. `$ sudo su`, `$ su -l`, and `$ su -` yield three distinct results (as far as `# env` is of concern).

Not sure how is this is it? related to `update-grub` (a rather "Ubuntu-esque" thingy I never bothered to mince details of, like with "Debian-esque" `os-prober` thingy as well), though. But since you mentioned something about environments (and since sudobsd realized about the shebang line a little too late for me not to wonder how he/she interpreted/launched a "root terminal") I thought I'd better say something.


----------

