Since i'm always asking a ton of questions i thought it might be time to give a little something back to the massively friendly NetBSD community (or rather BSD community as a whole since this howto can be pretty much used for any system not officially supported by Hetzner).
For simplicity reasons i'll be using hcloud
(Hetzner's CLI cloud management tool which can be downloaded at https://github.com/hetznercloud/cli with a basic demonstration available at https://community.hetzner.com/tutorials/howto-hcloud-cli but everything shown here can obviously also be done through Hetzner's cloud panel.
1. Preparation
First off make sure that you have a working cloud API token for use with hcloud
(https://docs.hetzner.com/cloud/api/getting-started/generating-api-token/) and that it's stored safely.
At this point you can use hcloud server-type list
to check the available VM types and select one that fits your needs (at the time of writing the API sadly doesn't list the actual hourly rates of the various VMs, so you'll need to check the website to figure those out at https://www.hetzner.com/cloud/#pricing - small shared CPU instances are currently starting at around 0.7 euro-cent).
ARM systems aren't covered by this tutorial but really shouldn't make much of a difference beyond having Qemu emulate an ARM system.
The available locations can be listed using hcloud datacenter list
(at this time various datacenters in either Germany, Finland or the US).
2. Creating a system disk image
From my experience the smaller shared CPU VMs boot using legacy BIOS while the dedicated CPU instances use EFI. Networking is always supplied by a virtio device with configuration handled by DHCP (meaning networking will just work with the settings detected during installation in Qemu). Going by this information using Qemu to prepare the disk image will look more or less like this:
truncate -s 10G /path/to/disk/image.raw
qemu-system-x86_64 -cpu host -m 1G -smp cores=1 -boot d -no-reboot -vnc :1 -netdev user,id=user0 -device virtio-net,netdev=user0 -drive file=/path/to/disk/image.raw,format=raw -drive file=/path/to/NetBSD/installation.iso,media=cdrom,format=raw,read-only
or in case of a VM that's going to be booted by EFI:
truncate -s 10G /path/to/disk/image.raw
qemu-system-x86_64 -bios /usr/share/qemu/OVMF.fd -cpu host -m 1G -smp cores=1 -boot d -no-reboot -vnc :1 -netdev user,id=user0 -device virtio-net,netdev=user0 -drive file=/path/to/disk/image.raw,format=raw -drive file=/path/to/NetBSD/installation.iso,media=cdrom,format=raw,read-only
You should obviously adjust the size of your virtual harddisk (the example uses 10G, which unsurprisingly is a 10GB image) to the amount your target VM supports and what you actually need (smaller images might take a little less time to install).
Depending on which kind of system you use to create the image it might make sense to add -enable-kvm
or whatever option is available to enable hardware acceleration and thereby speed up the installation process.
Once Qemu is running use your favorite VNC viewer to complete the installation (it's likely also possible to have Qemu redirect the VM's console output to stdout but i won't cover that here). Using gvncviewer that would look something like this (replace 127.0.0.1 with the appropriate IP of the host Qemu is running on - the relevant port being 5900 + display number):
gvncviewer 127.0.0.1:1
Once you finished installing the system choose to reboot, which will cause Qemu to exit. After that you compress the disk image using:
xz -9 /path/to/disk/image.raw
3. Creating the VM
hcloud server create --datacenter hel1-dc2 --type cx11 --start-after-create=false --image debian-10 --name test
This creates a cx11 VM instance (the smallest type available) named 'test' in Helsinki and tells you what IP was assigned to it (you should write that down but if you somehow lose it you will always be able to look it up using hcloud server list
). You should adjust the type and datacenter to your actual requirements. Also note the --start-after-create=false
which is needed as we will never boot into the selected Debian 10 system. After the VM has been deployed we will activate rescue mode and start the system:
hcloud server enable-rescue test
hcloud server poweron test
Enabling rescue will tell you to root password for the rescue system. Make sure to keep that handy as otherwise you will need to repeat this step.
4. Installing the system
We now wait for the VM to boot and then (i.e. when ssh finally manages to connect) run the following command (obviously replacing 1.2.3.4 with the IP of your VM):
cat /path/to/disk/image.raw.xz | ssh root@1.2.3.4 'xz -d | dd if=/dev/stdin of=/dev/sda bs=1M'
Depending on the speed of your internet connection that might take a while even if from my experience the compressed disk images aren't overly large (a rather minimal image with pkgsrc installed is around 300MB). If the time needed to upload the image is unreasonable long on your connection you can obviously also prepare and upload the image from another server thereby cutting the length to a mere couple seconds.
5. Booting NetBSD
Once the image transfer is complete all that's left to do is disabling rescue mode and restarting the VM:
hcloud server disable-rescue test
hcloud server reset test
Voila! Once your VM has finished booting you can now log into your shiny new NetBSD VPS using the SSH daemon you hopefully setup during the installation. If you forgot that or have some other problem with connecting to your VM Hetzner's cloud panel also has a VNC console (https://docs.hetzner.com/cloud/servers/getting-started/vnc-console) you can use to debug the issue.
6. Removing your VM
If you no longer need the VM all you'll have to do is shut it down and delete it (being billed by the hour it makes sense to remove any unneeded VMs as soon as possible):
hcloud server poweroff test
hcloud server delete test
If you plan to continue using the system somewhere in the future you can also reverse the process described earlier to pull a snapshot of your disk which you can later use to restore the system. To do so you would first make sure to cleanly shutdown your VM (basically by running shutdown -h now
as root after doing whatever other manual steps your system requires as hcloud's poweroff
/reset
pretty much equal pulling the plug/hitting the reset button and therefore don't give your VM a chance to do any possibly required housekeeping, which usually isn't that big of a deal but at least in theory could result in data loss) and then adjust the deletion process as follows:
hcloud server enable-rescue test
hcloud server reset test
ssh root@1.2.3.4 'dd if=/dev/sda of=/dev/stdout bs=1M | xz -9' > /path/to/snapshot.raw.xz
hcloud server poweroff test
hcloud server delete test
7. Possible problems
I've had a 16 core shared CPU VM kernel panic on me during boot over something related to console initialization. If that happens editing boot.cfg on your system disk image to use com0 as console will likely fix it. This obviously also means that the VNC console in the cloud panel is no longer usable though as the VM now expects console input on com0.