Improvements or suggestions towards this document are welcome.
-
Download latest
.vdi
file. You should be able to find the most recent.vdi
file at https://cdn.amazonlinux.com/os-images/latest/virtualbox/ Alternatively, here is a direct link to the most current version at the time of writing this (January 2019) https://cdn.amazonlinux.com/os-images/2.0.20181114/virtualbox/amzn2-virtualbox-2.0.20181114-x86_64.xfs.gpt.vdi -
Build virtual CD that contains cloud-init data (Will generate a file
seed.iso
. Ensure that this is ran from the same directly which contains the filesuser-data
andmeta-data
from this repository.
genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data
brew install cdrtools
mkisofs -output seed.iso -volid cidata -joliet -rock user-data meta-data
- Create new VM with the following criteria
- name: AMZN
- type: linux
- version: Other Linux 64bit
- Select the
.vdi
image downloaded earlier as the Hard Disk (option might state something like "Use an existing virtual hard disk file") - Add the
seed.iso
file generated above to the virtual CD drive - Start the Amazon Linux 2 virtual machine
- Remove the cloud-init ISO (
seed.iso
)image from VirtualBox settings - Log in to the virtual machine (this can be done in the virtual box terminal window)
- user: root
- password: vagrant
- From the VirtualBox menu select Devices->Insert Guest Additions CD Image
- Inside the terminal, we must now mount the inserted CD (I manually typed these commands into the VirtualBox terminal, suggestions of a better approach are welcome)
sudo yum -y update
# next line suggested at https://stackoverflow.com/a/37706087/1241791
# to solve shared folder issue later on
sudo yum -y install kernel-headers kernel-devel
#mount the inserted guest additions CD
mount -r -t iso9660 /dev/cdrom /media
cd /media
./VBoxLinuxAdditions.run
systemctl enable vboxadd.service
Ignore tainted kernel message
#Delete Bash command history
export HISTSIZE=0
#Delete cache of yum
yum clean all
rm -rf /var/cache/yum
#Optimize the area of the virtual hard disk
dd if=/dev/zero of=/ZERO bs=1M
rm -f /ZERO
shutdown -h now
These commands to be executed on the host machine
vagrant init
vagrant package --base AMZN --output amazonlinux2.box
The output amazonlinux2.box is the file of Base Box
The ssh key in the user-data file is the usual Vagrant insecure keypair from here
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/amazon-linux-2-virtual-machine.html
https://qiita.com/aibax/items/7fd9a874cb7e88f95488
https://superuser.com/questions/1048091/can-i-install-ec2-amazon-linux-os-locally-on-virtual-machine
Paul O'Flynn Original Author