PiKVM using a Raspberry Pi Zero 2W

       1027 words, 5 minutes

My new OpenBSD server / toy is a fanless barebone that is supposed to be connected to an HDMI monitor and a USB keyboard. The serial console port is only available since OpenBSD boots.

So I decided to assemble a KVM using a Raspberry Pi Zero and the PiKVM software to be able to gain full access to the BIOS and bootloader via the network.

The hardware

There’s a few hardware required to get a KVM installation out of a Pi. I got myself:

The X630 modules comes with FPC cables, spacers and screws. Those are mostly made to match a Pi 4 configuration. Properly connecting it to the Pi Zero requires extra fixing parts ; which I have not. So I managed to assemble parts with the bits I had.

The software

I’ve used the PiKVM Open Source project. I’m following the DIY path, using hardware for v2.

Download the software. Browse to https://pikvm.org/download/ , look at the “Raspberry Pi Zero 2 W, v2 platform” section and download the latest image for HDMI-to-CSI bridge. The file was named “v2-hdmi-zero2w-latest.img.xz”.

Extract the archive, insert the µSD card into a computer and flash the OS. Using a Manjaro installation, I did:

$ sudo dd if=v2-hdmi-zero2w-latest.img of=/dev/sda bs=1M

When done, remove the µSD card. And reinsert it for later configuration. It may not be necessary to eject/insert the card. But memory muscle says to do so after a dd operation.

Configure Wi-Fi

The Raspberry Pi Zero 2 W has not ethernet port ; only Wi-Fi. And as I don’t have an HDMI monitor, I need a tweak to auto-configure wireless connection on first boot.

Connect the µSD card to a Linux system, mount the FAT32 partition and add the wireless parameters to the “pikvm.txt” file:

# fdisk -l sda
(...)
Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1              1   524287   524287  256M  c W95 FAT32 (LBA)
/dev/sda2         524288 12500000 11975713  5,7G 83 Linux
/dev/sda3       12500001 61067263 48567263 23,2G 83 Linux

# mount /dev/sda1 /mnt
# vim /mnt/pikvm.txt
FIRST_BOOT=1
WIFI_ESSID="changeme"
WIFI_PASSWD="changeme"
# sync && umount /mnt

Remove the µSD card and plug it into Raspberry Pi.

You may connect the mini HDMI connector to an external monitor but it is not required. Connect the PWR IN micro-USB to power and let the Pi boot.

The Pi boots a first time. The system runs “first boot” routines and reboot automatically. On the next reboot, the Pi should get an IP address via the wireless connection ; the IP address is printed on the screen. If you have no HDMI monitor connected, check your wireless router logs. Beware that wireless configuration is not permanent yet ; if the Pi reboots now, it will loose wireless configuration.

Browse to the Web interface using https://obtained_ip/login/. The default credentials are admin/admin.

Click the “Terminal” button to access a Web console and configure WiFi properly. Check the documentation :

$ su -                                    # default passwd is root
# rw
# vim /etc/systemd/network/wlan0.network  # everything is set properly
# wpa_passphrase myssid 'mywpa' >         \
  /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
# systemctl enable wpa_supplicant@wlan0.service
# ro
# reboot

This time, the Pi should boot with a permanent WiFi connection enabled.

Apply a bit of security

Passwords can be changed from the terminal ; either the Web session or SSH. The default root/root credentials works using SSH so you’d better change this:

# rw

# passwd root              # Change the OS root password
# kvmd-htpasswd set admin  # Change the Web admin password
# systemctl restart kvmd kvmd-nginx

# mkdir ~/.ssh
# cat > ~/.ssh/authorized_keys
ssh-(...)

# vi /etc/ssh/sshd_config
(...)
PermitRootLogin prohibit-password
(...)
PasswordAuthentication no
# systemctl restart sshd

# ro

Update PiKVM

From the console, use an ArchLinux magic spell:

# rw
# pacman -Syu
# reboot

The update takes a bit of time. Load average goes up to 5 and the wait states indicate either the Pi or the µSD storage are slow ; or both :)

The online documentation says:

Pacman saves all installed packages in a compressed format so that you can roll back to the old version if something goes wrong. After you’ve updated and made sure everything works, it makes sense to clear the package cache so that it doesn’t take up space on the SD card: rw; rm -rf /var/cache/pacman/pkg; ro.

On reboot, the updated software is ready to use ; and the wireless connection kept working.

Connecting to an OpenBSD system

Connect the Raspberry PWR IN micro USB port to a 5V DC 2.5A power source.

Connect the Raspberry On-The-Go (OTG) micro USB port to one of the USB server port.

Connect the X630 HDMI input to the HDMI server port.

On my OpenBSD 7.1 system, the PiKVM devices are identified as:

uhidev0 at uhub0 port 7 configuration 1 interface 0 "PiKVM Composite KVM Device" rev 2.00/1.00 addr 4
uhidev0: iclass 3/1
ukbd0 at uhidev0: 8 variable keys, 6 key codes
wskbd0 at ukbd0: console keyboard, using wsdisplay0
uhidev1 at uhub0 port 7 configuration 1 interface 1 "PiKVM Composite KVM Device" rev 2.00/1.00 addr 4
uhidev1: iclass 3/0
ums0 at uhidev1: 8 buttons, Z and W dir
wsmouse0 at ums0 mux 0
umass1 at uhub0 port 7 configuration 1 interface 2 "PiKVM Composite KVM Device" rev 2.00/1.00 addr 4
umass1: using SCSI over Bulk-Only
scsibus5 at umass1: 2 targets, initiator 0
cd0 at scsibus5 targ 1 lun 0: <PiKVM, CD-ROM Drive, 0515> removable

I have not tested the virtual CD drive. But the HDMI output and USB input allows managing the BIOS and monitor the sysupgrade process.

So far, so good.