Please excuse the sloppyish formatting. I did this quickly from memory. Feel free to submit improvements..
-
Download .VDI file from here
-
Build virtual CD that contains cloud-init data using the files in this directory
genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data
hdiutil makehybrid -o seed.iso -hfs -joliet -iso -default-volume-name cidata seedconfig/
- Create a new VM in VirtualBox, call it "AMZN"
- Add the seed.iso file generated above to the virtual CD drive
- Add the .VDI file downloaded above as the hard drive (i.e. do not create a new one)
- Start the Amazon Linux 2 virtual machine
Remove the cloud-init ISO image from VirtualBox settings
Insert the CD image of VirtualBox Guest Additions from the menu
Log in to the virtual machine as root/vagrant
From the VirtualBox menu select Devices->Insert Guest Additions CD Image
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
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