# Dual boot FreeBSD & Linux



## sidney (Feb 11, 2021)

ada0 => freebsd
ada1 => SElinux

both on x86 machine. Both using MBR.
What do I need to dual boot? How do I set that up. Thx!


----------



## zirias@ (Feb 11, 2021)

grub should be able to handle that, see for example https://forums.freebsd.org/threads/how-do-i-configure-grub2-to-boot-freebsd-11-1.65992/

But I'd recommend rethinking that, most of the time, you have one "preferred" system and it's easy (and more flexible) to virtualize the other one (bhyve, kvm, virtualbox, ...). Well, just as a suggestion.


----------



## sidney (Feb 11, 2021)

Thx for the link! Virtualization not possible on this legacy box.


----------



## sidney (Feb 11, 2021)

Zirias said:


> grub should be able to handle that, see for example https://forums.freebsd.org/threads/how-do-i-configure-grub2-to-boot-freebsd-11-1.65992/
> 
> But I'd recommend rethinking that, most of the time, you have one "preferred" system and it's easy (and more flexible) to virtualize the other one (bhyve, kvm, virtualbox, ...). Well, just as a suggestion.


OTOH that link deals with s single HDD with 4 partitions. I’ve got 2 HDDs each dedicated to an OS.


----------



## zirias@ (Feb 11, 2021)

Sure, but that's just a matter of using the correct `(hd<d>,<p>)` specs in the grub config, with `<d>` being the disk number and `<p>` being the partition number.


----------



## sidney (Feb 11, 2021)

Zirias said:


> Sure, but that's just a matter of using the correct `(hd<d>,<p>)` specs in the grub config, with `<d>` being the disk number and `<p>` being the partition number.


Okay thx. I’ll give it a shot. BTW, should I install GRUB2 on freebsd, linux or both? And which gets the config treatment?


----------



## zirias@ (Feb 11, 2021)

Never tried that myself, I assume it doesn't matter. But isn't it the "default" bootloader on Linux anyways? So I'd just try to configure it from there I guess…


----------



## bookwormep (Feb 11, 2021)

Just an alternative idea: turn on and immediately open BIOS menu selections for boot sequence. Select the boot device directly from there.


----------



## sidney (Feb 11, 2021)

bookwormep said:


> Just an alternative idea: turn on and immediately open BIOS menu selections for boot sequence. Select the boot device directly from there.


Very good! A KISS solution to boot. I’ll give it a shot. Thx!


----------



## sidney (Feb 11, 2021)

Zirias said:


> Never tried that myself, I assume it doesn't matter. But isn't it the "default" bootloader on Linux anyways? So I'd just try to configure it from there I guess…


No boot loader got installed on Gentoo when I installed it yesterday. What confuses me is that both HDDs have an MBR. So if I install GRUB2 on the Gentoo HDD-the second one- then I suppose I should tell BIOS to boot from there first in order to get the boot menu?


----------



## zirias@ (Feb 11, 2021)

sidney said:


> No boot loader got installed on Gentoo when I installed it yesterday.


That would mean there would be no way to boot the system. So maybe double-check that. A boot loader doesn't HAVE to display something while doing its work. I don't know Gentoo, but I'd be surprised if it did use something other than grub.


sidney said:


> So if I install GRUB2 on the Gentoo HDD-the second one- then I suppose I should tell BIOS to boot from there first in order to get the boot menu?


Yes, probably. Or alternatively, just install grub to the MBR of the first disk. Which is possible from either system, IIRC with command `grub-install`.


----------



## sidney (Feb 11, 2021)

Zirias said:


> That would mean there would be no way to boot the system. So maybe double-check that. A boot loader doesn't HAVE to display something while doing its work. I don't know Gentoo, but I'd be surprised if it did use something other than grub.
> 
> Yes, probably. Or alternatively, just install grub to the MBR of the first disk. Which is possible from either system, IIRC with command `grub-install`.


Okay! Lot’s of help!! Thx.


----------



## scottro (Feb 11, 2021)

I usually use Linux's grub to boot FreeBSD. Gentoo may require you to explicitly install the boot loader, I've not done a Gentoo install since a 2 month recuperation period after surgery a few years ago. I have a page on grub2. https://srobb.net/grub2.html
I'm guessing this isn't a UEFI boot. Depending upon how Linux is referring to your hard drives, (the ad sounds like FreeBSD, with Linux, it's probably sd), you'd install grub in Linux (Gentoo?) and then in /boot/grub/ (if that's the name, again, I don't know about Gentoo, in RedHat based systems it's /boot/grub2), you have a custom.cfg. There are various versions. This one works for me on legacy bios with FreeBSD. 

```
menuentry "FreeBSD" {
set root='(hd0,1)'
kfreebsd /boot/loader
}
```

That assumes that FreeBSD is on the first partition. Grub counts partitions as 1,2,3 rather than 0,1,2.  
If that doesn't work, then replacing kfreebsd /boot/loader with 


```
chainloader (hd0,1)+1
```
may work.


----------



## sidney (Feb 11, 2021)

scottro said:


> I usually use Linux's grub to boot FreeBSD. Gentoo may require you to explicitly install the boot loader, I've not done a Gentoo install since a 2 month recuperation period after surgery a few years ago. I have a page on grub2. https://srobb.net/grub2.html
> I'm guessing this isn't a UEFI boot. Depending upon how Linux is referring to your hard drives, (the ad sounds like FreeBSD, with Linux, it's probably sd), you'd install grub in Linux (Gentoo?) and then in /boot/grub/ (if that's the name, again, I don't know about Gentoo, in RedHat based systems it's /boot/grub2), you have a custom.cfg. There are various versions. This one works for me on legacy bios with FreeBSD.
> 
> ```
> ...


Much obliged scottro!! I just tried the BIOS boot from 2nd HDD trick. It wanted to work but got a kernel panic. Root partition hosed. Got to gox THAT and try YOUR “good stuff!”. Thx


----------



## scottro (Feb 11, 2021)

Glad it *may* have helped. We'll see once / is fixed.  But it works well for me on most legacy bios.


----------



## sidney (Mar 26, 2021)

Got it working like a champ!!


```
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000LM048-2E71
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 6D886D0A-6F2B-4AB1-B7CE-2539B137FA06

Device          Start        End   Sectors   Size Type
/dev/sda1        2048  976476159 976474112 465.6G Linux filesystem
/dev/sda2   976476160  980672511   4196352     2G Linux swap
/dev/sda3   980672512  980673535      1024   512K FreeBSD boot
/dev/sda4   980673536 1945362423 964688888   460G FreeBSD UFS
/dev/sda5  1945362424 1953525134   8162711   3.9G FreeBSD swap
```

Thanks everybody!!


----------

