These instructions have been tested on Ubuntu 9.10 (Karmic) 64-bit. Skip right to the instructions if you're short on time.
After being a happy Xen user for several years now, I've recently had to switch to an alternative virtualization solution. My colleague Arun (@iamclovin) actually struggled for a week with Xen VMs that locked up on Hardy; we've had much success with Hardy and Xen before, so we attributed it to a hardware problem since these were our first blade servers.
Out of ideas, we tried Karmic (Ubuntu 9.10) only to discover that Xen support via the apt package system is gone. I went down the path of compiling a paravirt_ops Dom0 kernel (this article was very useful) but ended up deciding the process took far too long despite being successful.
With KVM gaining official support from Ubuntu as the virtualization solution, I ended up ditching Xen and switching to KVM for these new servers on Karmic. The rest of the entry is a step-by-step guide on setting up KVM VMs on a Ubuntu server; I'm putting this down because like all wikis, the Ubuntu KVM wiki has grown a little too organically to be useful.
Preparing a host server for KVM
Update and upgrade apt packages (use your own discretion on whether this is necessary):
aptitude update && aptitude dist-upgrade
Check whether CPU supports hardware virtualization:
egrep '(vmx|svm)' --color=always /proc/cpuinfo
You should see lines with either "vmx" or "svm" highlighted.
Install these packages:
aptitude install kvm libvirt-bin ubuntu-vm-builder bridge-utils
If you see a
FATAL: Error inserting kvm_intelmessage during installation, it means that virtualization is not enabled in your machine's BIOS. You'll need to reboot your machine, enter the BIOS setup and enable virtualization (you'll have to hunt for the option).
After enabling virtualization in the BIOS and rebooting, run:
There should be no error shown (in fact, no console response).
Optionally, install virt-top, a top-like tool for your VMs:
aptitude install virt-top
Verify that you can connect to the hypervisor:
virsh -c qemu:///system list
You should see something like this:
Connecting to uri: qemu:///system Id Name State ----------------------------------
Setup a network bridge on the server for VMs. Edit
/etc/network/interfacesso it looks like this (use your own IPs):
auto lo iface lo inet loopback auto eth0 iface eth0 inet manual auto br0 iface br0 inet static address 192.168.1.222 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.167 bridge_ports eth0 bridge_stp off bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_maxwait 0
Make sure that you have a direct console to the server because you're going to restart networking:
Verify that your changes took place with
ifconfig. You should see 2 entries like these:
br0 Link encap:Ethernet HWaddr 00:11:22:33:44:55 inet addr:192.168.1.215 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::223:aeff:fefe:1f14/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1099 errors:0 dropped:0 overruns:0 frame:0 TX packets:50 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:74665 (74.6 KB) TX bytes:6223 (6.2 KB) eth0 Link encap:Ethernet HWaddr 00:66:77:88:99:00 inet6 addr: fe80::223:aeff:fefe:1f14/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4939 errors:0 dropped:0 overruns:0 frame:0 TX packets:39 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:532798 (532.7 KB) TX bytes:5585 (5.5 KB) Interrupt:36 Memory:da000000-da012800
Setting up a VM
Setup a VM with
vmbuilder kvm ubuntu \ -v \ --suite=karmic \ --libvirt=qemu:///system \ --arch=amd64 \ --cpus=2 \ --mem=2048 \ --swapsize=4096 \ --rootsize=20480 \ --flavour=server \ --hostname=billiejean \ --ip=192.168.1.240 \ --mask=255.255.255.0 \ --net=192.168.1.0 \ --bcast=192.168.1.255 \ --gw=192.168.1.167 \ --dns='188.8.131.52 184.108.40.206' \ --bridge=br0 \ --mirror=http://archive.ubuntu.com/ubuntu \ --components='main,universe' \ --addpkg=openssh-server \ --user=administrator \ --pass=icanhaspasswd \ --dest=/root/vm-billiejean \ --tmpfs=-
The options you need to care about are:
suite: Version of Ubuntu to install (e.g. karmic, hardy).
cpus: Number of CPUs to assign to VM.
mem: Amount of RAM in MB to assign to VM.
swapsize: Size of swap in MB of VM.
rootsize: Size of root filesystem in MB of VM.
flavour: The "flavour" of kernel to use in the VM. Either "virtual" or "server".
hostname: Hostname of VM.
ip: IP address of VM.
mask: Netmask of VM.
net: Network of VM.
bcast: Broadcast address of VM.
gw: Gateway of VM.
dns: DNS server(s) for VM.
addpkg: APT packages to install in the VM. openssh-server is needed so that we can login to the VM to setup the virsh console.
pass: User account that's setup for you to access the VM.
dest: Destination directory on server where VM disk image will reside.
If your VM is created successfully, there'll be a config file for the VM in
/etc/libvirt/qemu/billiejean.xml), and a disk image in the directory specified in the
You can verify that it works by starting the VM and SSHing into it (virsh console will not work yet).
virsh start billiejean
Converting Disk Images to LVM Logical Volumes
Now, we have the VM setup but it's running off a disk image. For better performance, running the VM off a LVM logical volume will optimize disk IO.
vmbuilder is supposed to support the
--rawoption to write the VM to a block device (such as a LVM logical volume), but I've had no success with it (as does Mark Imbriaco, sysadmin of 37signals: http://twitter.com/markimbriaco/status/7437688341 and http://twitter.com/markimbriaco/status/7437699338). We're going to convert the disk images using qemu-img and write the bits into a LVM logical volume instead.
- Stop the VM if it's running:
virsh shutdown billiejean
- Convert the VM's qcow2 (QEMU image format) disk image to a raw disk image:
qemu-img convert disk0.qcow2 -O raw disk0.raw
- Create a logical volume to house the VM, making sure it's big enough for the VM's rootsize and swapsize options:
lvcreate -L24GB -n <logical_volume_name> <volume_group_name>
- Copy raw image into the logical volume:
dd if=disk0.raw of=/dev/<volume_group_name>/<logical_volume_name> bs=1M
This will take awhile (the bigger your image, the longer it takes).
- Edit the VM's config so that it uses your new logical volume:
virsh edit billiejean
<disk>to point to the logical volume:
<disk type='block' device='disk'> <source dev='/dev/<volume_group_name>/<logical_volume_name>'/> <target dev='hda' bus='ide'/> </disk>
- Startup the VM. You might wanna rename the original
disk0.qcow2image first just to make sure your VM isn't still using it.
- Once you're sure your VM is running off your LVM logical volume, you can delete or backup the original qcow2 disk image.
Getting a console to your VM from the Host Server
Now, we have to setup the VM so that virsh console works. This is a console to the VM from the host server that works even when the networking in the VM is not.
- Edit the VM's settings:
virsh edit billiejean
<serial type='pty'> <target port='0'/> </serial>
- Startup your VM:
virsh start billiejean
- SSH into VM and create a file
start on stopped rc RUNLEVEL= stop on runlevel [!2345] respawn exec /sbin/getty -8 38400 ttyS0 vt102
Start the tty with:
- Still in the VM, install acpid so that the VM will respond to shutdown commands from the server:
aptitude install acpid
- Reboot the VM.
- Verify the console works by opening a console to the VM from the server:
virsh console billiejean
You may have to hit "Enter" before you see any console output.
Miscellaneous VM Setup
That's it, your VM is ready! You'll probably want to do these:
- Set a root password and possibly delete the user you setup using
- Set the timezone with
- Update and upgrade apt packages (use your own discretion on whether this is necessary):
A minor UI improvement to Firefox has been made to Firefox and it's currently only available on nightly builds of Firefox: the Stop and Reload buttons have been merged into a single button. This change should make it into Firefox 3.6.
I'm always up for 1 less unnecessary button. I think this feature is copied from Safari (I might be wrong).
A mini-tip on viewing images quickly in a new tab in Firefox. Useful for web devs who want to look at the URL of an image quickly.
To open the thumbnail image of Maru in a new tab, right-click the image, and then middle-click the View Image item from the context menu:
It should open up in a new tab:
You can also do the same for background images (middle-click View Background Image from the right-click context menu).
Slightly more than a month back I wrote this little iPhone app (App Store link), almost a toy app really, to check the usage of my data plan with my local telco (Singtel). I wanted to scratch an itch and I also really didn't want to exceed my data plan - the fees are excessive.
Anyway, I submitted it to the iPhone App Store for approval as a free app and named it Singtel Data Usage. No points for creativity with the name but I thought it'd be nice to know exactly what the app did from just reading its name. After one keyword rejection (which was unfounded but I wasn't going to argue with the app reviewers), it finally got approved a few days ago.
Yeah that's what it looks like. I stole part of the design from another iPhone app - can anyone guess which one? I think I spent 80% of development time changing the design over and over again, tweaking font sizes, and agonizing over which icons to use.
Thanks to folks on Twitter (I'm @chuyeow - do follow me if you're reading my blog), word got around and by the 3rd day of it being approved, my app was the Top Free app on the Singapore App Store. Going to take a time out for the vanity shot:
A similar app, iBBOM, was approved around the same time but I believe I got a head start because of all the awesome people on Twitter who retweeted my tweet and the kind folks who gave glowing reviews on the App Store (thanks especially to Andy Croll for the 1st review). iBBOM actually looks much better than my app (I can't help tweeting about it) and works perfectly (only thing I don't like are the ads). I believe I couldn't have gotten to the top of the App Store without the guys and gals who spread the word on Twitter.
On to the not so fun part of this post. Yet another similar app, SG BBOM, was pulled from the App Store by Singtel (the telco) recently so I'm expecting to hear from Singtel really soon. We shall see.
In the meantime, if you own an iPhone and have a Singtel data plan, do check out my app (App Store link) and give an honest review on the App Store. If you've already downloaded it, I'd like to know what you think in a review as well. Thanks!
After 5 long years of using the same old blog theme, which I'd handcrafted from scratch way back in 2004, I've finally got down to refreshing it to a more contemporary look. I've also updated the woefully outdated About page.
Here's a before and after shot:
I think it's much better, definitely more modern and minimalist.
The only thing I kept from my old theme, which I affectionately called "Clover", was the same clover logo. I did that with the shape tool in Photoshop - it's a simple logo and no skill was required to create it, obviously!
If you're reading this in a feed reader or one of those aggreggator-type sites, you can help me out by checking out the blog itself and giving me some good old constructive criticism.
subscribe via RSS