Running Arch Linux using OpenBSD vmd(8)

    

I had difficulties running Linux as a virtual machine using OpenBSD vmd(8). Ubuntu LTS crashed during installation wizard, Debian 9 does not seem to ship with virtio drivers, Alpine randomly freezes the console and Slackware … well slack has not been updated in years. Arch Linux seems to run well. And as I didn’t find a complete guide to install and run it using OpenBSD vmd(8), here are my notes.

Creating the virtual machine

First things first, create a virtual disk for the virtual machine.

# mkdir -p /home/vm/hoth
# cd /home/vm/hoth
# vmctl create hoth.qcow2 -s 20G
# ftp http://archlinux.mirrors.ovh.net/archlinux/iso/2019.07.01/archlinux-2019.07.01-x86_64.iso
# more /etc/vm.conf
(...)
vm "template" {
  disable
  disk "/dev/null"
  memory 512M
  interface {
    group "vm"
    switch "vswitch0"
  }
}

The Arch Linux VM will be installed using my template VM. This allows specific parameters from the vmctl(8) command and automatic network configuration that will match my pf(4) rules.

Installing Arch Linux

Boot the virtual machine using the ISO file and attaching a console:

# vmctl start hoth -c -t template -B cdrom -d ./hoth.qcow2 \
  -r ./archlinux-2019.07.01-x86_64.iso

When the boot loader appears, hit . The enter “ console=ttyS0,115200” and hit . This will boot Arch Linux using the console.

From there, follow the official installation guide. Here’s the things I did:

Arch Linux 5.1.15-arch1-1-ARCH (ttyS0)

archiso login: root
Last login: Thu Jul 4 22:19:58 on tty1
root@archiso ~ # ip address
(...)
2: enp0s2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether fe:e1:bb:d1:0f:ad brd ff:ff:ff:ff:ff:ff
    inet 10.15.5.71/24 brd 10.15.5.255 scope global noprefixroute enp0s2
(...)

root@archiso ~ # timedatectl set-ntp true

root@archiso ~ # fdisk -l
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
(...)
root@archiso ~ # fdisk /dev/vda
(...)
Command (m for help): p
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbf91d445

Device     Boot    Start      End  Sectors Size Id Type
/dev/vda1           2048 20973567 20971520  10G 83 Linux
/dev/vda2       20973568 29362175  8388608   4G 82 Linux swap / Solaris
/dev/vda3       29362176 41943039 12580864   6G 83 Linux

root@archiso ~ # mkfs.ext4 /dev/vda1
root@archiso ~ # mkfs.ext4 /dev/vda3
root@archiso ~ # mkswap /dev/vda2

root@archiso ~ # mount /dev/vda1 /mnt
root@archiso ~ # pacstrap /mnt base
==> Creating install root at /mnt
==> Installing packages to /mnt
:: Synchronizing package databases...
(...)
pacstrap /mnt base  8.30s user 3.61s system 6% cpu 3:10.48 total

root@archiso ~ # swapon /dev/vda2
root@archiso ~ # mount /dev/vda3 /mnt/var/log
root@archiso ~ # genfstab -U /mnt >> /mnt/etc/fstab

root@archiso ~ # arch-chroot /mnt

[root@archiso /]# ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
[root@archiso /]# hwclock --systohc

[root@archiso /]# vi /etc/locale.gen
en_US.UTF-8 UTF-8
en_US ISO-8859-1
fr_FR.UTF-8 UTF-8
fr_FR ISO-8859-1
fr_FR@euro ISO-8859-15
[root@archiso /]# locale-gen
Generating locales...
(...)
Generation complete.
[root@archiso /]# echo 'LANG=en_US.UTF-8' > /etc/locale.conf

[root@archiso /]# echo 'hoth' > /etc/hostname
[root@archiso /]# echo '127.0.0.1 hoth.tumfatig.local hoth' >> /etc/hosts
[root@archiso /]# cp /etc/netctl/examples/ethernet-dhcp /etc/netctl/enp0s2
[root@archiso /]# vi /etc/netctl/enp0s2
Description='A basic dhcp ethernet connection'
Interface=enp0s2
Connection=ethernet
IP=dhcp
[root@hoth ~]# netctl enable enp0s2

[root@archiso /]# passwd root
New password:
Retype new password:
passwd: password updated successfully

[root@archiso /]# pacman -S syslinux
[root@archiso /]# syslinux-install_update -i -a -m
Syslinux BIOS install successful
(...)
Installed MBR (/usr/lib/syslinux/bios/mbr.bin) to /dev/vda
[root@archiso /]# diff -U2 /tmp/syslinux.cfg.orig /boot/syslinux/syslinux.cfg
--- /tmp/syslinux.cfg.orig 2019-04-03 20:29:47.000000000 +0200
+++ /boot/syslinux/syslinux.cfg 2019-07-04 23:01:00.891684476 +0200
@@ -52,5 +52,5 @@
MENU LABEL Arch Linux
LINUX ../vmlinuz-linux
- APPEND root=/dev/sda3 rw
+ APPEND root=/dev/vda1 rw console=ttyS0,115200
INITRD ../initramfs-linux.img

@@ -58,5 +58,5 @@
MENU LABEL Arch Linux Fallback
LINUX ../vmlinuz-linux
- APPEND root=/dev/sda3 rw
+ APPEND root=/dev/vda1 rw console=ttyS0,115200
INITRD ../initramfs-linux-fallback.img

[root@archiso /]# exit
root@archiso ~ # umount -R /mnt
root@archiso ~ # halt -p
[         Stopping Session 3 of user root.
(...)
[  455.635617] reboot: System halted

[EOT]

Configuring the Arch Linux VM

Now that Arch Linux is installed, the final vmd(8) configuration can be done.

# vi /etc/vm.conf
(...)
vm "hoth" {
#  disable
  memory 4G
  disk "/home/vm/hoth/hoth.qcow2"
  interface {
    group "vm"
    locked lladdr fe:e1:ba:d2:50:75
    switch "vswitch0"
  }
}

# vmctl reload
# vmctl console hoth
Connected to /dev/ttyp4 (speed 115200)

hoth login: root
Password:
[root@hoth ~]#

So far, it seems to run OK.