all repos — aaoth.xyz @ 5aae3e80a31476c5762720489f911a989891496d

aaoth.xyz website

_posts/2021-11-03-dualboot-linux-and-openbsd-with-grub.md (view raw)

 1---
 2title: dualboot linux and openbsd with grub
 3date: 2021-11-03T15:23:00+03:00
 4author: la-ninpre
 5tags: openbsd linux grub tutorial
 6---
 7
 8i've been trying to dualboot openbsd with linux using grub on both bios and
 9uefi machines and here's a solution that i've come up with.
10
11<!--more-->
12
13there are some guides about this on the internet, but there's no single guide
14that covers both bios and uefi. @rootbsd has a video where he shows how to
15do this, but his solution has one little disadvantage. he's specifying drives
16in a grub config using relative drive and partition numbers, such as
17`(hd0,gpt2)`. since these numbers could be different if one inserts a new drive
18to the computer, or changes drive order, the boot option could fail
19(which happened).
20
21all partitions and drives have their unique identifier -- uuid. there's no
22direct way to specify uuid in grub configuration, but there is a workaround.
23
24grub manual describes the `search` command which has an option to set root
25device if it is found. so we can use it for our purposes.
26
27## steps for dualbooting in bios/legacy mode
28
291. install linux system on one of your drives
30
312. reboot and boot from openbsd install media and install openbsd to other drive
32or partition.
33
343. reboot and login to your linux system
35
364. open a terminal and run `blkid` or `lsblk -f` to get an output partition
37uuids.
38
395. write the following at the bottom of `/etc/grub.d/40_custom`:
40
41  ```
42  menuentry 'OpenBSD' {
43      search -su --no-floppy *UUID*
44      chainloader +1
45  }
46  ```
47
48  where *UUID* is the uuid of your openbsd partition (with type 'ufs2')
49
506. run either `update-grub` or `grub-mkconfig` depending on what distribution
51you are using. consult your distro's wiki to find a way to update your grub
52configuration with recent changes.
53
547. now reboot and you should see an openbsd's boot option in grub menu.
55
56## steps for uefi system
57
58for boot in uefi mode there are few differences. after installing openbsd
59don't reboot, but choose **shell**. now cd into `/mnt` directory and
60download `BOOTX64.EFI` from your desired openbsd mirror. for example:
61  ```
62  # cd /mnt
63  # ftp https://cdn.openbsd.org/pub/OpenBSD/7.0/amd64/BOOTX64.EFI
64  # reboot
65  ```
66
67after that the only other difference is that `chainloader` directive should
68be `chainloader /BOOTX64.EFI`.
69
70all other steps are the same.