Amazon Linux to Vagrant Box – Part 1

You will need to get a few things set up for this to move forward.

  • Amazon Linux EC2 instance running in AWS
  • Reasonably speedy Internet connection
  • Local virtualization platform to get things going – this example will be using VMware Fusion

Head over to aws.amazon.com and log yourself in. You then need to fire up a new instance using the Amazon Linux AMI. Machine type does not matter in this case and I used a t1.micro as my base.


Once your instance is running you will need to install some software and update the system software, after you log in and become root:

sudo su - root
yum install make
yum install kernel-devel
yum install gcc
yum install grub
yum update

You will prompted before each install, and you should say ‘y’ (or yes) and let it run. When complete you should then issue the reboot command:

reboot

Now the Amazon Linux instance is ready for us to continue.

In your virtualization platform (Fusion in my case), make yourself a VM with 2 virtual disks.

  • 10 GiB – first disk is for booting up your local Linux distribution of choice – I used Ubuntu 10.10 (see part 2 for why)
  • 40 GiB – second disk is where we start working with our image

Attach your CDROM device to your new virtual machine and boot up.

Install your distribution on to the 10 GiB virtual disk and reboot.

Once the system is back up, log in and become root (prompt will use a # symbol).

From the command line, log into a root shell so you can skip prefacing everything with sudo:

sudo su - root

Now that you are in a root shell, make a new primary partition on /dev/sdb and build a filesystem:

fdisk /dev/sdb
mkfs.ext4 /dev/sdb1

Install dump (and restore) utilities, mount virtual disk and prepare for building phase 1 of the image:

apt-get install dump
mkdir -p /mnt
mount -o noatime,async /dev/sdb1 /mnt

Now copy all the data from your Amazon Linux EC2 image to this new virtual disk:

ssh \
  -i  \
  ec2-user@remote-ip-address \
  "sudo dump -0 -f - /" | \
  (cd /mnt ; restore -rf -)

And a breakdown of the above command line:

Line 1 – run ssh
Line 2 – your private certificate from AWS
Line 3 – remote username is ec2-user and remote-ip-address is the instance IP address
Line 4 – using sudo – run the dump command over the SSH connection, at level 0, output to standard out for the root filesystem
Line 5 – start a subshell, change directory to /mnt, and run restore taking standard in as the data stream

Depending on your download speed from the Internet this should take between 3-10 minutes to complete.

While this is still not a bootable system, if all went well, you now have a copy of Amazon Linux locally.

The next post will show you how I set up the environment to boot for the first time.

As before, you can donate to this work by sending BTC to this Bitcoin address.

Comments are closed.