Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Embedded Systems

Virtualization: Up Against the Wall

Driving on Virtual

QEMU emulates a complete desktop-class PC with system and VGA BIOS code from the Bochs project, peripherals typical of a low-end PC, and linkage to some of the host machine's actual hardware. I used only the video and disk interfaces, although the emulated NIC can access SMB-shared files on the host.

Because pixie's hard-disk image must eventually fit on the CF card, the first step is measuring the card. The command /sbin/fdisk -ul /dev/sdc displays the raw device capacity in bytes: 2,079,350,784 for my card. Note that shiitake has two SATA drives that put the CF card at /dev/sdc, but your system will be different. I stored the CF size in an environment variable CFsize=2079350784 to avoid typos. (Hint: Use your mouse to highlight the value and middle-click-copy to the command line.)

Listing One (a) shows how to create drive images. The count=0 seek=<size> parameters produce a sparse file occupying only the disk space required for nonzero sectors. The initial hard-drive image thus requires essentially no space and the final images will be about half a gig.

dd if=/dev/zero of=develop.hd bs=1 count=0 seek=$CFsize
dd if=/dev/zero of=uttpdos.fd bs=1K count=0 seek=1440

/sbin/mkdosfs uttpdos.fd
sudo mount -o loop,uid=ed uttpdos.fd /mnt/loop
cp uttpfdos.exe /mnt/loop
Listing One

Listing One (b) shows how to set up a floppy filesystem and copy files using the loopback device. The uid=ed parameter sets the owner to my userid, simplifying the copy. This column's download file contains cfg-devel.fd and cfg-pixie.fd, the floppy-disk images I used to configure those systems, which should save you some typing.

Listing Two (a) shows how to fire up QEMU for the FreeDOS installation. Watching DOS install itself in a Linux window is less weird than watching Windows in a Linux window, but we won't go there. The FreeDOS installation will see a completely blank drive and offer you its disk partitioner; a 10-MB partition suffices for a minimal installation and the ThinkPad utilities.

qemu -kernel-kqemu -fda uttpdos.fd -fdb blank.fd -hda develop.hd 
             -cdrom fdfullcd.iso -boot cdrom

qemu -kernel-kqemu -fda cfg-devel.fd -hda develop.hd 
             -cdrom slackware-11.0-install-d1.iso -boot d

qemu -kernel-kqemu -fda cfg-devel.fd -hda develop.hd 
             -cdrom slackware-11.0-install-d1.iso -boot d
bare.i root=/dev/hda2 noinitrd ro   (boot Slackware from hard drive)
ctrl-alt-2          (get to QEMU monitor)
change cdrom slackware-11.0-install-d2.iso
ctrl-alt-1          (return to Slackware install)
mount /dev/hdc /mnt/cdrom
installpkg /mnt/cdrom/extra/grub/grub-0.97-i486-2.tgz
grub-install —no-floppy /dev/hda
mount /dev/fd0 /mnt/floppy
cp /mnt/floppy/config/menu.lst /boot/grub

qemu -kernel-kqemu -fda cfg-devel.fd -hda develop.hd
Listing Two

After installing FreeDOS, extract the utilities from their EXE wrapper to "floppy drive b:" using some applied VM magic:

a:uttpfdos b:

then copy the results to a directory on the equally unreal hard drive with:

mkdir ThinkPad
copy b:*.* ThinkPad

Those utilities will not run in the VM, of course, but they'll be ready to configure the real ThinkPad.

When you install Slackware with the QEMU command line in Listing Two (b), use cfdisk to create a pair of 1-GB ext2 partitions for system and image storage; we'll later resize them for pixie. Select ext2 rather than ext3 filesystems, because we don't need a robust journal.

Create a mount point and mount the floppy image before starting the Slackware install program:

mkdir /fd
mount /dev/fd0 /fd

My cfg-devel.fd floppy image has tagfiles that produce a bare-bones Slackware: Install the A, AP, D, K, L, N, and X groups with the tagpath set to /fd/tagfiles. The floppy has some other config files you'll find useful, including an automatic root login. That actually makes sense here, as you're always doing dangerous system manipulations. Get over it.

I have never had much luck with lilo, Slackware's boot manager of choice, and wasn't surprised when it choked during this installation. Listing Two (c) shows the one-time dance required to start from Slackware CD 1, boot the hard-drive kernel, insert the CD 2 image, install and configure grub, and finally reboot normally. You can back up the hard-drive image by just copying the develop.hd file: A virtual machine makes trial-and-error learning much less painful.

You must shut down Slackware using halt or shutdown, because just quitting QEMU is exactly the same as pulling the plug on a physical system. Filesystem damage is a clear and present danger.

After verifying that the development system boots properly in the VM, do a smoke test. Shut down Slackware, exit QEMU, unmount the CF card, and copy the entire develop.hd image:

sudo dd if=develop.hd of=/dev/sdc bs=1M

The bs=1M parameter dramatically improves throughput, although the USB adapter and CF card may limit the maximum rate. My setup runs at about 10 MB/s with a 50X card.

Pop the CF card and IDE adapter into the ThinkPad's hard-drive connector and turn it on, at which point grub should boot just as it did in the QEMU VM. Fire up FreeDOS and use the ThinkPad PS2 utility to enable Presentation mode and set the serial port to COM1 for use as a console. Reboot to Slackware, which should also behave just as it did in the VM.

At this point you have a functional Slackware system to install the DPF programs and sample images. You'll use the VM for the next steps, but it's comforting to see the ThinkPad track the VM's progress.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.