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.

Thursday, October 23, 2014

How to properly setup your DNS with using Elastic Beanstalk

If you ever want to be able to swap environments easily (for zero downtime deployments) you need to get your DNS right.

Suppose you have the website and

Route 53 you need to have the following setup: (A Record) w/ special Amazon Alias to is an A record with Alias to your load balancer -->

Sunday, October 5, 2014

How to get Dell PERC H310 Monitoring on Ubuntu

HWRaid is probably the best set of packages for Ubuntu:


sudo add-apt-repository "deb lucid main"
wget -O - | sudo apt-key add -

apt-get update
apt-get install megactl


Enabling WMI on Windows Azure

To enable WMI on Windows Azure machines:
  • Open the firewall port 135
  • Set WMI to use a static port
Step one:  Set the DCOM config to use a static port....
Basically, run "dcomcnfg" from command prompt. Navigate the tree to My Computer > DCOM Config > Windows Management and Instrumentation, select properties of that folder.
Go to the Endpoints tab
Select Properties button for Connection-oriented TCP/IP
Use static endpoint, set the port.
Step 2:  Configure WMI to use a fixed port
  1. At the command prompt, type winmgmt -standalonehost
  2. Stop the WMI service by typing the command net stop "Windows Management Instrumentation"
  3. Restart the WMI service again in a new service host by typing net start "Windows Management Instrumentation"
  4. Establish a new port number for the WMI service by typing netsh firewall add portopening TCP 24158 WMIFixedPort
Still testing this myself, so not 100% certain it works.

49154 - TCP Port for DCOM when using wmic.

winexe -U Administrator%password // "C:\\AutoHotKeyScripts\\debug.exe"

To get winexe working make sure to open port 445 on Azure.

When I got the error
[winexe/winexe.c:120:on_ctrl_pipe_error()] ERROR: Failed to install service winexesvc - NT code 0x00000424
I did the following:

sc create winexesvc binPath= C:\WINDOWS\WINEXESVC.EXE start= auto DisplayName= winexesvc 
sc description winexesvc "Remote command provider for Zenoss monitoring"

Creating virtual machines with KVM

I was pretty confused when I first started creating virtual machines. Between Xen, VirtualBox, VMWare, LXC, Docker there are a ton of technologies for virtualization.

I decided to go with KVM. A library called libvirt helps a lot in creating virtual machines (aka domains). Libvirt has a tool called virsh which is what we will be using.

virsh uses xml files for the configuration of the domains. To create one easily you can use the virt-install command. The files are stored are in /etc/libvirt/qemu/

virt-install \
  --name moloko \
  --vcpus=1 \
  --disk /var/kvm/moloko,size=32 \
  --ram 1024 \
  --graphics vnc,password=password,listen=,port=5910 \
  --accelerate \
  --cdrom /var/kvm/ubuntu-14.04.1-server-amd64.iso \
  --os-type=linux \
  --noautoconsole \
  --boot cdrom,fd,hd,network,menu=on

To delete the domain:

virsh destroy moloko
virsh undefine moloko

Wednesday, January 15, 2014

How to get mobile data in Cusco, Peru for your phone using Claro

Getting mobile data to work in Cusco was fairly easy. You should make sure you have an unlocked phone that can take a SIM card. I was using a Nexus 4 so it comes unlocked.

Basically you can buy a SIM card at a Claro store. It will cost you 8 soles and will come with no money on it.

There are lots of places that say "Claro" in a big red logo but only some of them are actually official stores that sell the SIM card. When you ask for it they will ask for your passport.

After you get the SIM card you will need to recharge it or put money on it. This is the easiest part because you can then go to any of the shops that say "Claro Recharga". They are like everywhere. The process to put money on a card for a merchant only seems to require a cell phone so almost any merchant can do it.

Now for pricing. It can be found on at You are looking for prepaid internet plans or "Paquetes de Internet". What package you decide to purchase depends on how long you are staying in Peru and how much data you use.

For me I was on T-Mobile back in the US, $50 per 30 days, 500MB worth of 4G internet then drops to 3G. 500MB carried me about the end of the month. I wish it was like 600 or 700MB. Of course that is with only light uploading and streaming.

The thing with Claro is that you have to buy a data pack and it will be good for only a certain amount of time. So the data packs come in 1 hour, 1 day, 3 day, 5 day, 10 day, 15 day, and 30 day amounts. I purchased the 5 day amount at 200MB.

To purchase you first give money to a recharging person. 3 soles is the minimum. I recommend you put 10 soles to buy the 5 day pack. After it is loaded you will get an SMS saying it is successful.

Here are the SMS messages I got. I actually did it 3 times for 5 soles, 5 soles, and the minimum 3 soles.

After your account is loaded then the trick is to SMS the phone number 779 with the text "5d" or "1h" or "3d" depending on what plan you want. This will activate the data pack. It is case sensitive by the way.

After this you should be able to configure your APN settings. These are settings specific to Claro used to access their data network. If you don't have them you can go here

That should be it. The 3G is stupid fast in Cusco. Much faster than in the US.