Or, how I learned to stop worrying about which hosting providers supported my OS and love QEMU/KVM
So uh recently I was thinking about migrating my main server (the one that hosts, among other things, this website) to a new, improved, cleaner server. The one that runs this is on debian, lived through wheezy, jessie and stretch, and since I’ve experimented on it a fair bit in the ~4 years it’s been running, is littered with weird projects and packages that shouldn’t be installed and stuff. Yeah, that’s practically the definition of “bad admin practices”, but I was young(er) when this server started running.
Anyway, I was thinking of upgrading to a new server with FreeBSD, and using Jails to isolate the services (it’s, uh, still a WIP). Since I like Online.net a lot when it comes to hosting servers (they’re relatively cheap and they provide good service, which is all I ask generally), and that they support FreeBSD, I decided to order a server from them and work on the migration over the next few weeks.
Alas! After ordering the server, it appears they only support FreeBSD on UFS! Since I was born after 1983, I didn’t want to use UFS as root on a FreeBSD server, that would be a waste! So, obviously, I decided to use the KVM-over-IP access they provide to load up an ISO and install things my way.
Well, I was a fool, cause the class of server I ordered (the cheapest) don’t have KVM-over-IP! That’s a feature reserved for the slightly more expensive ones. But I didn’t want to upgrade and pay more per month, so I thought and thought, and I ended up coming with the following solution
So the idea is pretty simple: spawn a Qemu VM, with its first disk being the server’s physical disk, and the ISO of the OS you want to install. Then perform a simple installation, fix things up a bit (network interface name/IP, stuff like that), reboot, and profit.
What I did for FreeBSD 11 specifically was
sudo apt install qemu-kvm wget http://ftp.fr.freebsd.org/mirrors/ftp.freebsd.org/releases/ISO-IMAGES/11.1/FreeBSD-11.1-RELEASE-amd64-disc1.iso qemu-system-x86_64 -hda /dev/sda -cdrom FreeBSD-11.1-RELEASE-amd64-disc1.iso -net nic,model=e1000 -curses -boot d
Then, do the install in the, uh, even-uglier-than-usual environment of the curses Qemu interface. Nothing special about this, it’s a standard FreeBSD install. Afterwards, spawn a shell, edit /etc/rc.conf
ifconfig_igb0="inet xxx.xxx.xxx.xxx netmask 255.255.255.0" defaultrouter="xxx.xxx.xxx.xxx"
Reboot, and your server should come up. If it doesn’t, well, you can always boot the recovery FreeBSD system to see what’s wrong, or reinstall and retry.
Of course, I’m speaking about FreeBSD here but this works with any target OS, linux, FreeBSD, Windows, Haiku, Plan9… whatever.
It’s kinda hacky, but