0

Show all my disks and partitions.

sudo fdisk -l
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000VX000     
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: BF20422A-7E3A-4CA2-B249-61BB4A5D42B7

Device         Start        End    Sectors   Size Type
/dev/sda1       2048     923647     921600   450M Windows recovery environment
/dev/sda2     923648    1128447     204800   100M EFI System
/dev/sda3    1128448    1161215      32768    16M Microsoft reserved
/dev/sda4    1161216  314069245  312908030 149.2G Microsoft basic data
/dev/sda5  314071040  315117567    1046528   511M Windows recovery environment
/dev/sda6  315119616  346370047   31250432  14.9G Linux swap
/dev/sda7  346370048 1953523711 1607153664 766.4G Linux filesystem


Disk /dev/sdb: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: ST500DM002-1SB10
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: 4635826C-E544-11EB-AD01-48F31700362D

Device         Start       End   Sectors   Size Type
/dev/sdb1         40    532519    532480   260M EFI System
/dev/sdb2     532520 968884255 968351736 461.8G FreeBSD UFS
/dev/sdb3  968884256 976773127   7888872   3.8G FreeBSD swap

FreeBSD is already installed in /dev/sdb2,i can enter it after selecting in bios. enter image description here

I want to add it in the grub menu.

sudo vim  /boot/grub/grub.cfg
### BEGIN /etc/grub.d/40_custom ###
menuentry "FreeBSD" {
    insmod ufs2
    insmod bsd
    set root=(hd1,gpt2)
    kfreebsd /boot/loader
    kfreebsd /boot/kernel
    set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ada1p2
    set kFreeBSD.vfs.root.mountfrom.options=rw
    set kFreeBSD.hw.psm.synaptics_support=1
}
### END /etc/grub.d/40_custom ### 

Reboot,the FreeBSD added in grub menu. enter image description here

Click it to boot,it encounter "invalid a.out header".

enter image description here
If i simply set the grub.cfg as below:

sudo vim  /boot/grub/grub.cfg
### BEGIN /etc/grub.d/40_custom ###
menuentry "FreeBSD" {
    insmod ufs2
    insmod bsd
    set root=(hd1,gpt2)
    kfreebsd /boot/loader
}
### END /etc/grub.d/40_custom ### 

Nothing output ,it seems boot load get stuck there.

Mount /dev/sdb2 in debian and list all files related boot.

debian@debian:~$ sudo mkdir  /mnt/freebsd
debian@debian:~$ sudo mount -r -t ufs -o ufstype=ufs2 /dev/sdb2  /mnt/freebsd
debian@debian:~$ ls  /mnt/freebsd
bin   COPYRIGHT  entropy  home  libexec  mnt  proc    root  sys  usr
boot  dev        etc      lib   media    net  rescue  sbin  tmp  var
debian@debian:~$ ls  /mnt/freebsd/boot
beastie.4th         efi.4th         loader.efi          modules
boot                entropy         loader_lua          pmbr
boot0               firmware        loader_lua.efi      pxeboot
boot0sio            fonts           loader.rc           screen.4th
boot1               frames.4th      loader_simp         shortcuts.4th
boot1.efi           gptboot         loader_simp.efi     support.4th
boot2               gptboot.efi     logo-beastie.4th    uboot
brand.4th           gptzfsboot      logo-beastiebw.4th  userboot_4th.so
brand-fbsd.4th      images          logo-fbsdbw.4th     userboot_lua.so
cdboot              isoboot         logo-orb.4th        userboot.so
check-password.4th  kernel          logo-orbbw.4th      version.4th
color.4th           loader          lua                 zfs
defaults            loader.4th      mbr                 zfsboot
delay.4th           loader_4th      menu.4th            zfsloader
device.hints        loader_4th.efi  menu-commands.4th
dtb                 loader.conf     menu.rc
efi                 loader.conf.d   menusets.4th

Search the a.out file with :

tree  /mnt/freebsd/boot/ | grep  a.out

No file named a.out in /dev/sdb2!
How to fix grub.cfg file then ?
Why don't write it with grub-mkconfig ?

debian@debian:~$ sudo grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.19.0-17-amd64
Found initrd image: /boot/initrd.img-4.19.0-17-amd64
Found linux image: /boot/vmlinuz-4.19.0-16-amd64
Found initrd image: /boot/initrd.img-4.19.0-16-amd64
Found Windows Boot Manager on /dev/sda2@/efi/Microsoft/Boot/bootmgfw.efi
Found FreeBSD 13.0-RELEASE on /dev/sdb2
Adding boot menu entry for EFI firmware configuration
done

windows was recognized and written into grub.cfg.

debian@debian:~$ cat  /boot/grub/grub.cfg  | grep  -i  window
menuentry 'Windows Boot Manager (on /dev/sda2)' --class windows --class os $menuentry_id_option 'osprober-efi-4A44-FBE5' {

FreeBSD was recognized too and not to be written into grub.cfg.

debian@debian:~$ cat  /boot/grub/grub.cfg  | grep  -i  freebsd
debian@debian:~$ cat  /boot/grub/grub.cfg  | grep  BSD

How to fix then ?

1
  • Why do it manually? Doesn't running sudo grub-mkconfig -o /boot/grub/grub.cfg make a valid entry for you? Is BSD not detected in that command's output?
    – terdon
    Jul 16 at 11:24
1

a.out is not a filename, but the name of a particular executable file format. The error message basically means "This does not look like the correct kind of file for this command."

I'm not too familiar with FreeBSD, but based on quick Googling, it seems to me /boot/loader would be intended for BIOS-based booting, and runs as a BTX client with the processor in virtual 86 mode, i.e. using 16-bit or 32-bit code.

A modern UEFI-based x86_64 system, on the other hand, runs even the firmware in full 64-bit mode, so I would expect kfreebsd /boot/loader to be a wrong thing to do on a UEFI system.

You might try something like this:

### BEGIN /etc/grub.d/40_custom ###
menuentry "FreeBSD (chainloaded loader.efi)" {
    set root=(hd1,gpt1)
    chainloader /EFI/BOOT/BOOTX64.EFI
    # /EFI/BOOT/BOOTX64.EFI could be replaced with /EFI/FreeBSD/loader.efi
    # either way, the chainloaded file should be a copy of FreeBSD /boot/loader.efi
}

This attempts to chainload the UEFI version of the FreeBSD loader, loader.efi, from the EFI System Partition of the second disk, just like the firmware-based boot entry does.

You could also use efibootmgr -v to view the UEFI NVRAM boot entry for FreeBSD and find the pathname of the loader.efi instead of /EFI/BOOT/BOOTX64.EFI: it'll probably be something like /EFI/FreeBSD/loader.efi.

The above entry should be easier to get working, since it essentially just duplicates what the firmware would do if you select the "FreeBSD" boot option in the firmware boot menu.

If you want the flexibility to edit the kFreeBSD boot options through GRUB, here's the second entry you might try, but this is just an educated guess because I'm not familiar with FreeBSD:

menuentry "FreeBSD (native from GRUB)" {
    insmod ufs2
    insmod bsd
    set root=(hd1,gpt2)
    # /boot/loader is not applicable on UEFI, maybe GRUB can do its job directly?
    kfreebsd /boot/kernel
    set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ada1p2
    set kFreeBSD.vfs.root.mountfrom.options=rw
    set kFreeBSD.hw.psm.synaptics_support=1
}
### END /etc/grub.d/40_custom ### 
0

I have posted info on /boot after mounting the freebsd partition in debian. It shows that :

sudo mount -r -t ufs -o ufstype=ufs2 /dev/sdb2  /mnt/freebsd
ls  /mnt/freebsd/boot | grep boot
boot
boot0
boot0sio
boot1
boot1.efi
boot2
cdboot
gptboot
gptboot.efi
gptzfsboot
isoboot
pxeboot
uboot
userboot_4th.so
userboot_lua.so
userboot.so
zfsboot

So add lines in /boot/grub/grub.cfg as below:

### BEGIN /etc/grub.d/40_custom ###
menuentry "FreeBSD" {
       insmod ufs2
       chainloader (hd1,gpt2)/boot/boot1.efi
}
### END /etc/grub.d/40_custom ###

It works fine.
The second entry can't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.