Amazon Linux 2 is a Linux distribution provided by Amazon Web Services(AWS). This distribution is stable, with high-performance and security-focused. It is highly preferred due to the following features:
- Long term support, provides peace of mind to developers and system admins with the stability offered by the LTS versions
- Large Partner ecosystem. It has a massive community of Technology Partners such as Independent Software Vendors (ISVs). This makes it possible to install several partner applications.
- Pricing, on the cloud services, the Amazon Linux 2 is provided at no additional charge.
- Enhanced developer productivity – The Amazon Linux 2 is offered as a virtual machine and container image for on-premises development and testing. This helps developers speed up application development, with the ability to test and integrate the application in a production environment.
As said before, the Amazon Linux 2 virtual machine images are used for on-premises development and testing. The images are available for:
- VirtualBox (Oracle VM)
- Microsoft Hyper-V
By following this guide to the end, you should be able to run the Amazon Linux 2 on VirtualBox / VMware vSphere / Hyper-V.
This setup entails the following steps:
- Preparing the seed.iso boot image
- Downloading the Amazon Linux 2 VM image
- Booting and connecting to the new VM
Now let’s dive in!
#1) Prepare the seed.iso boot image
The seed.iso file contains the initial configuration required to boot into the new VM. This includes the network configs, hostname, and user data.
This configuration is split into two main files:
- The Meta-data – consists of the static network config and the hostname for the VM.
- The user-data that defines the user accounts, password, keys, and access mechanisms to the VM. By default, the created user is the ec2-user, whose password can be defined in the file.
Now let’s see how each of these files can be generated.
Begin by creating the file below and navigate into it.
mkdir seedconfig && cd seedconfig
Now we will begin by creating the meta-data file.
In the opened file, set the hostname and static IP for the VM appropriately.
local-hostname: myvm.localdomain # eth0 is the default network interface enabled in the image. You can configure static network settings with an entry like the following. network-interfaces: | auto eth0 iface eth0 inet static address 192.168.100.155 network 192.168.100.0 netmask 255.255.255.0 broadcast 192.168.100.255 gateway 192.168.100.1
Remember to replace myvm.localdomain with the appropriate hostname for your system and also set the network address correctly.
Save the file and proceed to create the user-data file as below.
In the file, add the lines below.
#cloud-config #vim:syntax=yaml users: # A user by the name `ec2-user` is created in the image by default. - default chpasswd: list: | ec2-user:StrongPassw0rd # In the above line, do not add any spaces after 'ec2-user:'.
For this guide, we will proceed with the default user(ec2-user). Remember to replace StrongPassw0rd with the password for the user.
Optionally, you can add the below lines to the user-data file to prevent cloud-init from applying network settings at each boot.
# NOTE: Cloud-init applies network settings on every boot by default. To retain network settings from first boot, add the following ‘write_files’ section: write_files: - path: /etc/cloud/cloud.cfg.d/80_disable_network_after_firstboot.cfg content: | # Disable network configuration after first boot network: config: disabled
Save the file and proceed to create the seed.iso file using the meta-data and user-data files.
The tool for use on Linux systems is genisoimage. From the seedconfig folder, run the command below.
genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data
I: -input-charset not specified, using utf-8 (detected in locale settings) Total translation table size: 0 Total rockridge attributes bytes: 331 Total directory bytes: 0 Path table size(bytes): 10 Max brk space used 0 183 extents written (0 MB) $ ls meta-data seed.iso user-data
For macOS systems, you can use the hdiutil tool. With this tool, you need to navigate one level up from the seedconfig folder then execute:
hdiutil makehybrid -o seed.iso -hfs -joliet -iso -default-volume-name cidata seedconfig/
After this, you should have the seed.iso file generated.
#2) Download the Amazon Linux 2 VM image
The Amazon Linux 2 VM image is available for several virtualization platforms. Download one that best suits you using the below links.
#3) Create the Amazon Linux 2 VM
Now we have come to the crux of the matter where we need to create the Amazon Linux 2 Virtual Machine.
The steps may be a bit different depending on your Virtualization platform but the main goal is to load both the Amazon Linux 2 VM image and the seed.iso file.
The below steps will help you load the VM image and the seed.iso file on your Virtualization platform:
- Begin by creating a new VM and assign it a name. Choose the type and version for the VM
- Set the memory size.
- Now proceed and use an existing disk. Browse and load the VM image and create.
- Now proceed to the VM’s Settings->Storage and choose optical drive under Controller: IDE
- Load the seed.iso file here and apply the changes.
Similar steps are followed here:
- Begin by creating a datastore for the created seed.iso file.
- Next, deploy the downloaded OVF template.
- Right-click on the new VM and Edit Settings
- Proceed to the Virtual hardware> New device and choose to add a CD/DVD Drive
- Now load the seed.iso file on the CD/DVD Drive by navigating to the datastore and selecting the file.
- Finally, connect the added CD/DVD Drive
Begin by extracting the compressed VM image and use the below steps to load it:
- Create a New virtual machine
- On prompt, select Generation 1
- If prompted to configure the network adapter, select External.
- Connect to a Virtual disk by using an existing disk. Browse and select the extracted VM image and choose Finish to create the VM
- Now on the new VM, right-click and select Settings->IDE Controller 1, choose DVD Drive.
- Browse and load the seed.iso file to the DVD drive and apply the changes.
#4) Boot into the Amazon Linux 2 VM
Once the VM has been created as required, power it on and proceed as below.
The VM will load the Amazon Linux 2 VM image settings defined in the seed.iso.
Once everything has been loaded, log in to the VM using the created user.
Now perform tasks on your new Amazon Linux 2 VM.
Verify the installation.
Update the system.
sudo yum update
That is it!
You now have the Amazon Linux 2 installed on VirtualBox / VMware vSphere / Hyper-V. Proceed and use the instance as desired.