Wednesday, April 21, 2010

Manipulating Existing Images

Hello there,

After all this time we were still running on our cloud the pre-packed images (they call as Eucalyptus-certified images) available in Eucalyptus' website. Until now, we were just worried about the system functionality itself, not about what was running on it.

Those pre-packed images work, but they are static copies and as we explained before, any modification to a image is simply discarded next time the system starts since Eucalyptus will start a new instance copying whatever is in walrus, hence the non-modified image.

So, we decided to work doing two things:

a) modify an existent pre-packed image, adjust it to our needs and then upload the new version to eucalyptus;

b) create a new Xen VM, install a fresh operating system on it and then upload the VM to eucalyptus.

This post is related to the first option listed above. We will post about the second one later, since we are having troubles making a new VM work on the cloud.

Well, let's explain how to customize an eucalyptus pre-packed image...

First, we put the three images (filesystem, ramdisk and kernel) in the same directory. As we didn't know the root's password for the image, we had to mount the filesystem in our local computer in order to modify the /etc/passwd file. To mount the filesystem we used the loop device. Assuming that we are inside the dir where the images are stored, fsimage.img is the name of our filesystem image and /any_dir is the location where we wanted to mount it.

# losetup /dev/loop5 fsimage.img
# mount /dev/loop5 /any_dir


Now, to remove the root password we edited the /any_dir/etc/passwd file as well as the /any_dir/etc/shadow file.

==> /any_dir/etc/passwd file before
root:x:0:0:root:/root:/bin/bash

==> /any_dir/etc/passwd file after
root::0:0:root:/root:/bin/bash

==> /any_dir/etc/shadow file before
root:$1$6lk5l5ux$LCsJdxM4AWzxDRKdcZa0Y1:14708:0:99999:7:::

==> /any_dir/etc/shadow file after
root::14708:0:99999:7:::

After saving the files in our local machine, we unmounted the image:

# umount /any_dir

Now, let's explain how to run the pre-packed image locally using Xen. To make it happen we created a basic config file for the machine in our /etc/xen directory. The content of the file can be seen below:

name = "digs_domain"
memory = 256
ramdisk = "/any_dir/initrd.img"
kernel = "/any_dir/vmlinuz.img"
root = "/dev/sda1 ro"
disk = [ "file:/any_dir/fsimage.img,sda1,w" ]
vif = [ "mac=00:16:36:48:17:dc,bridge=xenbr0,script=vif-bridge" ]
dhcp="on"


Then, we ran it!

# xm create digs_domain
# xm console digs_domain


Inside the VM we logged using the root passwordless account. Of course, we now have a new password simply after running the passwd command.
The modification that we made to the image was simple: we installed the apache server with its basic configuration.

The final step was to shutdown the VM and upload its new version to eucalyptus. We only uploaded our filesystem image, since the kernel and the ramdisk were not modified.

The new modified VM is now ready to be used, proving that system admins can have customized versions of VMs available in their academic cloud.

We will be back to post our adventures installing a system from scratch.

Keep in touch and thanks for reading.

Lucio

No comments:

Post a Comment