April 5, 2010

QEMU on Ubuntu

Filed under: Linux, Tech — Chris @ 9:22 pm

It was a lot easier to set up QEMU than I expected it would be. Easier even than the online tutorials make it seem.

  1. apt-get install qemu-kvm qemu-kvm-extras
  2. Download a prebuild image for the guest system you want to run. In my case, I wanted armel, which meant I also had to download initrd and vmlinuz images.
  3. If you want to copy files from the host system (i.e., your computer) into the guest, you need to make a “raw” image that you can mount from both sides:
    $ qemu-img create data.img <SIZE>
    Formatting 'data.img', fmt=raw size=...
    $ mke3fs -j data.img
    mke2fs 1.41.9 (22-Aug-2009)
    data.img is not a block special device.
    Proceed anyway? (y,n) y
    $ sudo mount -o rw,loop data.img <MOUNT_POINT>

    <SIZE> is a size in kilobytes, or use suffixes M and G for megabytes/gigabytes. The image only has to be big enough to temporarily hold the data you want to copy; you can move it to the guest’s root filesystem before you start working with it.

    <MOUNT_POINT> is any existing empty directory where you want to mount the image. I just made a directory foo in the same directory as the image.

    You should copy over any data now, because apparently it would be VERY BAD to do that while QEMU is running.

  4. Now it’s time to start the sucker. An example command line will be given in the README for the image you downloaded. I use:
    qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-1-versatile \
        -initrd initrd.img-2.6.26-1-versatile -hda debian_lenny_armel_small.qcow2 \
        -hdb data.img -append "root=/dev/sda1"

    Notice the -hdb data.img argument. That sets up the data image we set up in the last step as a disk drive in the guest system. You can probably login as user with password user. The root password is probably root.

  5. Once you’re logged in, make a directory to use as a mount point, then su and do:
    mount -t ext3 /dev/sdb <MOUNT_POINT>
  6. Now you can copy over your data. And here’s the beautiful part: you should be able to get on the network with no problem. If you need anything that’s not installed, just apt-get update and then apt-get install the missing package. Should work, no problem.

Blog at

%d bloggers like this: