Creating image for Eucalyptus

To create image we will need a raw HDD for the virtual machine. So, set as much space as you need.

kvm-img create -f raw server.img 5G

Get Ubuntu 11.04 Server downloaded from here,


To start the installation process, boot a KVM instance with the OS installer ISO in the virtual CD-ROM and set up a VNC port at 0

sudo kvm -m 256 -cdrom ubuntu-11.04-server-amd64.iso -drive file=server.img,if=scsi,index=0 -boot d -net nic -net user -nographic  -vnc :0

Connect to the VM using the Client PC’s IP with VNC port 0 and finish the installation i.e. :0

vncviewer :0

Create a single ext4 partition mounted on ‘/’ during the installation of Ubuntu. Do not create a swap partition.

After finishing the installation relaunch the VM by executing the following command,

sudo kvm -m 256 -drive file=server.img,if=scsi,index=0,boot=on -boot c -net nic -net user -nographic -vnc :0

Now you can add any packages you want. So for our test purpose we will just update and upgrade the system.

sudo apt-get update
sudo apt-get upgrade

Install the following packages as well

sudo apt-get install openssh-server cloud-init

Remove the network persistent rules to make sure that the new network interface eth0 without creating any problem.

$ sudo rm -rf /etc/udev/rules.d/70-persistent-net.rules

Shutdown the VM.

To upload the image on Eucalyptus, it needs to be an ext4 filesystem image. To obtain an ext4 filesystem image, do the following

sudo losetup  -f  server.img
sudo losetup -a
/dev/loop0: [0801]:16908388 ($filepath)

Observe the name of the loop device ( /dev/loop0 in our setup) when $filepath is the path to the mounted .raw file.

Now we need to find out the starting sector of the partition

sudo fdisk -cul /dev/loop0

You should see an output like this

Disk /dev/loop0: 5368 MB, 5368709120 bytes
149 heads, 8 sectors/track, 8796 cylinders, total 10485760 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: 0x00072bd4
Device Boot Start End Blocks Id System
/dev/loop0p1 * 2048 10483711 5240832 83 Linux

Make a note of the starting sector of the /dev/loop0 partition i.e the partition whose ID is 83. This number should be multiplied by 512 to obtain the correct value. In this case: 2048 x 512 = 1048576

Unmount the loop0 device:

sudo losetup -d /dev/loop0

Now mount only the partition(/dev/loop0) of server.img which we had previously noted down, by adding the -o parameter with value previously calculated value

sudo losetup -f -o 1048576 server.img
sudo losetup -a

You’ll see a message like this

/dev/loop0: [0801]:16908388 ($filepath) offset 1048576

Make a note of the mount point of our device(/dev/loop0 in our setup) when $filepath is the path to the mounted .raw file.

Copy the entire partition to a new .raw file

sudo dd if=/dev/loop0 of=serverfinal.img

Now we have our ext4 filesystem image i.e serverfinal.img.

Unmount the loop0 device

sudo losetup -d /dev/loop0

Tweaking /etc/fstab

You will need to tweak /etc/fstab to make it suitable for a cloud instance.

Loop mount the serverfinal.img

sudo mount -o loop serverfinal.img /mnt

Edit /mnt/etc/fstab and modify the line for mounting root partition(which may look like the following)

UUID=e7f5af8d-5d96-45cc-a0fc-d0d1bde8f31c  /           ext4    errors=remount-ro  0       1


LABEL=uec-rootfs              /          ext4           defaults     0    0

Kernel and Initrd

Copy the kernel and the initrd image from /mnt/boot to user home directory. These will be used later for creating and uploading a complete virtual image to Eucalyptus.

sudo cp /mnt/boot/vmlinuz-2.6.38-7-server /home/shaon
sudo cp /mnt/boot/initrd.img-2.6.38-7-server /home/shaon

Unmount the Loop partition

sudo umount  /mnt

Change the filesystem label of serverfinal.img to ‘uec-rootfs’

sudo tune2fs -L uec-rootfs serverfinal.img

Now, we have all the components of the image ready to be uploaded to Eucalyptus server.

About these ads

2 thoughts on “Creating image for Eucalyptus

  1. Hi Shaon,
    I’m sorry if I poste my question not right place.
    I install Eucalyptus on Ubuntu 12.04, with hypervisor KVM in System Mode.
    I can Ping to my Vm instance but cannot SSH to it, because of “Read from socket failed: Connection reset by peer” error as follow output :

    chuan@7LM3X4J:~$ ssh -i new-key.private -vvv root@
    OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 19: Applying options for *
    debug2: ssh_connect: needpriv 0
    debug1: Connecting to [] port 22.
    debug1: Connection established.
    debug3: Incorrect RSA1 identifier
    debug3: Could not load “new-key.private” as a RSA1 public key
    debug3: key_read: missing whitespace
    debug1: identity file new-key.private type -1
    debug1: identity file new-key.private-cert type -1
    debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
    debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
    debug2: fd 3 setting O_NONBLOCK
    debug3: load_hostkeys: loading entries for host “” from file “/home/chuan/.ssh/known_hosts”
    debug3: load_hostkeys: loaded 0 keys
    debug1: SSH2_MSG_KEXINIT sent
    Read from socket failed: Connection reset by peer

    I think, this is because Cloud-init cannot get metadata service by : http://:8773/
    But I don’t know how to fix it because I cannot SSH to this instance.

    Please help me!
    Thanks very much.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s