As the title says, I regularly download my Rackspace images for backup of my VPS, however I'm wondering if it's possible to run them locally on KVM (for example) so I can run tests on my application without affection production.
As the title says, I regularly download my Rackspace images for backup of my VPS, however I'm wondering if it's possible to run them locally on KVM (for example) so I can run tests on my application without affection production.
Almost a year to the day after the original question, I think I have a good procedure set up for downloading Rackspace images and running them locally, under Xen running on Ubuntu Precise.
I'll write down the steps here so there's 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.
(These instructions are also posted on our blog at http://www.everichon.com/blog/2013/05/29/running-rackspace-images-locally/)
Install Ubuntu precise (12.04 LTS), and follow the steps mentioned in http://blog.heidt.biz/blog/2012/09/17/setting-up-ubuntu-12-dot-04-precise-pangolin-as-xen-dom0/ 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.
Go to your servers page on the rackspace cloud (
manage.rackspacecloud.com -> Hosting -> Cloud servers
) and select the one you want to run locally. Go to theImages
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.)Check the name of the image in cloud files. Go to
Hosting -> Cloud Files
and open the containercloudservers
. There should be the file there named likemyservername_YYYYMMDD_XXXXX_cloudserverZZZZZ.tar.gz.0
, and that's the file you want.Download the image to your server. The easiest way to do this on Ubuntu 12.04 is to use
swift
. To install, justsudo apt-get install swift
. Then run it likeswift -A https://auth.api.rackspacecloud.com/v1.0 -U username -K API_key download cloudservers myservername_YYYYMMDD_XXXXX_cloudserverZZZZZ.tar.gz.0
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
is the one we're interested in, as it contains your root partition from the cloudserver.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, dosudo apt-get install qemu-utils
). To convert the image.vhd to something that's easier to work with, doqemu-img convert -p image.vhd disk.img
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:Note the start offset for the first partition, and the sector size.
(Optional) Check that the disk image is ok. For this, we mount it loopback and simply see that it works.
This gives you an indication that the disk is ok. Then unmount the image.
umount tmp
Create logical and swap volumes for your new DomU.
lvcreate -L20G -n myservername-disk vg0
andlvcreate -L2G -Cy -n myservername-swap vg0
. Also initialize the swap disk,mkswap /dev/vg0/myservername-swap
.Copy your disk image to the new logical volume.
dd if=disk.img of=/dev/vg0/myservername-disk bs=4096 skip=256
. Thebs
andskip
arguments are there to get the correct offset for your partition. I could go withbs=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.)Check the filesystem on your logical volume (and fix any errors), resize the fs to fit the lv, and check again.
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 grubmenu.lst
file.Note the disk names for root and swap!
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:(for rackspace's environment) to:
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
.Create a xen config file for your imported DomU,
vi /etc/xen/myservername.cfg
, and put in something like this:Again, note that you should use the same device names for the virtual devices as the ones you discovered in step 12.
Now everything should be ready! To verify, create the domU and attach a console by running
xm create -c /etc/xen/myservername.cfg
Yes, you can run them, the hypervisor they use is Xen IIRC. You are also able to download and install Openstack and have your own private cloud.
Here is good link on "Run Rackspace Cloud Server locally on Hyper-V"
http://www.sudonym.com/375/run-rackspace-cloud-server-locally-on-hyper-v