Install Fedora on headless remote servers
or "Freeeeeedom of OS choice" Fri 14 May 2021Context
I run this website on a dedicated server hosted by OVH from their Kimsufi product range. I've had this server for a long time now and even though they publicly advertise that one can install Fedora (and many other) distribution on that product line, they cannot (or don't want to) give me the option to do it on my dedicated server, therefore I had to come up with something to install Fedora without OVH giving me the option to do so.
I did this 2 years ago, it was painful but I thought it was a one time thing to do, so I didn't document the process. Fast forward to about a month ago, I started the Fedora 34 upgrade. When the packages are installed, Fedora reboots into a very simple system where old version packages are replaced by new version packages. In that scenario, obviously no network is needed so the server does not respond to pings. Turns out I had monitoring of my server enabled and the technician seeing a logging screen but no ping hard rebooted my server while it was upgrading. I tried to recover it for a day, gave up and went through a day and half of pain to reinstall Fedora. The hard thing with those servers is that there's no console access, only SSH is available, so if your distribution does not setup the network or does not boot, you have no indication on what went wrong. Now that I've struggled twice, it's time for me to document the process so that next time my server is messed up or I change my server, I can reinstall Fedora in the blink of an eye.
Steps
- Install an officially supported distribution from your cloud provider dashboard. From my Kimsufi dashboard, I selected CentOS 7 because it's made by Red Hat too but any distribution which uses GRUB2 as bootloader will do just fine.
- SSH to your new server OS,
- Download the PXE boot images from Fedora. For release 34, they are available here. I installed
wgetby runningyum install wgetand then ran:
wget https://mirror.karneval.cz/pub/linux/fedora/linux/releases/34/Server/x86_64/os/images/pxeboot/initrd.img
wget https://mirror.karneval.cz/pub/linux/fedora/linux/releases/34/Server/x86_64/os/images/pxeboot/vmlinuz
- Put both files in the
/bootdirectory. I renamed the file to more or less match the naming convention in my/bootdirectory.vmlinuzbecamevmlinuz-fc34andinitrd.imgbecameinitrd-fc34.img. - Check whether the
/bootdirectory is in its own partition or not by running this command:df /boot. If you have/bootin the columnMounted on, it is on its own partition, therefore no/bootprefix needed in the next step. If it says/, then you need to have/bootas a prefix in the next step. On my CentOS 7 installation,/bootis mounted on/so I add the/bootprefix in the next step. - In order to have access to the Fedora installer that starts with the PXE boot image on a headless server, you need to access it via VNC. This can be done by adding
inst.vncandinst.vncpassword=<password>.<password>should be 7 characters long. 6 and 8 characters length are supposed to be supported but it didn't work for me. - Edit your GRUB2 configuration file to add a GRUB entry for this kernel and initrd images. On CentOS 7, you just need to add your entry to
/etc/grub.d/40_customfile since all files in/etc/grub.d/are appended to the final configuration file. The file should look like this:
menuentry 'FedoraNetInstall' {
load_video
set gfxpayload=keep
insmod gzi
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
linux16 /boot/vmlinuz-fc34 ip=dhcp inst.repo=https://download.fedoraproject.org/pub/fedora/linux/releases/34/Server/x86_64/os inst.vnc inst.vncpassword=test123
initrd16 /boot/initrd-fc34.img
}
N.B.: on Debian 9 and Fedora 34, the linux16 and initrd16 are respectively linux and initrd but the content stays the same (+- the /boot prefix).
N.B.2: Check that the settings before linux16 are similar to the ones you have in entries listed in /boot/grub2/grub.cfg, specifically the set root one.
N.B.3: Quadruple check that there are no typo anywhere in this file (I lost a few hours because I put /boot/initramfs-fc34.img instead of the above after initrd16)
- Make a backup of
/boot/grub2/grub.cfg:cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak - Add your menuentry to
grub.cfgby running:grub2-mkconfig -o /boot/grub2/grub.cfg - In order to make sure you boot next time into your new menuentry but that if it fails to boot the next menuentry to be selected at next boot will be your current OS, run
grub2-set-default 0andgrub2-reboot FedoraNetInstall. - Reboot your machine.
- Check there's a ping after a few minutes (servers take a much longer time than consumer desktops or laptops to boot so be patient :) ).
- Install a VNC client on your computer. I used TigerVNC on Fedora which I installed with
dnf install -y tigervnc. From the command line, runvncviewer <remote server IP>:<vnc port>. Or from the GUI, just start TigerVNC and configure it to connect to your server. By default,vnc portis 5901. One can use the1equivalent too. - Configure your new Fedora installation and wait for it to reboot.
- Profit.
Source:
Quentin Schulz