Setting Up RHEL 8 on Linode

Background

I have used Linode for about 10 years now because the service and price are great. They are one of the most automated cloud providers and they invest in tools to do things like resizing existing VMs. It’s super useful for lab environments and experiments.  As such, I wanted to use Linode for my new containers running Red Hat UBI on RHEL 8 and eventually OpenShift. There’s just one problem –  no RHEL 8 on Linode, and CentOS 8 isn’t out yet, so Linode hasn’t developed a working process yet.

So, I decided to draw my sysadmin katana and reverse engineer the Linode tools to make it work. Following these instructions, it should take you 5 or 10 minutes to create a RHEL 8 golden image.  Hopefully, this will save you the 10 hours of work it took me to figure out all of the nuances.

Enjoy 🙂

Process

This process will leave you with a fully working RHEL 8 virtual machine image on Linode. You can shrink and expand it, deploy from it, snapshot it for backups just like you would be able to do with an official Linode image. Let’s get started.

On cloud.linode.com

Create a Linode (they call virtual machines Linodes) from the provided Fedora image (Fedora 30 at the time of this writing):

Shutdown the Linode, shrink the root disk (Fedora 30 Disk) to 30GB so that you have room to create another disk. Then, add a 2GB disk (RHEL 8 Grub) which we will use for the image template. Note, you must create the ext4 filesystem with the Linode tools because the mkfs.ext4 in RHEL 8 is too new and won’t work with Linode’s tooling (I just saved you a two hour rat hole):

Modify the Fedora boot configuration so that the newly created volume (RHEL 8 Grub) is accessible as /dev/sdc:

Add another boot configuration which we can use to to test our newly created volume (RHEL 8 Grub). Notice that we specify the RHEL 8 volume as /dev/sda and also boot from /dev/sda with Grub2:

Boot the Linode up in the Fedora boot profile. Now, we have enough room on our root disk to do our work, and also a 2GB volume which we will use for our golden image.

 

At access.redhat.com/downloads

Copy the download link for the RHEL 8 KVM image:

On the Fedora Virtual Machine

Connect to the new Linode instance with SSH:

ssh [email protected]

 

Download the RHEL 8 KVM image using the link from the last section. These instructions were developed using (Red Hat Access 29815 – How to download install disc iso images from RHN using wget or curl?):

wget -O rhel-8.0.qcow2 -c "https://access.cdn.redhat.com/content/origin/files/sha256/68/68312d7c9f6316921086dc891285fdba41a0f0febee35cc28161d65e6170857f/rhel-8.0-x86_64-kvm.qcow2?user=0edea7b4a80dae28d504f0cdcf3afa53&_auth_=1563800536_ebc7728fe1c361b4977df664714a7487" -O rhel-8.0.qcow2

 

Now, convert it to an img file so that we can mount it. These instructions were developed using (Red Hat Access 3214311 – Convert raw VM image (img) to qcow2 using qemu-img):

yum install -y qemu-img
qemu-img convert rhel-8.0.qcow2 rhel-8.0.img

 

Mount the RHEL 8 Grub disk, the RHEL 8 img file, and copy data from the XFS filesystem to the ext4 filesystem. This set of commands essentially copies the data from the RHEL 8 xfs filesystem to the slightly older Linode ext4 filesystem while preserving the SELinux labels:

mkdir /mnt/rhel-8.0
mkdir /mnt/sdc
mount -o loop,offset=$((2048*512)) /root/rhel-8.0.img /mnt/rhel-8.0/
mount /dev/sdc /mnt/sdc
rsync -av -A -X -H /mnt/rhel-8.0/ /mnt/sdc/

 

Create a change root for the rest of our work:

mount -t proc proc /mnt/sdc/proc/
mount -t sysfs sys /mnt/sdc/sys/
mount -o bind /dev /mnt/sdc/dev/
chroot /mnt/sdc

Modify fstab. Change from UUID to device and critically, remember to change XFS to EXT4:

vi /etc/fstab

Modify it to look like this:

/dev/sda / ext4 defaults 1 1
/dev/sdb none swap defaults 0 0

Modify grub2 to use the older boot method so that Linode tools will work with the image (resize, snapshots, imaging, etc). This will disable kernelopt and fall back to writing things out in the grub.cfg file. These instructions were developed using Red Hat KB 3710121 and Install a Custom Distribution on a Linode:

vi /etc/default/grub

Modify it to look like this:

GRUB_TIMEOUT=10
GRUB_CMDLINE_LINUX="console=ttyS0,19200n8"
GRUB_TERMINAL=serial
GRUB_DISABLE_LINUX_UUID=true
GRUB_SERIAL_COMMAND="serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1"

Build a new grub.cfg file:

grub2-editenv - unset kernelopts
grub2-mkconfig -o /boot/grub2/grub.cfg
sed -i s/sdc/sda/g /boot/grub2/grub.cfg
grub2-editenv - list | grep kernelopt
ln -s /boot/grub2/grub.cfg /boot/grub/grub.cfg

Rebuild initrd image. Careful, you may have to modify the kernel version depending on the patch level of the KVM image. Built with instructions from Red Hat KB 1958:

dracut -f /boot/initramfs-4.18.0-80.4.2.el8_0.x86_64.img 4.18.0-80.4.2.el8_0.x86_64

Force an SELinux relabeling on first boot:

touch /.autorelabel

Disable cloud-init:

touch /etc/cloud/cloud-init.disabled

Disable kdump:

rm -f /etc/systemd/system/multi-user.target.wants/kdump.service

Set root password:

passwd

Unmount everything:

exit
cd /
umount /mnt/sdc/proc /mnt/sdc/sys /mnt/sdc/dev
umount /mnt/sdc

Results

 

On cloud.linode.com

Power the Linode down, and reboot into the RHEL 8 Grub profile to test the image and cause the SELinux relabel:

Power off the RHEL 8 VM, and snap an image of it. Right click on the RHEL 8 Grub disk and select Imagize:

You will now have a new Image (RHEL 8 Core Build) available in Linode:

Results

You now have an image set up on Linode which can be used to deploy as many RHEL 8 instances as you have subscriptions for. This set up is not supported by Red Hat, but nonetheless, I use it because $10/mo for a small instance on Linode is a much better value than almost any other cloud provider. Combined with the fact that their tools allow you to do things like what’s described in this how-to make it an extremely attractive option for power users.

3 comments on “Setting Up RHEL 8 on Linode

  1. One addition to this tutorial that’s important: I’m not sure if this was due to a change by linode or was already there but, after following this tutorial, while I was able to boot into RHEL I could not enable Selinux. This could have been missed since I know a lot of people prefer to leave it disabled (but shouldn’t). The reason for this was because of the way linode interjects in the boot process, it created a grub and grub2 directory and when you tell linode to use the grub2 loader it looks in the grub directory instead of grub2.

    The solution is:
    1. Delete grub directory
    2. Create symbolic link so grub -> /boot/grub2
    3. touch /.autorelabel
    4. shut the server down
    5. Change server settings back to grub2 loader
    6. Boot server, check that selinux is enabled and prosper!

    Credit for finding this actually goes to a friend of mine but I wanted to share it here so that others may know how to overcome this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *