Wednesday, March 25, 2015

Downloading a Rackspace cloud vm and running it on KVM

Do you need to migrate a rackspace image and run it locally? Or perhaps you need to run it on another server.

There is a good article on how to run it on Xen here:

However my server is running KVM so I needed to make some small modifications.

The overall strategy:

  • Go to your rackspace cloud page and create an image.
  • Authenticate to rackspace's API using your api key generated on the web portal. This gets you an access token.

    curl -s -X POST \
      -H "Content-Type: application/json" \
      -d '{
        "auth": {
          "RAX-KSKEY:apiKeyCredentials": {
            "username": "exampleusername",
            "apiKey": "1c9bde3d45804cce5bb24333bce81960"
      }' | python -m json.tool

    Basically the response comes back as JSON so you want to pipe it to the json.tool module of python to format it nicely.
  • Once you have your token put it in your environment.

    export TOKEN="d129535e3b6dcc4e4c3b0c809be341b8"
    export ENDPOINT=""
    I had to figure out where I took the image and what endpoint to use. This one is Dallas-Fort Worth.
  • Use the access token to get a list of images. One of them is the one you created:

    curl -s $ENDPOINT/images -H "X-Auth-Token: $TOKEN" | python -m json.tool
  • Generate a POST request to export the image to a swift container. This is basically your cloud files container name (in this case Container1):
    curl -s -X POST $ENDPOINT/tasks \
      -H "Content-Type: application/json" \
      -H "X-Auth-Token: $TOKEN" \
      -d '{
        "type": "export",
        "input": {
          "image_uuid": "11107aa8-3187-4e0d-abcd-4a5d0a4f084d",
          "receiving_swift_container": "Container1"
      }' | python -m json.tool
  • Periodically call:

    curl -s -X GET $ENDPOINT/tasks \
      -H "Content-Type: application/json" \
      -H "X-Auth-Token: $TOKEN" \
      | python -m json.tool

    To see the status of the task. If it immediately errors you did something wrong. If it says processing then you are good to go. For a 6GB image it took about an hour while it was stuck processing. The way you know it is working is if you go to the web front end and refresh your cloud files you will start to see files pop up.
  • Use the swift tool to download the image from the server.

After you have the image some tools that will help you get it in the right direction to run:

qemu-img info server.img

Gives you nice information about the format. Example:

image: server.img
file format: raw
virtual size: 1.0T (1073905926144 bytes)
disk size: 945G

I then created a new server using virt-install:

virt-install \
  --name exampleserver \
  --vcpus=2 \
  --disk path=/data/rackspace/server.img,device=disk,bus=virtio,format=raw \
  --ram 2048 \
  --graphics vnc,password=examplepassword,listen=,port=9999 \
  --accelerate \
  --os-type=linux \
  --noautoconsole \
  --network network=default \
  --boot cdrom,fd,hd,network,menu=off

The thing is though the server might start up but you will get lots of kernel panics because paths and devices are wrong. The easiest way I found was to convert the image into a raw format (it comes as something else) and then mount it. Then go into /etc/fstab and change it all around properly.

I also had to change one other file because it was looking for /dev/xvda1 I believe and that didn't exist. That's pretty much it.