DOS Emulation with dosemu

Dean Oisboid

Issue #13, May 1995

Do you like Linux, but need to use DOS programs? Dean Oisboid recently braved the wilds of the Linux DOS emulator and has returned with the answer.

Welcome back. In the first Novice-to-Novice article, we installed Linux to an existing DOS setup using UMSDOS and without needing to repartition. This is one of the great beauties of Linux for PC users—being able to try it without losing their DOS setup.

If you read the first article, you know it took me a few tries to get a good installation, the problem primarily being not enough hard drive space despite reserving 150 megabytes for this purpose. Since then, I must confess, I reinstalled one more time, and by being very picky regarding which files to install, I managed to keep Linux down to about 80 megabytes of the 150 available.

Also I discovered that Slackware defaults to four virtual consoles set up for login, with X coming up on the fifth virtual console. While this was great for switching between screens using the Alt-F buttons, the resulting lack of RAM (I only have 8 MB) interfered with many programs, most notably seyon (a modem program) under X-Windows. The solution was to edit the /etc/inittab file and comment out (by putting a # character at the beginning of the lines mentioning tty3 and tty4) the third and fourth virtual consoles. Rebooting with this freed up a lot of memory, allowing X and seyon to run a bit smoother.

For this article, we'll explore a unique facet to Linux: running MS- or PC-DOS under Linux via dosemu. (Windows emulation using WINE is still in its infancy and was covered in the August 1994 issue of Linux Journal.)

Why try dosemu? Put simply, emulators allow you to use multiple operating systems at one time. The flexibility that this gives the user is something that is not available in Windows and DOS, but it is available under Linux. There are also other emulators available for other operating systems; the brave can try an Apple II+ emulator or an “iBCS2” emulator that allows the user to run binaries intended for other Unix systems. You can see that Linux may well stand as the vanguard of a quiet yet extraordinarily powerful revolution—that of function and utility over sheer profit margin.

Enough of that, let's do it!

For the record, I tested version 0.53 patch level 28 of dosemu. This is the distribution I received on my Slackware Professional 2.1 disks. (As always with projects in development, these versions were obsolete even before the CDs were mastered.) The latest development version of dosemu is 0.53pl45 as of this writing, and the developers plan to have a stable, public release available soon after Linux 1.2.0 is released.

I copied /tsx-11/ALPHA/dosemu/Development

/pre0.53_28.tgz to /usr using mc, the Midnight Commander—the great Norton Commander clone—which also, via an option under F2, allowed me to unzip and untar the file once it was copied over.

If you have purchased any Linux documentation, you may have discovered that information on dosemu is skimpy. There is a HOWTO, but it doesn't cover using the emulator in conjunction with UMSDOS nor how to begin, except for a reference QuickStart to a file that comes with dosemu. Looking through this file, another thing you'll notice is that dosemu will need to be compiled. Time for a heart attack.

Two immediate caveats: One, you will need to have bison and flex (installed from Slackware's `D' set), otherwise the compilation process will crash. Second, you want to backup any important DOS files and prepare a DOS system boot disk. I insist!

If you want to compile this version of dosemu, the installation recommends having a sum total of 12-20MB of RAM and swap available. My computer has only 8MB of RAM and dosemu just wouldn't compile. Swap space was definitely needed. I had not ever tried setting up swap but decided to give it a try.

Novice Note: If you decide to create a swap space (while using UMSDOS) you must—must, must--repartition your hard disk. If you go through the creation process without repartitioning and referring to that partition, expect to lose something. My hard disk got slaughtered! Linux wouldn't recognize directories. A reboot wouldn't bring up DOS. Panic? Heart attack? Wet pants? Oh yes, and then some. Luckily I had a DOS boot disk, and Norton Disk Doctor was able to put things right and restore the FAT (File Allocation Table) and system files. Sigh of relief! This is how religions get started.

What I really wanted, since it doesn't require repartitioning, was a swapfile for my swap. Peter Scott of the Jet Propulsion Laboratory pointed this out to me and gave me a clue as to the commands to do the job. In a normal Unix system, he also mentioned, you would want a large partitioned swap space, around 50MB or so. I shook my head; my hard drive was down to 30MB because of a sudden influx of vital games and work-related data. [Linux requires less swap space than normal Unix systems because it uses memory somewhat differently—ED]

According to the System Administration manual, you create a swap file called /swap with the following:

dd if=/dev/zero of=/swap bs=1024 count=8192
mkswap /swap 8192
sync
swapon /swap

This will create an 8MB swap file. Even if you decide to skip using dosemu, you could still benefit from using swap. For example, I've been playing with a copy of Netscape in X, but without swap, it wouldn't allow me to access the preferences menu. It would crash. But with the swap active, preferences and other menus became available. This was a real testament to the value of swap space.

In order to cause the swap file to be used each time you boot, you can add swapon /swap to your /etc/rc.d/rc.local file. However, a better way is to add the line:

/swap  none  swap  defaults  0  0

to your /etc/fstab file. This will cause the swap to be automatically added at the best possible time.

If you ever desperately need the disk space back, you can delete the swap file with:

swapoff /swap
rm /swap

If you have added a line to /etc/rc.d/rc.local or /etc/fstab, make sure that you remove that line.

With a swap file in place and active, I tackled the compilation of dosemu again. Reading through the QuickStart file knotted my stomach but I followed instructions. The command:

make most

started the dirty work of compilation. I do not have TeX (an advanced typesetting system) installed, so this was the correct command instead of make doeverything. After some time of grinding, the compilation finished. No crashing errors! The instructions then said to copy hdimage.dist to /var/lib/dosemu/hdimage and also to copy and edit /examples/config.dist to /etc/dosemu.conf.

Editing /etc/dosemu.conf was straight-forward. The only lines I really had to change were for my mouse and modem; I also had to uncomment the reference to:

disk { image "/var/lib/dosemu/hdimage" }

The sample dosemu.conf file that was provided has extensive comments explaining what to do.

With that done, I then prepared the recommended boot disk by returning to DOS and formatting a system disk. Then back to Linux.

Finally, I typed in dos, and sure enough, the boot disk booted and I was staring at the familiar A: prompt. From there if I typed C: I was brought to an image of a C: drive.

Nice, but not what I was expecting. The goal was to be able to access my current DOS system through Linux, not have a faux DOS image.

Going back into the /etc/dosemu.conf file, I switched the hard drive reference to:

disk { partition "/dev/hda1" 1 readonly }

This would allow me to access the hard drive but not change anything because of the readonly mode. Yet when I started dosemu nothing happened. What the heck, I changed the disk reference to:

disk { wholedisk "/dev/hda" }

which would allow full and potentially dangerous access. Typed dos and sure enough dosemu started to load. First thing noticeable was a message saying something about QEMM (Quarterdeck's memory manager program) not being loaded because the processor was already in Virtual 86 mode. Without QEMM, many of the other memory residents didn't get loaded. A check using DOS mem showed that the mouse and CD drivers were missing (not surprisingly, since dosemu provides its own mouse and CD drivers). Yet in all, I had 599K free RAM. Not too bad. However, the real test would be to run a program. [dosemu provides the basic functionality of QEMM—it provides as much EMS and XMS memory as you want it to—ED]

Unfortunately, while the documentation says that wholedisk access is dangerous, it is easy to miss why it is dangerous. It turns out that a DOS file system can be destroyed by using wholedisk access to that partition while that partition is mounted by the kernel, either as a Ms-dos or UMSDOS file system.

After experiencing some file system damage, I found out that there is a way to make my DOS C: drive also be my C: drive under the DOS emulator without doing damage and without booting from a floppy. Taking a hint from a comment in dosemu.conf, and with a little help from a friend, I first edited config.sys on my boot floppy, adding the line:

device=a:\emufs.sys /dos/

which makes the /dos directory under Linux show up as C: under dosemu. I also added the line:

a:\lredir d: linux\fs\

to autoexec.bat to make the Linux root directory show up as D: under dosemu, to make it easier to access some Linux files from within dosemu.

I then enter

dd if=/dev/fd0 of=/var/lib/dosemu/floppy

with my boot floppy in drive A. Then, in the floppy configuration section of dosemu.conf, I changed

floppy { device /dev/fd0 threeinch }:

to:

floppy { heads 2 sectors 18 tracks 80 threeinch
file /var/lib/dosemu/floppy }
floppy { device /dev/fd0 threeinch }

by modifying and uncommenting a few lines. I changed the bootC line to bootA and removed the wholedisk line that damaged my files. Now I could boot without a floppy in the drive, but C: was still C:. [There are other ways to do the same thing, but this works fine—ED]

Sadly, it still seemed that nothing would run. Quattro Pro 5 for DOS crashed mightily. Warlords II did the same. The crashes were bad enough to not only lock up the computer but when I did a Ctrl-Alt-Delete to reboot, the screen filled with colorful garbage. This rather pretty effect also happened if I switched virtual consoles.

Although I hated to ask for any help, I sent a message to James MacLean, who is the current maintainer of dosemu, asking if anyone else had success using dosemu under UMSDOS. Three replies came quickly back from Mr. MacLean, Marty Leisner, and Lars Marowsky-Bree. All offered help, which I politely declined because their very replies gave me the incentive I needed—the knowledge that, indeed, someone had succeeded!

Back in Linux, I glared mightily at dosemu.conf—and bless it if the answer wasn't there all the time. A section of the configuration file deals with the video setup. Originally I had chosen:

video { vga console }

but I should have chosen:

video { vga console graphics }

to enable graphics. This worked! When I ran dos and picked the bare boot setup, sure enough, I could now run programs like Warlords II or Quattro Pro 5.

But the mouse wouldn't work. AAARRGHH!! OK, exitemu to return to Linux, edit /etc/dosemu.conf, and change the line from:

serial { com 1 mouse }

to

serial {com 1 device /dev/mouse }

and try once again. No good. DOS just couldn't find the mouse as if...as if the mouse were already in use. GPM! (General Purpose Mouse driver) My Linux setup automatically loads gpm upon booting. Using top, I located the process number for gpm and kill-ed it. [killall gpm would also work—ED] Back to DOS, load the mouse driver. YES! DOS recognizes the mouse. YES! Warlords II runs with mouse support! YES! Quattro Pro v5 runs with mouse support! NO! FoxPro 2.6 crashes because of memory problems (I expected that but the lucky streak was there and I had to press it). [FoxPro 2.6 can also be run with the correct configuration—ED]

Whew! Despite all my problems with compiling, swaps, and pretty color crashes, I consider dosemu an incredible achievement. That DOS can run under Linux is mind-boggling. Sure, dosemu can be rough going for us newbies but the potential reward makes up for it. There are a few things being worked on now that will make it easier. One is the FreeDOS project which is writing a free version of DOS. It will run under dosemu just like MS-DOS, except that dosemu can be distributed with it pre-installed, saving the user (that's you!) the pain of installing a legally-owned copy of MS-DOS, PC-DOS, or DRDOS to get started. Also, the public release of dosemu should be very stable and easier to distribute.

Next month, the lighter side of Linux as Novice-to-Novice descends into the depths of DOOM and tackles blasting sound using a SoundBlaster. Until then...

Dean Oisboid, owner of Garlic Software, is a database consultant, Unix beginner, and avowed Warlords II addict. He can be reached at 73717.2343@compuserve.com.