# will an installation destroy my grub?



## kagi3624 (Jun 17, 2020)

Hello, I have several SSDs and HDs  in my desktop. one ssd has windows and another ubuntu installed in EFI mode. So when I boot I have a choice between the two. I want to install freeBSD on a third SSD, but I am anxious that it might destroy the grub and that then I wont be able to launch any of the OPs. So is it possible to keep the grub and have freeBSD as a third boot option? Or if freeBSD puts whatever it uses on top, will I keep my boot choices?


----------



## T-Daemon (Jun 18, 2020)

The FreeBSD installation process on a separate disk won't touch the other disks or GRUB, unless during installation you choose the wrong disk. As precaution make sure you have a backup of your important data from the present installations.

In case you are utmost concerned about your other installations, you could disconnect the disks (unplug the data cable on a powered down system!), install FreeBSD, reconnect the disks ( on a powered down system!).

If you choose during installation _Auto (UFS) Guided Disk Setup_ (2.6. Allocating Disk Space),  that would need extra intervention at the end of the installation process. You would need to change two partition names (label the partitions).

In case you choose _Auto (ZFS)  Guided Root-on-ZFS_, no intervention is needed during the installation process. After reboot the swap partition will need to be adjusted, but it's non critical to the system boot process.

In both cases, if not I, others will surely assist you to label the partitions if you ask.


----------



## Jose (Jun 18, 2020)

I always disconnect the disk I don't want to mangle for safety. You should be able to configure GRUB to boot Freebsd once you are done.


----------



## kagi3624 (Jun 18, 2020)

Jose said:


> I always disconnect the disk I don't want to mangle for safety. You should be able to configure GRUB to boot Freebsd once you are done.



I have installed in ZFS UEFI mode. freeBSD isn't shown in the GRUB, is there any tutorial how to configure grub for freeBSD, I have never done it before. Thx.


----------



## T-Daemon (Jun 18, 2020)

Try this setting to GRUBS's /etc/grub.d/40_custom menu:


```
menuentry "FreeBSD 12.1-RELEASE" {
       insmod zfs
       search --set --label zroot
       kfreebsd /ROOT/default/@/boot/zfsloader
}
```

Don't forget to run update-grub.


----------



## a6h (Jun 18, 2020)

And just for the record, this one is a solution for *MBR/GPT* (Not *ZFS/UEFI*) for MBR/GPT user who has the same problem.
Suppose, FreeBSD has installed on the 2nd partition (partition as in non-FreeBSD temenology)

partition 1: Ubuntu
partition 2: FreeBSD => (hd0,1) second primary partition of the first hard disk
In case of dual-boot windows, it's probably reside on 3rd partition, because you have a Windows hidden system partition, therefore (hd0,2)

partition 1: Windows hidden system
partition 2: Windows
partition 3: FreeBSD => (hd0,2)


```
/etc/grub.d/40_custom
    menuentry "FreeBSD" {
    set root='(hd0,1)'
    kfreebsd /boot/loader
}
```

`# grub-mkconfig -o /boot/grub/grub.cfg`

[EDIT]: add extra information
And in the process if you managed to destory grub, don't panic, run a Live CD and:
An example on /dev/sda (/dev/sda1) # it works on Arch.


```
mount /dev/sda1 /mnt
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt
grub-install /dev/sda1
grub-install --recheck /dev/sda1
update-grub
exit
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev/pts
umount /mnt/dev
umount /mnt
```
Then reboot.


----------



## T-Daemon (Jun 18, 2020)

vigole said:


> And in the process if you managed to destory grub, don't panic, run a Live CD and:


Dude, don't scare the kid with doom and destruction.


----------



## kagi3624 (Jun 18, 2020)

T-Daemon said:


> Try this setting to GRUBS's /etc/grub.d/40_custom menu:
> 
> 
> ```
> ...


I tried this, freeBSD 12.1 is in the grub boot menu, but if I chose it screen goes black and nothing happens, I waited like for 5 minutes


----------



## a6h (Jun 18, 2020)

Change 3rd line: from `search --set --label zroot` to `search --set=root --label zroot`
[EDIT]: Don't forget update-grub


----------



## kagi3624 (Jun 18, 2020)

vigole said:


> Change 3rd line: from `search --set --label zroot` to `search --set=root --label zroot`
> [EDIT]: Don't forget update-grub


Nop, just the same result, don't know if it helps, but here is the result of update-grub
`Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-37-generic
Found initrd image: /boot/initrd.img-5.4.0-37-generic
Found linux image: /boot/vmlinuz-5.4.0-26-generic
Found initrd image: /boot/initrd.img-5.4.0-26-generic
Found Windows Boot Manager on /dev/nvme0n1p2@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings
done`


----------



## T-Daemon (Jun 19, 2020)

Does FreeBSD boot when chosen from the BIOS/UEFI boot selection menu (usualy the F12 key, but it may differ for your computer)?


----------



## kagi3624 (Jun 19, 2020)

T-Daemon said:


> Does FreeBSD boot when chosen from the BIOS/UEFI boot selection menu (usualy the F12 key, but it may differ for your computer)?


it`s F11 on my mainboard..but yeah, there are 3 options. UEFI OS (P1: ssd name) is the one with the freeBSD installation and i can boot it from there.


----------



## patovm04 (Jun 19, 2020)

Chainloading FreeBSD EFI loader from GRUB always works for me:

```
menuentry "FreeBSD" {
    set root=(hd0,gpt1)
    chainloader /efi/boot/bootx64.efi
}
```
Change _hd0_ with your actual disk


----------



## kagi3624 (Jun 19, 2020)

Nop, this didn't work either...it just said device not found. So someone asked what my devices look like.






freeBSD is on sdb, windows is nvme1n1 and ubuntu is on nvme0n1, grub looks like this


----------



## patovm04 (Jun 19, 2020)

kagi3624 said:


> Nop, this didn't work either...it just said device not found. So someone asked what my devices look like.
> 
> View attachment 8017
> 
> ...


Just to confirm, sdb would mean 'hd1' in GRUB. Was that what you did?
It should look like this:

```
menuentry "FreeBSD" {
    set root=(hd1,gpt1)
    chainloader /efi/boot/bootx64.efi
}
```


----------



## T-Daemon (Jun 19, 2020)

patovm04 said:


> Chainloading FreeBSD EFI loader from GRUB always works for me:
> 
> ```
> menuentry "FreeBSD" {
> ...



I was about to recommend your tutorial:








						[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
				




Beginning at "_# Mount the existing EFI partition of your disk:_", ending at "_# For GRUB:_"
Is it still up to date?


----------



## patovm04 (Jun 19, 2020)

T-Daemon said:


> I was about to recommend your tutorial:
> 
> 
> 
> ...


Yes, it is. The difference is, in my tutorial you do a _manual_ installation and you give the efi loader the name "freebsd.efi" (so it doesn't interfere with loaders from other systems). On the other hand, when using FreeBSD's _default_ installation, the efi loader is named "bootx64.efi"


----------



## kagi3624 (Jun 19, 2020)

patovm04 said:


> Just to confirm, sdb would mean 'hd1' in GRUB. Was that what you did?
> It should look like this:
> 
> ```
> ...



No, I actually just put in sdb there the first time . Anyway I replaced it with what you said, I did sudo update-grub, but now when I choose freeBSD from the menu the cursor is put back on the Ubuntu entry


----------



## Jose (Jun 19, 2020)

GRUB has tab completion. Maybe this can help you pick the right device?


----------



## patovm04 (Jun 19, 2020)

kagi3624 said:


> No, I actually just put in sdb there the first time . Anyway I replaced it with what you said, I did sudo update-grub, but now when I choose freeBSD from the menu the cursor is put back on the Ubuntu entry


Hmm, perhaps it may be that GRUB is numbering the disk where it resides in as the first one, thus altering the numbering of the other drives...
You can try changing from 'hd1' to 'hd2' and see if it makes a difference. I'm just guessing though


----------



## T-Daemon (Jun 19, 2020)

kagi3624 said:


> I replaced it with what you said, I did sudo update-grub,


You can set/check the right hd without editing the grub custom file.

At the GRUB menu pressing the C key will take you to the GRUB terminal, enter `ls`, it will list all disks. Identify your FreeBSD disk and partition 1. Descend into the disk directory to verify the correct disk and partition:

`ls (hd1,gpt1)/` ,
`ls (hd2,gpt1)/efi/boot` , etc.

Press Esc to return to the GRUB menu.

Then choose at the GRUB boot menu FreeBSD, press the E key, that will enter into the menu entry editor mode, edit the entry, press F10 to boot. If all is satisfactory edit /etc/grub/40_custom.


----------



## kagi3624 (Jun 21, 2020)

Hello, I did that, so the partitions are as follows


```
ls (hd1,gpt3)
Partition hd1,gpt3: Filesystem type zfs - Label `zroot' -...

ls (hd1,gpt2)
No known filesystem detected.

ls(hd1,gpt1)
Partition hd1,gpt1: Filesystem type fat - Label `EFISYS' ...

ls (hd1,gpt1)/efi/boot
BOOTx64.efi startup.nsh
```

Then I pressed E to modify the freeBSD entry and made sure that 


```
menuentry "FreeBSD" {
    set root=(hd1,gpt1)
    chainloader /efi/boot/bootx64.efi
```
}

is still there. But when I press F10 to boot up I get the error message:


```
Image has invalid negative size
```

Strangely though when I exit grub freeBSD starts to booting up anyway.


----------



## T-Daemon (Jun 21, 2020)

kagi3624 said:


> ls (hd1,*gpt3*)
> Partition hd1,*gpt3*: Filesystem type zfs - Label `*zroot*' -...
> 
> 
> ...



Try setting *gpt3*:

```
menuentry "FreeBSD" {
    set root=(hd1,*gpt3*)
    chainloader /efi/boot/bootx64.efi

}
```


----------



## kagi3624 (Jun 21, 2020)

I tried that. I get an error: File `efi' not found. Is it perhaps because I chose GPT(UEFI) for the partition scheme during the installation? Maybe a reinstall with another partition scheme (UEFI+BIOS) or just (BIOS) would help?


----------



## patovm04 (Jun 21, 2020)

kagi3624 said:


> I tried that. I get an error: File `efi' not found. Is it perhaps because I chose GPT(UEFI) for the partition scheme during the installation? Maybe a reinstall with another partition scheme (UEFI+BIOS) or just (BIOS) would help?


No, I don't think so. It's absolutely right to use GPT(UEFI), unless you're booting in legacy mode.
The reason it shows the error "efi not found" is because you pointed to gpt3, which is the partition with ZFS.
Using gpt1 was correct when trying to chainload, as the FreeBSD efi loader is in fact located in that 200M FAT32 efi partition.
I have no clue why it reported before "Image has invalid negative size", but hey, if anyway it does boot to FreeBSD afterwards I guess you shouldn't care too much.
Finally, if you want to try a different way than chainloading, then you could try directly loading the FreeBSD kernel from GRUB (here you would indeed need to point to 'gpt3', the partition with ZFS), but you'll need to find exactly how to do it elsewhere as I don't really know how to


----------



## T-Daemon (Jun 21, 2020)

kagi3624 said:


> I tried that. I get an error: File `efi' not found.


My mistake. I haven't dealt with grub quite a while and had an alternative solution in mind which involves gpt3. I overlooked `set root` refers to where the boot loader is situated, not system root (necessarily).

Also I need my eyes checked. Seriously, it's in front, but I haven't seen it:


kagi3624 said:


> ls (hd1,gpt1)/efi/boot
> BOOTx64.efi startup.nsh



Try setting for `chainloader` uppercase `BOOTx64.efi`:

```
menuentry "FreeBSD" { 
     set root=(hd1,gpt1)
     chainloader /efi/boot/BOOTx64.efi
}
```

You can also try this one:

```
menuentry "FreeBSD 12.1-RELEASE" {
       insmod zfs
       search --set --label zroot --hint hd1,gpt3
       kfreebsd /ROOT/default/@/boot/zfsloader
}
```


----------



## kagi3624 (Jun 21, 2020)

The first one just immediately  throws me back into the grub menu to the Ubuntu choice and the second one my monitors just go blank. I guess I will try to install freeBSD on my other drive and if it does not work there I guess I have to live with it.


----------



## T-Daemon (Jun 21, 2020)

kagi3624 said:


> I guess I will try to install freeBSD on my other drive and if it does not work there I guess I have to live with it.


You could also boot FreeBSD from the UEFI boot selection menu (F11) until found a solution for GRUB.


----------

