1

I'm running the "Amazon Linux" OS/distro in production on EC2, But I'd like to do some local development/testing with VirtualBox VMs. What would be a good distribution to use that is most like Amazon Linux. I'm most interested in making sure that I have the same packages available to me.

I'm most familiar with yum/rpm based distros, so that's where i'd like to stay, but if there's another distro that will have better package similarity with apt instead I suppose I can make that work.

A brief list of the packages I need to run are mysql5.5, apache2.2, php5.3 and tomcat7.

closed as primarily opinion-based by terdon, jasonwryan, Anthon, devnull, slm Apr 26 '14 at 7:40

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Sorry but this kind of opinion seeking is off topic here. In any case, just about any distribution will have those packages. If you want to stay in the RPM world, just go for Fedora, it probably feel 100% like Amazon Linux. They're both based on Red Hat. – terdon Apr 26 '14 at 1:28
  • 1
    Thanks for the comment. Fedora was on my short list, but I was afraid that it would be too bleeding edge. I'm not really looking for a subjective response to this question. I'm hoping someone with more experience with different distros than me has a concrete suggestion of a good fit for my situation. I'm quite familiar with CentOS. Maybe a better question would be what is the right way to get those versions of packages easily installed on CentOS 6? – Steakfest Apr 26 '14 at 1:55
  • I think if you reframe your question to say how to use Amazon AMI in virtualbox, the question will stay. – Ramesh Apr 26 '14 at 2:18
  • But I don't want to use any Amazon AMI in virtual box. I'm talking specifically about the "Amazon Linux" distro. AFAIK, it is not possible to install the Amazon Linux distro outside of EC2. – Steakfest Apr 26 '14 at 12:51
  • If CentOS doesn't have the versions of the stuff you want, either 1) build from source, 2) just use fedora -- which someone already recommended and you said this recommendation is no good...and using Amazon AMI is no good. Why are you asking for opinions if you are already set on your own? How many more choices do you want? – goldilocks Apr 26 '14 at 14:29
2

This question is bound to get closed as it is too broad. But, I want to share some useful information which might be useful for future references. You can use the Amazon AMI image that you had originally created (preferably a Fedora image) in the virtualbox.

Steps

NOTE: you'll have to do all of this with root privileges.

Make a new raw drive file

This one is ~10 gigs:

dd if=/dev/zero of=newimage.raw bs=1M count=10240

Partition it

First, add it to a loopback device:

losetup -fv newimage.raw
Loop device is /dev/loop0 

Next, partition it (this makes one partition for the whole disk). Make sure it's bootable. The defaults are otherwise fine.

cfdisk /dev/loop0

Note: You need to actually select Write and hit enter for this to work or you'll Quit without actually partitioning it, which I do every Time.

Create a filesystem

You can't use mkfs because it screws up its automatic determination of filesystem sizes on loopback devices. Instead, find the partition beginning, end, number of blocks, number of cylinders, and blocksize:

fdisk -l -u /dev/loop0
Disk /dev/loop0: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1   *          63    20964824    10482381   83  Linux

Calculate the beginning of the partition x blocksize. In this case (in most, actually), it's 512 * 63 (sector size * start sector): 32256. Setup a new loopback device for this partition by specifying an offset:

losetup -fv -o 32256 newimage.raw
Loop device is /dev/loop1

You're going to create a filesystem now with a some block size (probably 4096, which is standard and what I use) and a number of blocks that you compute with: ((end - start) * units) / blocksize, or ((20964824 - 63) * 512) / 4096, in our case.

To create the filesystem on our new partition:

mkfs.ext3 -b 4096 /dev/loop1 2620595

Copy and prepare the new filesystem

First, set up the .raw image also as a loopback device:

losetup -fv genprog-raw-image.raw
Loop device is /dev/loop2

Mount it:

mkdir /mnt/tmp_1
mount -t ext3 /dev/loop2 /mnt/tmp_1

Do the same for your new image:

mkdir -p /mnt/loop/1
mount -t ext3 /dev/loop1 /mnt/loop/1
cp -a /mnt/tmp_1/* /mnt/loop/1/

The instructions from the website I grabbed this all from suggests you need to copy over boot modules to get the initrd and kernel info, but for some reason I don't think I had to do this.

Various modifications before adding a bootloader

Edit menu.lst and make sure that the root= is set to /dev/sda1: (the root= substring is pretty randomly located)

vi /mnt/loop/1/boot/grub/menu.lst

Edit fstab for the same purpose (replace /dev/xfvg with /dev/sda1):

vi /mnt/loop1/etc/fstab

Amazon sets a random root password, which won't do. Instead:

chroot /mnt/loop/1
mv /etc/rc.local /etc/rc.local-old
passwd root
exit

Set up Grub on the new drive

Unmount and delete the loopback device with the partition (the one with the offset) so Grub will work without complaining:

umount /mnt/loop/1
losetup -d /mnt/loop1

Refer back to the info from fdisk, above (> fdisk -l -u /dev/loop0) and get the number of cylinders, heads, and sectors/track. Then do:

grub --device-map=/dev/null

You'll enter an interactive Grub thing.

grub> device (hd0) newimage.raw
grub> geometry (hd0) 1305 255 63
grub> root (hd0,0)
grub> setup (hd0)
You'll get a lot of output, then:
Done.
grub> quit

Unmount the mounted drives and delete all your loopback devices. Notes: umount unmounts. Why there's no n is beyond me. Also, losetup -a lists all active loopback devices.

losetup -d /dev/loop0
losetup -d /dev/loop1
losetup -d /dev/loop2

Make VirtualBox play nice

It's still a .raw, yes? Convert:

VBoxManage convertdd newimage.raw newimage.vdi

(I think convertfromraw works too b/c convertdd is for backwards-compatibility.)

Use the newimage.vdi in making a new VirtualBox machine. Do the default stuff, but open up settings, select System -> Processor and set the checkbox next to Enable PAE/NX.

Edit /etc/ssh/sshd_config and change the part that says "PasswordAuthentication" or whatever from no to yes.

Shutdown the vm. Back at the command line, to enable sshing in:

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

This will forward requests to the host machine's port 2222 to the guest machine's port 22 (where ssh listening happens by default). To ssh in, do:

ssh -p 2222 root@localhost

Done!

REFERENCES

http://church.cs.virginia.edu/genprog/index.php/Converting_an_EC2_AMI_to_a_VirtualBox_.vdi https://superuser.com/questions/504135/where-can-i-find-amazon-linux-ami-image-for-virtualbox http://linux.blogs.com.np/2010/04/05/how-to-move-a-virtual-machine-from-ec2-to-virtualbox-or-kvm/

  • 1
    Thanks for the response, but my question isn't about replicating just any Amazon Machine Image. I'm using the "Amazon Linux" distribution on EC2, and since that Distribution isn't available outside of EC2, I'm looking for a distro that will be as close to that distro as possible. – Steakfest Apr 26 '14 at 12:49
  • @Steakfest, what am suggesting is, you can create an ec2 instance of fedora with all the packages that you need. After that, you can take a snapshot of that image and then use it for your test environment as per the steps I had mentioned. Or even much more simpler way would be to google for fedora images for virtualbox and then use that image in virtualbox. You can easily install the packages you mentioned using yum install packagename. – Ramesh Apr 26 '14 at 14:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.