AWS Linux 2 – VirtualBox

So you want to run the AWS Linux 2 OS on your laptop for development purposes?  Its no problem now!

I followed the instructions (here) to get Linux 2 running with a VirtualBox VM.

These are the high-level steps I took.

  1. Create a cloud-init configuration ISO
    • Create my user-data and meta-data files
    • Validate the user-data YAML file syntax in a validator (important)
    • Create a new ISO with these 2 files on a linux server using genisoimage
      • genisoimage -output mySeed.iso -volid cidata -joliet – rock user-data meta-data
  2. Download the latest Linux 2 vdi file from AWS
  3. Copy the ISO file back to my Windows machine
  4. Create my new VM in VirtualBox (Linux\Other Linux 64-bit) using the new ISO and the downloaded vdi
    • IDE Primary Master = Linux 2 vdi file
    • IDE Secondary Master (Optical) = mySeed ISO file


Now you should be able to startup your VM and connect via any user defined in your user-data file.


VirtualBox\Guest Additions\Linux

If you are using VirtualBox and want some additional features present in your guest VM (RHEL), then you will probably end up “trying” to install Guest Additions within your VM. (e.g Shared folders, viewing guest properties from the host)

In my case, I had a VM up and running fine, but was unable to get the IP address of the VM from my host using the following command. (Host = Windows 10)

  • VBoxManage guestproperty enumerate <vm_name> | findstr IP

So after doing some research, I landed on a solution.  Install Guest Additions for VirtualBox on my VM and I will be able to retrieve the VM property “/VirtualBox/GuestInfo/Net/0/V4/IP” !

Next step, install Guest Additions using the following link.

Unfortunately I encountered the following error…..  Arrrgggg…

Unable to insert the virtual optical disk C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the machine CentOS. Would you like to try to force insertion of this disk? Count not mount the media/drive ‘C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso’ (VERR_PDM_MEDIA_LOCKED).

After some serious digging on the internet, I was able to finally find a solution.

  1. Before doing anything, you should install gcc kernel-devel bzip2 on the VM.
    • yum install -y gcc kernel-devel bzip2
  2. Download the corresponding “VBoxGuestAdditions_<version>.iso” from the following link.
  3. With your VM turned off, remount the Optical Drive (cdrom) to the location of the new .iso file.
    • guestadditions
  4. Now mount the .iso location
    • mount /dev/cdrom /mnt
  5. From within the /mnt folder, you can install Guest Additions using the following command. (May need to use sudo)
    • ./
  6. Reboot the VM to start the Guest Addition service.

Note: If there are issues with the install, the output from the Guest Addition install will reference log files that will help you understand the issue.

Putty and VirtualBox

I really like VirtualBox for testing new ideas.  However, I am not a huge fan of the VirtualBox preview console when working with Linux instances.

So I typically use Putty to ssh into the local instance as needed.  Seems to work pretty good for me.  Below are some configuration settings I needed to make to get things working.

  1. Download and install ssh client such as Putty.
  2. Configure the appropriate network settings for your VM.  I typically use Bridged Adapter as it seems to replicate my VM as a physical server closely.  (From a networking perspective)
  3. Once you have your VM running, you should be able to view your VM’s IP.
    • ip addr show (Run this command for Red Hat)
    • You should see something like this “inet” in the results.  This is the IP you will use to ssh into the VM.
  4. In my case, I did not see any IP address initially.  If I ran dhclient and then the above command, I would see an IP from my router.
  5. To help automate the DHCP process, I configured the network adapter to use DHCP and activate the network adapter on any reboot.
    • /etc/sysconfig/network-scripts/ifcfg-enp0s3
      • DEVICE=enp0s3
      • BOOTPROTO=dhcp
      • ONBOOT=yes

Now I can use all my nice ssh clients with ease when working with VB.

VirtualBox and Ansible

If you are interested in learning Ansible and\or just creating an Ansible test environment, VirtualBox can help you.

Steps to spinning up a VirtualBox Ansible test environment.  So easy!!!!

  1. Download and install VirtualBox
  2. Download your preferred Linux flavor.  In my case, I decided to us Red Hat Enterprise Linux (RHEL) 7.  The following link will show you how to download and install a RHEL iso with VirtualBox.  Remember the Ansible “controller” is not supported on Windows yet.
  3. Since I used RHEL in step #2, I needed to perform the following command before proceeding with the Ansible install.  (Based on my experience)
    • Run the dhclient command to reconfigure the network interfaces
      • After this command, verify the contents of /etc/resolv.conf
    • Next, I needed to register and apply a subscription to my new test server.  The login\pw I used in step #2 will be used here when prompted.
      • subscription-manager register
      • subscription-manager attach –auto
  4. Net you will need to install Ansible on your new VM.  The following commands will prep your server and then install Ansible as needed.

Its really that easy!  I executed my commands via root, but if I were to have used another account, I may have needed to sudo the commands.

Another gotcha I an encountered was around proxy servers, so be aware that if your rpm\yum commands fail, you may need set your specific proxy server accordingly.