Amazon Linux 2 runs on OpenStack perfectly fine. There is only one glitch that you should be aware of. Amazon Linux 2 won’t accept metadata and user data provided by OpenStack on boot. That means that you won’t be able to SSH into the instance after it comes up. In this brief tutorial, we are going to modify the Amazon Linux 2 image to fix this problem.
You can download Amazon Linux 2 images from https://cdn.amazonlinux.com/os-images/latest/. An image suitable for OpenStack is located in the
kvm subdirectory. I downloaded the
amzn2-kvm-2017.12.0.20180330-x86_64.xfs.gpt.qcow2 version of the image. By the time you are reading this tutorial, a newer version of the image may be available.
In the rest of this article, I’m going to use my machine that is running RHEL7 to modify the Amazon Linux 2 image. First, let’ download the image:
Next, let’s install the
qemu-img utility useful for manipulating qcow2 images:
Now we can convert the Amazon Linux 2 image from the qcow2 format to the raw format:
The previous command creates a file
amzn2-kvm.raw in the current working directory. This file is a binary image of the virtual machine disk. We can explore it using the
1 2 3 4 5 6 7 8 9 10 11 12
The output of the
fdisk command shows that the disk contains two partitions. The size of the first partition is 25 GB and it holds a Linux filesystem. On the disk, the Linux filesystem starts at the sector number 4096. Given that the size of the sector is 512 bytes, we can tell that the Linux filesystem starts at offset 2097152 (4096 * 512) bytes from the start of the disk image. Knowing the offset of the Linux filesystem, let’s loop mount the Linux filesystem under
If everything went well, we can now take a look at the cloud-init configuration of the Amazon Linux 2 image:
In the cloud-init configuration file, you can find the data source list set as follows:
Sadly, none of the listed data sources is available on OpenStack. OpenStack supports its own data source called
OpenStack. Alternatively, OpenStack is compatible with the AWS data source called
Ec2. This compatibility ensures that virtual machine images designed for EC2 will work properly on OpenStack. I would expect that the
Ec2 data source would be included in the data source list of the Amazon Linux 2 image but it is not. Let’s add the
OpenStack data source to the list:
I put the
OpenStack data source at the beginning of the list. You can choose to add it anywhere else. Just make sure that the
None data source remains as the last one on the list.
None is a fallback datasource used when no other datasources can be selected and it provides empty metadata and empty user data.
After you saved your changes, you can unmount the Linux filesystem:
And convert the modified image back to the qcow2 format:
Now you can upload the modified image into the OpenStack image repository:
After the image upload into OpenStack has completed, you can create a test virtual machine off of this image:
Note that in the above command, you’ll have to replace the
<net-id> placeholders with the name of your key pair and the name of the network you want your instance to be attached to. After the virtual machine has booted up, you should be able to connect to it using SSH. Note that the default user enabled on the Amazon Linux 2 image is
1 2 3 4 5 6 7 8 9 10
This is the end of the tutorial. You have a working Amazon Linux 2 image on OpenStack, congratulations! If you have any comments or questions, let me know in the comment section below.