Setting up Stubby

"Stubby" is my pet Debian Linux system. For work, I need to run a customized version of Red Hat Enterprise Linux on my laptop, which lacks the variety of software I want to use. After using Debian for years, I miss the apt-get ease of Debian (and now Ubuntu). My solution: run an emulated Debian machine under QEMU that I can use for hobby programming projects.

Overview of the steps

  1. Download and set up QEMU
  2. Download and set up the kqemu accelerator (optional, but recommended)
  3. Make a disk image and install Debian on it
  4. Set up networking for ssh from my main OS to Stubby
  5. Enjoy!

Download and set up QEMU

You can get QEMU from the author here. There is excellent documentation on how to install it, so I won't wast time or space here doing a poor job of regurgitation.

Download and set up the kqemu accelerator

The kqemu accelerator makes QEMU 2 to 10 times faster, but has a couple of restrictions:

  1. A stricter license.
  2. Only works for x86 on x86 emulation.

Again, see his documentation for details, but I had no problems getting it working. Here is what I run as root at boot time on my host OS to set up the acceleration:

# Load the kqemu accelerator:
sudo /sbin/modprobe kqemu

# Allow users to use the real-time clock at 
# higher speeds than the default
echo 1024 > /proc/sys/dev/rtc/max-user-freq

# Create the kqemu device so that no special 
# privilege is needed to use kqemu.
rm -f $device
mknod $device c 250 0
chmod 666 $device

Make a disk image and install Debian on it

Start downloading a CD-ROM iso of the Debian installer. I used the 40 MB mini-installer CD available here. You'll be able to install whatever else you want later using apt-get, so start small.

While that is downloading, create a disk image to hold your Debian system. To begin with, it will look very small, but qemu will expand it as needed (up to the full 8 GB given in this command).

$ qemu-img create -f qcow debian.dsk 8G
Formating 'debian.dsk', fmt=qcow, size=8388608 kB
$ ls -l debian.dsk
-rw-r--r--  1 harold harold 32816 Jan  5 16:52 debian.dsk

Now you can start up Debian installer using qemu with the following command. Your new Debian system will start up in a window and begin the installation. Networking will be auto-detected and work via your host OS network connection. Walk through the installer and you should be all set to go.


It might be a good idea to either put the swap partition first or use a swap file instead of a partition. This will keep qemu from expanding the disk image file to almost the full 8 GB right away.

$ qemu debian.dsk -cdrom debian-31r4-i386-businesscard.iso -boot d

If kqemu is not working correctly, you'll get a message in your terminal that it is not available. It is up to you to decide whether to go back and fix that now or proceed with a slower virtual machine.

After the install is done, you'll be able to start the Debian system in a window whenever you want using this command:

$ qemu debian.dsk

Set up networking for ssh from my main OS to Stubby

With sshd installed and running by default on Stubby, you need to take two more steps to get an ssh connection from the host OS to Stubby. First, we add a flag to the qemu command line to connect a port on the host OS to the sshd port (port 22) on Stubby. Then, we set up the ssh config file to be able to find stubby.

The new command line for qemu:

$ qemu debian.dsk -redir tcp:12345::22

The new information in your $HOME/.ssh/config file:

Host stubby
   HostName localhost
   Port 12345

A few parting thoughts ...

  1. Look into increasing the amount of memory you give the child OS, e.g. -m 256M on the qemu command line will give it 256 MB of memory instead of the default 128.
  2. Using -nographic will skip the window, but you'll still be able to ssh into the child machine. If you use the "ForwardX11 yes" option in your ssh config file, you can have GUI programs pop up on in your host OS window manager, which I like. If you do install X, I recommend removing the /etc/rc2.d/S99xdm symlink so that it won't try to start X in Stubby by default.
  3. You might also look into shortening the GRUB timeout before it boots to the kernel.
Picture of my email address.