Install an OS without KVM on Hetzner » 21 March 2024

I wanted to install RHEL on a Hetzner bare metal server, but there was a large demand for KVMs and I didn’t want to wait. I’ve found a tutorial on how to install Proxmox from the Hetzner rescue system - here’s how to do it for (almost) any OS.

Step 0: Boot into the rescue system

This is business as usual - go to the Hetzner robot, select your server, and boot into the rescue system. You’ll get an email with the root password or you can use your public keys.

Step 1: Preparations

First, we need to grab an image of the OS we want to install. I’ll use RHEL 9 as an example, but you can use any OS you want.

Then acquire the network configuration from the rescue system, you might need it later. For RHEL, it’s not necessary, you can just set your network configuration in the installer to automatic, then DHCP will handle the rest. It was necessary for Proxmox, though.

INTERFACE_NAME=$(udevadm info -q property /sys/class/net/eth0 | grep "ID_NET_NAME_ONBOARD=" | cut -d'=' -f2)
IP_CIDR=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}')
GATEWAY=$(ip route | grep default | awk '{print $3}')
IP_ADDRESS=$(echo "$IP_CIDR" | cut -d'/' -f1)
CIDR=$(echo "$IP_CIDR" | cut -d'/' -f2)

The INTERFACE_NAME might need some tweaking, ID_NET_NAME_ONBOARD may not exist.

Step 2: Install the OS via QEMU

Kick off the installation with QEMU. You can use the following command as a template, just replace the image and the disk with your own.

# Get the primary and secondary disks
PRIMARY_DISK=$(lsblk -dn -o NAME,SIZE,TYPE -e 1,7,11,14,15 | sed -n 1p | awk '{print $1}')
SECONDARY_DISK=$(lsblk -dn -o NAME,SIZE,TYPE -e 1,7,11,14,15 | sed -n 2p | awk '{print $1}')

# Kick off QEMU with CDROM
qemu-system-x86_64 -daemonize -enable-kvm -m 10240 \
-hda /dev/$PRIMARY_DISK \
-hdb /dev/$SECONDARY_DISK \
-cdrom /tmp/rhel-9.3.iso -boot d -vnc :0,password=on -monitor telnet:127.0.0.1:4444,server,nowait

# Set VNC password
echo "change vnc password <VNC_PASSWORD>" | nc -q 1 127.0.0.1 4444

Alternatively, if you have more than 2 disks, you can use -hda /dev/sda -hdb /dev/sdb -hdc /dev/sdc -drive file=proxmox-ve.iso,index=3,media=cdrom or similar, because -cdrom conflicts with -hdc.

Now you can connect to the VNC server with your favorite VNC client over port 5900.

If your server uses UEFI boot, you need to add -bios /usr/share/qemu/OVMF.fd to the QEMU command, or wherever your OVMF.fd is. (Hint: updatedb+locate)

After your OS is installed, you can shut down the QEMU session:

printf "quit\n" | nc 127.0.0.1 4444

Step 3: Boot into the installed OS - still in QEMU

After the installation is finished, reboot the guest OS, then restart the QEMU session:

# Kick off QEMU without CDROM
qemu-system-x86_64 -daemonize -enable-kvm -m 10240 \
-hda /dev/$PRIMARY_DISK \
-hdb /dev/$SECONDARY_DISK \
-vnc :0,password=on -monitor telnet:127.0.0.1:4444,server,nowait \
-net user,hostfwd=tcp::2222-:22 -net nic
# Did you use UEFI boot before? Make the same changes here.

# Set VNC password
echo "change vnc password <VNC_PASSWORD>" | nc -q 1 127.0.0.1 4444

Connect to the guest via VNC again, and copy the network settings from step 1, also make sure you can log in remotely from the server.

This is the time to grab your public keys and add them to the guest OS.

Pro tip: curl https://github.com/username.keys >> ~/.ssh/authorized_keys

Step 4: Wrapping up

Shut down the guest OS gracefully:

printf "system_powerdown\n" | nc 127.0.0.1 4444

Then reboot the rescue system.