UNIX / Linux keyboard.

How to run the QEMU emulator and Linux on a USB device

QEMU and Linux on a USB Device

This lets you run Linux within a window on a hosting machine running Linux or BSD or Windows.

No need to carry a bulky and expensive laptop. Just plug your USB thumbdrive into a host computer and start your own person machine running within a window there. You do not reboot the host machine — your Linux system runs as an application on its graphical desktop. It finds and uses the network connections, and acts like a full (although somewhat slow) Linux system!

First: Get QEMU and Puppy

See the page that explains how to do this with Puppy Linux: http://www.erikveen.dds.nl/qemupuppy/index.html. That very likely tells you everything you want. However, for suggestions of which further steps are especially useful, and how to do this with a different distribution, keep reading this page.

Notice that you can do all the initial work directly on your native Linux system! Extract the files into a directory and get things running there. No need to write the files to your USB drive until you have things set up the way you want them.

Second: Set up client SSH from the QEMU/Linux system

See my explanation of how to set up SSH user keys. This will let you easily pull in all your personal information, and easily upload it again. As the QEMU/Puppy page explains, FTP can be tricky in the QEMU environment. But SSH works just fine!

If you have already set up client SSH on your native Linux system, then good for you! Simply go into your QEMU/Puppy system and do the following, replacing nativelinux with the hostname of your native Linux system:

$ cd
$ scp -pr nativelinux:.ssh .

But if you haven't done this yet, see my explanation.

Third: Give yourself some room

See the suggestion on that page for resizing the file system. On your native Linux system:

$ resize2fs -f pup_save.3fs 512M
resize2fs 1.40.6 (09-Feb-2008)
Resizing the filesystem on pup_save.3fs to 524288 (1k) blocks.
The filesystem on pup_save.3fs is now 524288 blocks long.

Fourth: Replace the limited vi and more

Many of the UNIX utilities included in Puppy Linux are really part of Busybox, and so they are very stripped down and somewhat lame. I found its simple versions of more and vi especially annoying. See the suggestion on that page for installing a "DotPup" addition for vim, just do the following within your QEMU/Puppy system:

$ wget http://www.erikveen.dds.nl/qemupuppy/dotpups/vim.pup
$ rox vim.pup

/bin and /lib are rebuilt at every boot, so you need to shuffle things around every time. Notice that you already have less, the more capable replacement for more. Just add the following to the end of /etc/rc.d/rc.local:

mv /bin/vi /bin/vi.old
ln -sf /usr/bin/vim /bin/vi
mv /bin/more /bin/more.old
ln -sf /usr/bin/less /bin/more

Fifth: Do all this with a different distribution

I decided to try this with DSL Linux instead of Puppy. Start by downloading its embedded version. Also download the QEMU/Puppy embedded file.

The problem is that the embedded DSL version only includes QEMU for Windows! Yes, that's generally what you want when you're in some cybercafe, but it's not very useful for testing in your environment where you have nothing but UNIX machines.

The downloads will give you this:

$ ls -l
-rw-r--r-- 1 cromwell cromwell 51089688 Feb 19 10:52 dsl-4.2.5-embedded.zip
-rw-r--r-- 1 cromwell cromwell 91037739 Feb 19 10:48 qemu-puppy-2.17-1.tar.gz

Extract the two archives. Be careful, don't make a mess of the files! You want to have two subdirectories, one with each embedded distribution.

$ mkdir extracted-qemu-puppy
$ cd extracted-qemu-puppy
$ tar xvfz ../qemu-puppy-2.17-1.tar.gz

$ mkdir extracted-dsl
$ cd dsl
$ unzip ../dsl-4.2.5-embedded.zip

The QEMU/Puppy framework has both Windows and UNIX versions of QEMU, so we use it as a starting point. Remove the Puppy-specific files:

$ cd extracted-qemu-puppy
$ rm initrd.gz pup_save.3fs pup_217.sfs devx_217.sfs zdrv_217.sfs

Copy in the DSL-specific files:

$ mv ../extracted-dsl/linux24 .
$ mv ../extracted-dsl/minirt24.gz .
$ mv ../extracted-dsl/KNOPPIX .

Modify the UNIX QEMU script puppy.sh by changing the last line to the following. Note that I have broken the lines for display here, be very careful if you do that instead of simplying changing the one long line.

If you know the Linux machine will have more memory, then change that 128 to a larger number. But make sure that it is no larger than half the physical RAM on the host system!

$QEMU -kernel linux24 -initrd minirt24.gz \
	-append "qemu vga=791 noscsi nousb nofirewire atapicd noideraid \
			noacpi acpi=off noapm noagp \
			ide1=noprobe ide2=noprobe nomce frugal" \
	-hda KNOPPIX/KNOPPIX -m 128 $*

I eventually decided that I preferred Puppy Linux over DSL, once I replaced its more and vi and made other adjustments.

Below are some screen shots of DSL Linux running inside QEMU on a 64-bit Windows XP desktop. The screen shots are at 50% of original resolution, click on them for full-sized versions.

DSL or Damn Small Linux running inside a QEMU emulator on a 64-bit Windows XP desktop.

DSL Linux running inside QEMU on a Windows XP desktop.

Firefox on DSL or Damn Small Linux running inside a QEMU emulator on a 64-bit Windows XP desktop.

Firefox on DSL Linux running inside QEMU on a Windows XP desktop.

Another Method

Also see pendrivelinux.com for a way to run Linux from a USB device, either rebooting the hardware or, more elegantly, running it under Windows with QEMU.

Another Operating System Choice

Can you run Windows 8 inside QEMU on OpenBSD? Apparently! I haven't done it, but here's a video by someone who did.

VMware Networking How to Build VirtualBox on Linux How to install and run Windows within the QEMU emulator on an OpenBSD or Linux desktop Installing Office on that virtual Windows system Back to the Linux / Unix page