Issue with GRUB in dual-boot Ubuntu 20.10/FreeBSD 12.2

grz

New Member

Reaction score: 1
Messages: 6

Hi dear Daemons

I tried to make a dual-boot with Ubuntu 20.10 and FreeBSD 12.2.

To help me, I followed this great tuto: https://hauweele.net/~gawen/blog/?p=2252

When I try to boot FreeBSD from my GRUB menu entry, I got the error "Image has invalid negative size".

Booting on Ubuntu works well.

I have two disks:
1. hd0 is a data disk (HDD) mounted on /storage with only one ext4 partition
2. hd1 is a SSD, my main/system disk

My GPT partitions schema on hd1:
1. EFI (~ 300M)
2. Ubuntu (ext4) (~ 250G)
3. FreeBSD swap (4G)
4. FreeBSD UFS (~ 246G)

My custom GRUB menu entry (/etc/grub.d/40_custom):
Code:
menuentry 'FreeBSD' {
    insmod ufs2
    set root='(hd1,gpt4)'
    chainloader /boot/loader.efi
}

I'm aware that is a GNU GRUB issue, not directly FreeBSD, and I already looked for a solution, but if anyone have an idea, I will take it.

Regards
 

eternal_noob

Well-Known Member

Reaction score: 186
Messages: 354

Try to add insmod part_gpt right before set root='(hd1,gpt4)'


Code:
menuentry 'FreeBSD' {
    insmod ufs2
    insmod part_gpt
    set root='(hd1,gpt4)'
    chainloader /boot/loader.efi
}
 
  • Thanks
Reactions: grz
OP
grz

grz

New Member

Reaction score: 1
Messages: 6

Hi freebsd_noob

Thanks for your suggestion.

I just try it, but I got the same error. I made update-grub2
Code:
menuentry 'FreeBSD' {
    insmod ufs2
    insmod part_gpt
    set root='(hd1,gpt4)'
    chainloader /boot/loader.efi
}
 

T-Daemon

Daemon

Reaction score: 696
Messages: 1,465

You could try Super Grub2 Disk. If FreeBSD boots successful reboot Super Grub, enter the editor mode of the FreeBSD menu entry, copy the [Edit] relevant part of the [/EDIT] entry to 40_custom.
 
  • Thanks
Reactions: grz

tyson

Member

Reaction score: 40
Messages: 79

Hi dear Daemons

I tried to make a dual-boot with Ubuntu 20.10 and FreeBSD 12.2.

To help me, I followed this great tuto: https://hauweele.net/~gawen/blog/?p=2252

When I try to boot FreeBSD from my GRUB menu entry, I got the error "Image has invalid negative size".

Booting on Ubuntu works well.

I have two disks:
1. hd0 is a data disk (HDD) mounted on /storage with only one ext4 partition
2. hd1 is a SSD, my main/system disk

My GPT partitions schema on hd1:
1. EFI (~ 300M)
2. Ubuntu (ext4) (~ 250G)
3. FreeBSD swap (4G)
4. FreeBSD UFS (~ 246G)

My custom GRUB menu entry (/etc/grub.d/40_custom):
Code:
menuentry 'FreeBSD' {
    insmod ufs2
    set root='(hd1,gpt4)'
    chainloader /boot/loader.efi
}

I'm aware that is a GNU GRUB issue, not directly FreeBSD, and I already looked for a solution, but if anyone have an idea, I will take it.

Regards
If your PC has UEFI bios, id stick away from grub as its not really needed.
Just copy loader.efi to your EFI partition for example /efi/freebsd/loader.efi.
Than make your bios aware of FreeBSD entry with efibootmgr ( either from linux or FreeBSD).
 
  • Thanks
Reactions: grz

_martin

Aspiring Daemon

Reaction score: 227
Messages: 984

What about using only:
Code:
menuentry FreeBSD {
    set root=(hd1,gpt4)
    chainloader (hd1,4)+1
}
Where hd1 is really your system disk.
edit: no, that actually can't work in efi. I'll keep my suggestion here though.
 

bookwormep

Well-Known Member

Reaction score: 218
Messages: 354

From notes on an Ubuntu dual-boot there was another grub file: /etc/default/grub which needed an edit, commenting out lines: 1.) GRUB_HIDDEN_TIMEOUT or 2.) GRUB_TIMEOUT.

Maybe add another line to your custom menuentry:
Code:
kfreebsd /boot/loader
.

Finally, run: grub-mkconfig -o /boot/grub/grub.cfg. Reboot.
These are only suggestions which may help you.
 
  • Thanks
Reactions: grz

_martin

Aspiring Daemon

Reaction score: 227
Messages: 984

I've odroid h2 which I use for various things. Who would have thought -- I found one small ssd with Ubuntu 18 and FreeBSD 12.0 on it. What a coincidence. :) This machine is UEFI only.
FreeBSD was never booted before on this disk, I don't recall why or how it was set actually. It's a ZFS system. I actually used Ubuntu to copy data from ZFS ( what times we live in).

Anyway, I rolled the Ubuntu to 20 and did some testing. This is how FreeBSD sees the disk:
Code:
root@h2o:~ # gpart show
=>       34  234441581  ada0  GPT  (112G)
         34       2014        - free -  (1.0M)
       2048    1048576     1  efi  (512M)
    1050624  136323073     2  linux-data  (65G)
  137373697        256     3  freebsd-boot  (128K)
  137373953   97067662     4  freebsd-zfs  (46G)
What I did was that under Ubuntu I copied boot1.efito EFI:
Code:
root@h2o:/a/EFI/freebsd # ll
total 92
-rwxr-xr-x  1 root  wheel  93696 Feb 25 01:49 boot1.efi*
root@h2o:/a/EFI/freebsd #
This file should be updated with every FreeBSD update (or at least checked after upgrade if files are the same).
Grub is the default bootloader. I jumped to grub command line and did:

Code:
grub> chainloader (hd0,gpt1)/efi/freebsd/boot1.efi
grub> boot +1
And it jumped to FreeBSD.
So this is a way of doing things (add this entry to grub).

EDIT: I edited out some steps for the sake of clarity.
 

_martin

Aspiring Daemon

Reaction score: 227
Messages: 984

For real only thing u need on EFI boot partition is loader.efi.
But then you loose option to choose what you want to boot each time. You'd have to manage it as you said within OS or BIOS itself.
 

tyson

Member

Reaction score: 40
Messages: 79

But then you loose option to choose what you want to boot each time. You'd have to manage it as you said within OS or BIOS itself.
U don't loose option to choose what to boot. U have to remember to press F8/F12 or whatever your bios boot menu key is.
Its a matter of prefference i think. I did setups with Windows, and Linux+FreeBSD using same ZFS pool for boot, and it just worked fine with UEFI boot only.
 
  • Thanks
Reactions: grz

_martin

Aspiring Daemon

Reaction score: 227
Messages: 984

Yeah, there's more than one way to skin a cat. :) My solution is Linux dependent. I think actually having your solution as fallback is not a bad idea either.
 
OP
grz

grz

New Member

Reaction score: 1
Messages: 6

bookwormep I already tried your suggestion, but it doesn't works too.

tyson I also tried it. When I reboot, I see the FreeBSD entry on UEFI setup but not in the UEFI boot menu. Maybe some things are missing, like others EFI files. I don't know..

_martin That's the point: GRUB solution is Linux dependent.

I finally choose to remove Ubuntu and run only FreeBSD.

Thank you all for your suggestions.
 
OP
grz

grz

New Member

Reaction score: 1
Messages: 6

I retried and I successfully setup UEFI to boot one of these OS: Ubuntu, CentOS, FreeBSD.

I installed first the Linux OSes, then FreeBSD.

Then I added a FreeBSD entry to the UEFI with efibootmgr under Ubuntu

Code:
sudo -s
mkdir /boot/efi/EFI/freebsd
mount -t ufs -o ufstype=ufs2 /dev/nvme0n1p4 /mnt
cp /mnt/boot/boot1.efi /boot/efi/EFI/freebsd/bootx64.efi

cd /boot/efi
efibootmgr -c -d /dev/nvme0n1 -l EFI/freebsd/bootx64.efi -L 'FreeBSD'

It works fine now.
 
Top