Consult With Simon

Preparing a Debian ISO for Use in OpenBSD VM

A serial console must be enabled to install an OS in a virtual machine on OpenBSD, and as some of the install media comes without supporting it, it needs to be enabled first. The easiest way is to reuse an existing ISO and only modify the boot configuration.

The steps below produce a working ISO image as of October 2024.

Required tools

The tool to (re)create the ISO image used here is xorriso and needs to be installed first, as well as GnuPG, to verify the downloaded ISO file is authentic:

doas pkg_add xorriso gnupg

Working directory

Putting things in a separate directory to keep the place tidy:

mkdir -p debian-serial-iso/mnt
cd debian-serial-iso

Download ISO

Get the install media from an official source and make sure the checksum matches and the signature is correct according to the official signing public key:

ftp https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.7.0-amd64-netinst.iso
ftp https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA512SUMS
ftp https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA512SUMS.sign
sha512 -c -C SHA512SUMS debian-12.7.0-amd64-netinst.iso
gpg --keyserver keyring.debian.org --recv 6294BE9B
gpg --verify SHA512SUMS.sign SHA512SUMS

Extract files

Mount ISO images, copy all files from the installation media, unmount again, and adjust permissions to allow changes:

doas vnconfig vnd0 debian-12.7.0-amd64-netinst.iso
doas mount -t cd9660 /dev/vnd0c mnt
cp -R mnt new
doas umount mnt
doas vnconfig -u vnd0
chmod -R u+w new

Enable serial console

A few simple changes to the isolinux configuration files to enable the serial console at boot:

patch -l <<EOF
--- mnt/isolinux/isolinux.cfg   Sat Aug 31 12:41:34 2024
+++ new/isolinux/isolinux.cfg   Thu Oct  3 06:13:07 2024
@@ -1,7 +1,7 @@
 # D-I config version 2.0
 # search path for the c32 support libraries (libcom32, libutil etc.)
+serial 0 115200
+console 0
 path 
-prompt 0
-timeout 0
 include menu.cfg
 default vesamenu.c32
--- mnt/isolinux/txt.cfg    Sat Aug 31 12:41:34 2024
+++ new/isolinux/txt.cfg    Thu Oct  3 06:13:07 2024
@@ -1,4 +1,6 @@
+default install
 label install
    menu label ^Install
+   menu default
    kernel /install.amd/vmlinuz
-   append vga=788 initrd=/install.amd/initrd.gz --- quiet 
+   append vga=788 initrd=/install.amd/initrd.gz --- console=ttyS0,115200n8
--- mnt/isolinux/adtxt.cfg  Sat Aug 31 12:41:34 2024
+++ new/isolinux/adtxt.cfg  Thu Oct  3 06:13:07 2024
@@ -1,7 +1,7 @@
 label expert
    menu label E^xpert install
    kernel /install.amd/vmlinuz
-   append priority=low vga=788 initrd=/install.amd/initrd.gz --- 
+   append priority=low vga=788 initrd=/install.amd/initrd.gz --- console=ttyS0,115200n8
 include rqtxt.cfg
 label auto
    menu label ^Automated install
EOF

Clean up when all went well:

rm new/isolinux/{adtxt,txt,isolinux}.cfg.*

Create new ISO

Below are the steps for creating a new ISO image based on the official instructions.

Extract MBR

Get MBR from the original ISO image to use for the new ISO:

dd if=debian-12.7.0-amd64-netinst.iso bs=1 count=432 of=isohdpfx.bin

Adjust build command

To use the original command with a few changes to create a new ISO image:

sed -e 's! -checksum[^ ]* [^ ]*!!g;
        s! -jigdo-[^ ]* [^ ]*!!g;
        s! -o [^ ]*! -o debian-12.7.0-amd64-netinst-serial.iso!;
        s! \(-isohybrid-mbr\) [^ ]*! \1 isohdpfx.bin!;
        s! boot1 CD1! new!;
    ' new/.disk/mkisofs > mkisofs

Write new ISO

Execute the adjusted command to write the new ISO image:

sh mkisofs

Installation

The only thing to mention regarding the Debian installer is to select virtio in the network driver selection; everything else is the same as any other Debian installation.

On the OpenBSD side of this are the tap(4) network interfaces, with addresses in the 100.64.0.0/10 IPv4 range, as described in vmctl(8) - LOCAL INTERFACES.

Links

Next to the manual pages, the following links provided insights or pointed in the right direction:

2024-10-15

Step-by-step guide that explains how to create a custom ISO image with serial console enabled.

openbsd, debian, linux, serial, console, vm