Running rackspace images locally

Recently, we’ve been cloning some of our virtual servers from Rackspace’s cloud to some self-hosted Xen-servers for development and testing.

This is an easy recipe for you to follow if you want to try it out. The steps work for linux/Ubuntu domU’s at least, for others YMMV.

  1. Install Ubuntu precise (12.04 LTS), and follow the steps mentioned in to set up your server as a Xen Dom0. At least make sure to have a running 12.04 with xen and xe-tools installaed, and a LVM volume group to use for virtual disks for your DomU’s.

  2. Go to your servers page on the rackspace cloud ( -> Hosting -> Cloud servers) and select the one you want to run locally. Go to the Images tab for that server. Create an on-demand image. (Depending on the time the server was first created the on-demand image will either go directly to cloud files or be stored with the server. If the image is stored with the server, you have to move it to cloud files after creation.)

  3. Check the name of the image in cloud files. Go to Hosting -> Cloud Files and open the container cloudservers. There should be the file there named like myservername_YYYYMMDD_XXXXX_cloudserverZZZZZ.tar.gz.0, and that’s the file you want.

  4. Download the image to your server. The easiest way to do this on Ubuntu 12.04 is to use swift. To install, just sudo apt-get install swift. Then run it like swift -A -U username -K API_key download cloudservers myservername_YYYYMMDD_XXXXX_cloudserverZZZZZ.tar.gz.0

  5. When the download is done, unpack the downloaded file (tar zxf myservername_YYYYMMDD_XXXXX_cloudserverZZZZZ.tar.gz.0). When it’s done you’ll have gotten the following files:

        -> image.vhd
        -> manifest.ovf
        -> snap.vhd

    image.vhd is the one we’re interested in, as it contains your root partition from the cloudserver.

  6. To make it easier to work with the image file, we’ll convert it to a raw disk image. This is done using qemu-img (if it’s not available on your system, do sudo apt-get install qemu-utils). To convert the image.vhd to something that’s easier to work with, do qemu-img convert -p image.vhd disk.img

  7. Check the disk image using fdisk. (NOTE: I’ve only been working with 20 GB large images from rackspace, and my notes are about them. If you use another size, you’ll have to adjust some steps accordingly!) fdisk -l disk.img should give something like the following:

    Disk sda1.img: 20.4 GB, 20400758784 bytes
    255 heads, 63 sectors/track, 2480 cylinders, total 39845232 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
    disk.img1   *        2048    39845887    19921920   83  Linux

    Note the start offset for the first partition, and the sector size.

  8. (Optional) Check that the disk image is ok. For this, we mount it loopback and simply see that it works.

    mkdir tmp
    mount -o loop,offset=1048576 disk.img tmp/
    ls -la tmp
    (The offset above is start for the first partition * sector size) 

    This gives you an indication that the disk is ok. Then unmount the image. umount tmp

  9. Create logical and swap volumes for your new DomU. lvcreate -L20G -n myservername-disk vg0 and lvcreate -L2G -Cy -n myservername-swap vg0. Also initialize the swap disk, mkswap /dev/vg0/myservername-swap.

  10. Copy your disk image to the new logical volume. dd if=disk.img of=/dev/vg0/myservername-disk bs=4096 skip=256. The bs and skip arguments are there to get the correct offset for your partition. I could go with bs=512 skip=2048, of course, but making the block size larger makes copying much faster. (And 512*2048 = 4096*256, so it does not matter for the offset.)

  11. Check the filesystem on your logical volume (and fix any errors), resize the fs to fit the lv, and check again.

    e2fsck -f /dev/vg0/myservername-disk
    resize2fs -p /dev/vg0/myservername-disk 
    e2fsck -f /dev/vg0/myservername-disk     
  12. Check the virtual disk settings in your virtual machine. This will be needed for your DomU config file. Mount the logical volume. mount /dev/vg0/myservername-disk tmp. Then check the fstab file, and (if it exists) the grub menu.lst file.

    more tmp/etc/fstab
    more tmp/boot/grub/menu.lst 

    Note the disk names for root and swap!

  13. Update the network settings for your DomU. With the virtual disk still mounted, edit the interfaces file to something that suits your local environment. vi tmp/etc/network/interfaces. I’ve usually changed mine from something like:

    # The loopback network interface
    auto lo
    iface lo inet loopback
    auto eth0
    iface eth0 inet static
        address 184.106.XXX.YYY
        netmask 255.255.XXX.YYY
        gateway 184.106.XXX.YYY
        dns-nameservers 173.203.XXX.YYY 173.203.XXX.YYY
    auto eth1
    iface eth1 inet static
        address 10.179.XXX.YYY
        netmask 255.255.XXX.YYY
    up route add -net 10.176.XXX.YYY0 netmask 255.240.XXX.YYY gw 10.179.XXX.YYY
    down route del -net 10.176.XXX.YYY netmask 255.240.XXX.YYY gw 10.179.XXX.YYY
    up route add -net 10.191.XXX.YYY netmask 255.255.XXX.YYY gw 10.179.XXX.YYY
    down route del -net 10.191.XXX.YYY netmask 255.255.XXX.YYY gw 10.179.XXX.YYY

    (for rackspace’s environment) to:

    # The loopback network interface
    auto lo
    iface lo inet loopback
    # The primary network interface
    auto eth0
    iface eth0 inet dhcp

    for just using dhcp and one virtual network interface and my local server. After these changes, we should be done. Unmount the virtual disk, umount tmp.

  14. Create a xen config file for your imported DomU, vi /etc/xen/myservername.cfg, and put in something like this:

    name = "myservername"
    bootloader = '/usr/lib/xen-default/bin/pygrub'
    #uncomment the following if you want to boot into single user mode 
    #extra = " single"
    vcpus       = '2'
    memory      = '512'
    #  Disk device(s). (Use the correct mappings from step 12.) 
    disk        = [
    #  Networking
    vif         = [ 'bridge=xenbr0' ]
    #  Behaviour
    on_poweroff = 'destroy'
    on_reboot   = 'restart'
    on_crash    = 'restart'

    Again, note that you should use the same device names for the virtual devices as the ones you discovered in step 12.

  15. Now everything should be ready! To verify, create the domU and attach a console by running xm create -c /etc/xen/myservername.cfg


Welcome to our dev blog

This section of the Everichon web will contain random dev notes and tips and tricks for the technologies we are using. Expect to find anything including Android UI layout tricks, Nginx configuration, JSON statistics, NFC driver hacks, Python and a lot other things we encounter in the things we are building or trying to build. Currently we do not now how often this space will be updated or when we will get started but we believe that sharing and discussing knowledge is a great way to improve as a company so please remind us if we don’t.

About Everichon

Simplicity in a connected world.

Help & Support

To ask us any questions, please drop us a mail!

Support @ Everichon
Get in touch