Dear all,

multiboot installation of a BSD system with other operating systems
(OSs) on UEFI hardware is not officially supported by any of the
popular
BSDs. Because of the general interest in this topic, here I would like
to share my experience of running DragonFly BSD, OpenBSD, and Slackware
Linux on an UEFI ASUS laptop. The only boot manager you need is
[rEFInd](http://www.rodsbooks.com/refind). The tutorial is appended at
the
end of this post. I have also attached it as an .md file for better
readability in case some formatting is lost. I hope you will find the
tutorial useful.

Best regards,

Martin Ivanov


# Installation of OpenBSD in a multiboot on a UEFI machine 

## Preliminaries

As each OS is going to reside on its own hard drive slice,
the first step of setting your system for multiboot is slicing the hard
drive. In general, if you want to multiboot n OSs, you would need n + 1
slices. The extra slice is for the EFI system partition (ESP). Of
course, you have to make sure each partition is large enough for the OS
that is going to reside on it. As mentioned, in this tutorial I share
my
experience with installing DragonFly, OpenBSD, and Slackware Linux. I
sliced the hard drive from DragonFly, which I have exemplarily
described
in the [DragonFly documentation on
multiboot](
https://www.dragonflybsd.org/docs/handbook/Installation/#index6h1).
Of course, you will slice the hard drive from the first OS that you are
going to install. In the above link to the DragonFly documentation, I
have also described how the ESP is to be set up. Therefore, in the
following I assume your first OS has already been installed in its
slice, rEFInd has been installed in the ESP, and I only
consider the specifics of the OpenBSD installation.

## Installation of OpenBSD

First of all, I cannot enough recommend you to read the document 
https://ftp.openbsd.org/pub/OpenBSD/6.7/amd64/INSTALL.amd64. Of course,
this is for OpenBSD version 6.7, for a different OpenBSD version you
should update the version number accordingly.

Prepare the install medium for OpenBSD as described in the
[documentation](https://www.openbsd.org/faq/faq4.html#Download). If you
would need any additional firmware, make sure to download it to a USB
stick as [described in the documentation]
(https://www.openbsd.org/faq/faq4.html#Checklist). In my case with
OpenBSD-6.7, I had to go to http://firmware.openbsd.org/firmware/6.7/
and download the wireless driver I need (iwm-firmware-20191022p0.tgz).
Please make sure to download not only the respective *.tgz files but
also
the SHA256.sig and index.txt files and store them together in the same
folder on the USB stick as the *.tgz file(s).

Boot the computer with the install medium. In the following, I will
just
skim through the questions the installer asks that are not that obvious
how to answer (at least they weren't that obvious for me at the first
install :-))

Select (I)nstall

Do you want the X Window System to be started by xenodm? no (default)
You can always enable xenodm later. Setting no here makes sure after
booting you will be able to inspect the boot messages.

I do not configure network, because my wifi card needs the firmware to
be installed later.

Setup a user: no (default)
You can do this also after installing OpenBSD.

Which disk is the root disk: sd0
In your case the root disk maybe something else, please replace
accordingly.
Disk slicing:
We assume we have already created a disk slice for OpenBSD from the
other OS. Now we have to give that slice a type of A6, so that
the OpenBSD installer is able to recognise it. So, select your hard
drive when offered, and then select (E)dit. This will start an
interactive fdisk session. Typing p will show you the partition table.
If the partition for OpenBSD is number 2, setting its type to A6
involves the following command-line input:

        e 2
        t
        A6
        write
        quit

As we are going to use rEFInd as a boot manager, you do not need to
toggle a bootable flag on the OpenBSD partition.

Note: On subsequent installs, the OpenBSD installer detects the A6
partition and readily offers it as (O)penBSD area. 

Use (W)hole disk, use the (O)penBSD area, or (E)dit the GPT: OpenBSD
Select the OpenBSD area here, which is also the default choice.

Disklabel partitioning: 
Select a custom layout: C
We want to create a custom layout for the disklabel partitions to make
sure our file systems are large enough for our needs. For example, my
OpenBSD slice is 200 GiB. First, delete all partitions (note that c
cannot be deleted):

        z 

Then, I create the following layout:

Partition Size File System Mount Point
a         10g     4.2BSD            /
b         16g     swap
d         50g     4.2BSD            /usr
e         10g     4.2BSD            /var
f         15g     4.2BSD            /tmp
g         rest    4.2BSD            /home

Typing ? will help you figure out the exact commands you have to type
to
create your desired layout. When you are ready with the partitioning,
save and quit:

        w
        q

Note: if you already have disklabel partitions, after selecting the
custom layout they will be present. In that case, you can simply only
provide mount points (using the command n). Only the partitions for
which you provide mount points will be formatted.

Which disk do you want to initialise: done (the default)
Location of sets? (cd disk ftp http or 'done'): disk
Is the disk partition already mounted?: no

Two further questions for the location of the sets follow. You should
be
OK selecting the default answers.

Set name(s): done
Asks you to configure which sets to install. All are
preselected, so just hit Enter for done and everything will be
installed.

Directory does not contain SHA256.sig. Continue without verification:
yes

Just accept the default when the installer asks the same question
again:
Set names: done (default)

Toward the end of the installation you will obtain the following
warning:

Installboot: no OpenBSD partition
Failed to install bootblocks.
You will not be able to boot OpenBSD from sd0

Unheed these warnings, we will take care for the booting right away
with
rEFInd. The warnings may have to do with the fact that the ESP created
by DragonFly cannot be mounted by OpenBSD (at least on my machine it is
not possible; below you can see the error message I get).

If you have a multicore system, you need the smp-enabled kernel:

        mv /mnt/bsd /mnt/bsd.sp
        mv /mnt/bsd.mp /mnt/bsd

For a single-core machine, you can omit the previous step.

Plug in a USB stick to copy the OpenBSD boot code (it can be the same
stick where you downloaded the firmware). Note that as OpenBSD doesn't
have
a dynamic devfs, the contents of /dev are generated by a script in the
same directory (MAKEDEV). Thus, only a few devices have nodes created
by
default. You have to create the device nodes yourself manually as
follows.

We assume that the USB stick is recognised as sd2. Note that in
OpenBSD FAT disklabel partitions  are usually recognised as 'i':

        /bin/sh MAKEDEV sd2
        mount /dev/sd2i /mnt2

Copy the OpenBSD boot code to the USB stick:

        cp /mnt/usr/mdec/BOOTX64.EFI /mnt2/bootx64-openbsd.efi

Halt the machine to have time to take the USB stick out:

        halt

After the system halts, remove the usb sticks and boot into DragonFly
(or any of your already installed OSs, from which you can mount the
ESP.
On my laptop I get a "mount_msdos: /dev/sd0i on /mnt: Device not
configured" error). The following instructions assume you booted into
DragonFly.

Mount the ESP:

        mount_msdos /dev/nvme0s0 /efimnt

Mount the USB stick with the boot code (assuming it is recognised as
da8):

        mount_msdos /dev/da8s1 /mnt

Copy the OpenBSD boot code to the ESP:

        cd /efimnt/EFI/BOOT
        cp /mnt/bootx64-openbsd.efi .

        vi refind.conf
Add the following section:
menuentry "OpenBSD" {
  loader /EFI/BOOT/bootx64-openbsd.efi
  icon /EFI/BOOT/icons/os_freebsd.png
}

Actually you can use any icon different from the ones for your other
OSs, as currently there is no OpenBSD icon. Now you can halt the system
to safely take out your USB stick:

        halt

After the system halts, take out the USB stick
Press any key to reboot.

After reboot, the following error occurs:
Login: reorder_kernel: failed — see
/usr/share/relink/kernel/GENERIC/relink.log: Simply run the command
suggested in the relink.log file:

        sha256 -h /var/db/kernel.SHA256 /bsd

Please double check that the file /var/db/kernel.SHA256 is created and
that you have not misspelled its name. Reboot the system:

        reboot

Now the reorder_kernel error message should be gone.

Install the firmware you saved on the USB stick. Insert the USB stick
and, assuming it is recognised as /dev/sd1 and the folder with the
firmware is OpenBSD_firmware:

        mount_msdos /dev/sd1i /mnt
        fw_update -p /mnt/OpenBSD_firmware iwm
Here I only install iwm, the driver for my wireless card. You have to
run the above command for all drivers you have downloaded.

        umount /mnt

Set up your internet connection, assuming your wlan device is iwm0:

        vi /etc/hostname.iwm0
Add these lines:
nwid your-router-name wpakey your-router-password
dhcp

The above is an example setting for a wireless DHCP internet. You have
to adjust that accordingly for your connection.

Start networking, assuming the wlan device is iwm0:

        /bin/sh /etc/netstart iwm0

Now you should have internet connection. Time to update all necessary
firmware: 

        fw_update

Congratulations! You have successfully installed OpenBSD in a multiboot
with rEFInd!

## Basic Postinstall Configuration

### Set hardware clock to local time instead of UTC:

OpenBSD uses UTC as system time instead of local time as most other
OSs.
This will prevent ntpd from synchronising time if your system time is
ahead of the local time. Time is never synchronised backwards by ntpd.
Therefore, the hardware clock must already be running at the desired
offset before booting OpenBSD. This can be achieved using
the kern.utc_offset parameter. This is the real-time clock's (RTC)
offset from Coordinated Universal Time (UTC) expressed as minutes East
of UTC+0. 

Create the file /etc/sysctl.conf if it does not already exist:

        vi /etc/sysctl.conf
For my time zone, which is Europe/Berlin, I have to add 1 hour of
offset. You have to figure out the correct offset for your time zone:
kern.utc_offset=+60

### Add your user:

        adduser

Add the user not only to the wheel group but also explicitly to the
wheel group in the /etc/group file, otherwise the user will not be
able to use the su command. To be able to power off as user in xfce,
invite
the user to the operator group. Alternatively, you can do this also
later by issuing: usermod -G operator your-user

### Enable xenodm:

        rcctl enable xenodm
        rcctl start xenodm

### If you have USB sound devices, enable USB sound: 

        rcctl set sndiod flags -f rsnd/0 -F rsnd/1
        rcctl restart sndiod

It is always a good idea to

        man afterboot

to see if something else is remaining to be set. 

OpenBSD is notorious for its perfect documentation. In
/usr/local/share/doc/pkg-readmes/ you can find relevant infos for a lot
of software.

Have fun with your new OpenBSD system!

Dear all,

multiboot installation of a BSD system with other operating systems
(OSs) on UEFI hardware is not officially supported by any of the popular
BSDs. Because of the general interest in this topic, here I would like
to share my experience of running DragonFly BSD, OpenBSD, and Slackware
Linux on an UEFI ASUS laptop. The only boot manager you need is
[rEFInd](http://www.rodsbooks.com/refind). The tutorial is appended at the
end of this post. I hope you will find it useful.

Best regards,

Martin Ivanov


# Installation of OpenBSD in a multiboot on a UEFI machine 

## Preliminaries

As each OS is going to reside on its own hard drive slice,
the first step of setting your system for multiboot is slicing the hard
drive. In general, if you want to multiboot n OSs, you would need n + 1
slices. The extra slice is for the EFI system partition (ESP). Of
course, you have to make sure each partition is large enough for the OS
that is going to reside on it. As mentioned, in this tutorial I share my
experience with installing DragonFly, OpenBSD, and Slackware Linux. I
sliced the hard drive from DragonFly, which I have exemplarily described
in the [DragonFly documentation on
multiboot](https://www.dragonflybsd.org/docs/handbook/Installation/#index6h1).
Of course, you will slice the hard drive from the first OS that you are
going to install. In the above link to the DragonFly documentation, I
have also described how the ESP is to be set up. Therefore, in the
following I assume your first OS has already been installed in its
slice, rEFInd has been installed in the ESP, and I only
consider the specifics of the OpenBSD installation.

## Installation of OpenBSD

First of all, I cannot enough recommend you to read the document 
https://ftp.openbsd.org/pub/OpenBSD/6.7/amd64/INSTALL.amd64. Of course,
this is for OpenBSD version 6.7, for a different OpenBSD version you
should update the version number accordingly.

Prepare the install medium for OpenBSD as described in the
[documentation](https://www.openbsd.org/faq/faq4.html#Download). If you
would need any additional firmware, make sure to download it to a USB
stick as [described in the documentation]
(https://www.openbsd.org/faq/faq4.html#Checklist). In my case with
OpenBSD-6.7, I had to go to http://firmware.openbsd.org/firmware/6.7/
and download the wireless driver I need (iwm-firmware-20191022p0.tgz).
Please make sure to download not only the respective *.tgz files but also
the SHA256.sig and index.txt files and store them together in the same
folder on the USB stick as the *.tgz file(s).

Boot the computer with the install medium. In the following, I will just
skim through the questions the installer asks that are not that obvious
how to answer (at least they weren't that obvious for me at the first
install :-))

Select (I)nstall

Do you want the X Window System to be started by xenodm? no (default)
You can always enable xenodm later. Setting no here makes sure after
booting you will be able to inspect the boot messages.

I do not configure network, because my wifi card needs the firmware to
be installed later.

Setup a user: no (default)
You can do this also after installing OpenBSD.

Which disk is the root disk: sd0
In your case the root disk maybe something else, please replace
accordingly.
Disk slicing:
We assume we have already created a disk slice for OpenBSD from the
other OS. Now we have to give that slice a type of A6, so that
the OpenBSD installer is able to recognise it. So, select your hard
drive when offered, and then select (E)dit. This will start an
interactive fdisk session. Typing p will show you the partition table.
If the partition for OpenBSD is number 2, setting its type to A6
involves the following command-line input:

	e 2
	t
	A6
	write
	quit

As we are going to use rEFInd as a boot manager, you do not need to
toggle a bootable flag on the OpenBSD partition.

Note: On subsequent installs, the OpenBSD installer detects the A6
partition and readily offers it as (O)penBSD area. 

Use (W)hole disk, use the (O)penBSD area, or (E)dit the GPT: OpenBSD
Select the OpenBSD area here, which is also the default choice.

Disklabel partitioning: 
Select a custom layout: C
We want to create a custom layout for the disklabel partitions to make
sure our file systems are large enough for our needs. For example, my
OpenBSD slice is 200 GiB. First, delete all partitions (note that c
cannot be deleted):

	z 

Then, I create the following layout:

Partition Size File System Mount Point
a         10g     4.2BSD            /
b         16g     swap
d         50g     4.2BSD            /usr
e         10g     4.2BSD            /var
f         15g     4.2BSD            /tmp
g         rest    4.2BSD            /home

Typing ? will help you figure out the exact commands you have to type to
create your desired layout. When you are ready with the partitioning,
save and quit:

	w
	q

Note: if you already have disklabel partitions, after selecting the
custom layout they will be present. In that case, you can simply only
provide mount points (using the command n). Only the partitions for
which you provide mount points will be formatted.

Which disk do you want to initialise: done (the default)
Location of sets? (cd disk ftp http or 'done'): disk
Is the disk partition already mounted?: no

Two further questions for the location of the sets follow. You should be
OK selecting the default answers.

Set name(s): done
Asks you to configure which sets to install. All are
preselected, so just hit Enter for done and everything will be
installed.

Directory does not contain SHA256.sig. Continue without verification: yes

Just accept the default when the installer asks the same question again:
Set names: done (default)

Toward the end of the installation you will obtain the following warning:

Installboot: no OpenBSD partition
Failed to install bootblocks.
You will not be able to boot OpenBSD from sd0

Unheed these warnings, we will take care for the booting right away with
rEFInd. The warnings may have to do with the fact that the ESP created
by DragonFly cannot be mounted by OpenBSD (at least on my machine it is
not possible; below you can see the error message I get).

If you have a multicore system, you need the smp-enabled kernel:

	mv /mnt/bsd /mnt/bsd.sp
	mv /mnt/bsd.mp /mnt/bsd

For a single-core machine, you can omit the previous step.

Plug in a USB stick to copy the OpenBSD boot code (it can be the same
stick where you downloaded the firmware). Note that as OpenBSD doesn't have
a dynamic devfs, the contents of /dev are generated by a script in the
same directory (MAKEDEV). Thus, only a few devices have nodes created by
default. You have to create the device nodes yourself manually as
follows.

We assume that the USB stick is recognised as sd2. Note that in
OpenBSD FAT disklabel partitions  are usually recognised as 'i':

	/bin/sh MAKEDEV sd2
	mount /dev/sd2i /mnt2

Copy the OpenBSD boot code to the USB stick:

	cp /mnt/usr/mdec/BOOTX64.EFI /mnt2/bootx64-openbsd.efi

Halt the machine to have time to take the USB stick out:

	halt

After the system halts, remove the usb sticks and boot into DragonFly
(or any of your already installed OSs, from which you can mount the ESP.
On my laptop I get a "mount_msdos: /dev/sd0i on /mnt: Device not
configured" error). The following instructions assume you booted into
DragonFly.

Mount the ESP:

	mount_msdos /dev/nvme0s0 /efimnt

Mount the USB stick with the boot code (assuming it is recognised as da8):

	mount_msdos /dev/da8s1 /mnt

Copy the OpenBSD boot code to the ESP:

	cd /efimnt/EFI/BOOT
	cp /mnt/bootx64-openbsd.efi .

	vi refind.conf
Add the following section:
menuentry "OpenBSD" {
  loader /EFI/BOOT/bootx64-openbsd.efi
  icon /EFI/BOOT/icons/os_freebsd.png
}

Actually you can use any icon different from the ones for your other
OSs, as currently there is no OpenBSD icon. Now you can halt the system
to safely take out your USB stick:

	halt

After the system halts, take out the USB stick
Press any key to reboot.

After reboot, the following error occurs:
Login: reorder_kernel: failed — see
/usr/share/relink/kernel/GENERIC/relink.log: Simply run the command
suggested in the relink.log file:

	sha256 -h /var/db/kernel.SHA256 /bsd

Please double check that the file /var/db/kernel.SHA256 is created and
that you have not misspelled its name. Reboot the system:

	reboot

Now the reorder_kernel error message should be gone.

Install the firmware you saved on the USB stick. Insert the USB stick
and, assuming it is recognised as /dev/sd1 and the folder with the
firmware is OpenBSD_firmware:

	mount_msdos /dev/sd1i /mnt
	fw_update -p /mnt/OpenBSD_firmware iwm
Here I only install iwm, the driver for my wireless card. You have to
run the above command for all drivers you have downloaded.

	umount /mnt

Set up your internet connection, assuming your wlan device is iwm0:

	vi /etc/hostname.iwm0
Add these lines:
nwid your-router-name wpakey your-router-password
dhcp

The above is an example setting for a wireless DHCP internet. You have
to adjust that accordingly for your connection.

Start networking, assuming the wlan device is iwm0:

	/bin/sh /etc/netstart iwm0

Now you should have internet connection. Time to update all necessary
firmware: 

	fw_update

Congratulations! You have successfully installed OpenBSD in a multiboot
with rEFInd!

## Basic Postinstall Configuration

### Set hardware clock to local time instead of UTC:

OpenBSD uses UTC as system time instead of local time as most other OSs.
This will prevent ntpd from synchronising time if your system time is
ahead of the local time. Time is never synchronised backwards by ntpd.
Therefore, the hardware clock must already be running at the desired
offset before booting OpenBSD. This can be achieved using
the kern.utc_offset parameter. This is the real-time clock's (RTC)
offset from Coordinated Universal Time (UTC) expressed as minutes East
of UTC+0. 

Create the file /etc/sysctl.conf if it does not already exist:

	vi /etc/sysctl.conf
For my time zone, which is Europe/Berlin, I have to add 1 hour of
offset. You have to figure out the correct offset for your time zone:
kern.utc_offset=+60

### Add your user:

	adduser

Add the user not only to the wheel group but also explicitly to the
wheel group in the /etc/group file, otherwise the user will not be
able to use the su command. To be able to power off as user in xfce, invite
the user to the operator group. Alternatively, you can do this also
later by issuing: usermod -G operator your-user

### Enable xenodm:

	rcctl enable xenodm
	rcctl start xenodm

### If you have USB sound devices, enable USB sound: 

	rcctl set sndiod flags -f rsnd/0 -F rsnd/1
	rcctl restart sndiod

It is always a good idea to

	man afterboot

to see if something else is remaining to be set. 

OpenBSD is notorious for its perfect documentation. In
/usr/local/share/doc/pkg-readmes/ you can find relevant infos for a lot
of software.

Have fun with your new OpenBSD system!

Reply via email to