freebsdzine.org
Hanson's Treatment of Time: There are never enough hours in a day, but always too many days before Saturday.

[ Home  · Latest BSD News  · Site Statistics  · Wanted Articles  · Request an Article  · Submit an Article ]

Search freebsdzine.org

FreeBSD 'zine Polls

How did you find out about this site?

FreeBSD web site
Slashdot
BSD Today
Daemon News
IRC
FreeBSD mailing list(s)
word of mouth
a search engine
from moses

Results  · More polls


Sections
· Wanted articles
· Request an article
· Contribute
· Mailing lists
· About the site
· The staff
· Copyright info
· Privacy policy
· Change log
· Contact us

Resources
· The FreeBSD Project
· The FreeBSD Diary
· BSD Today
· Daemon News
· Daily Daemon News
· Slashdot BSD
· FreshPorts
· The FreeBSD Mall
· BSDVault
· The FreeBSD Browser
· GreasyDaemon.com
· iso-nix.com

FreeBSD Books
· Complete FreeBSD
· FreeBSD Handbook
· FreeBSD Corporate
Networker's Guide


Runs on FreeBSD
Using Bochs - Part 1
Marc Fonvieille <[email protected]>

Introduction

Bochs is a highly portable open source x86 PC emulator. It includes emulation of the Intel x86 CPU, common IO devices, and a custom BIOS. Like VMware, Bochs is a kind of virtual machine that can run Windows95, MS-DOS, Linux, etc..

MandrakeSoft has bought Bochs, and committed it to open source (LGPL) in order to help the development of the Plex86 project (an open source PC virtualization software program which will allow users to run multiple operating systems concurrently on the same machine).

Last month, I talked about doscmd(1), which allows you to run DOS programs, however, it only can run text-based applications. In the first part of this article, I'll demonstrate how to run MS-DOS applications in Bochs (both text and graphical applications). The second part of the article will cover Windows95 and other OSes.

Getting Ready

As with VMware, you'll need a pretty fast machine to run Bochs (a 400MHz machine should be plenty). Having at least 64MB of RAM will also help. You should also be running FreeBSD 3.X or 4.X.

The first thing you'll need to do is install Bochs. Execute the following command as root:

# cd /usr/ports/emulators/bochs && make install clean

In order to run Bochs, you need a VGA font. If you have a recent FreeBSD 4.X source tree (after June 30, 2000), the font is included with the source, and you just have to do the following before running Bochs:

% xset fp+ /usr/libdata/doscmd/fonts

The above can also be added to your .xinitrc file, if you prefer that method.

If you don't have a source tree from after June 30, 2000, you'll have to do the following:

  1. Fetch this file.

  2. Run the following commands as root:

    # uudecode cp437-8x16.pcf.gz.uu > cp437-8x16.pcf.gz
    # cp cp437-8x16.pcf.gz /usr/X11R6/lib/X11/fonts/misc/
    # mkfontdir /usr/X11R6/lib/X11/fonts/misc/
    # xset fp rehash
Configuration

You must create a "virtual hard drive" image file. The image size depends on the CHS number (Cylinders, Heads, Sectors) of the virtual hard drive.

Here are some examples of drive geometries:

Size Cylinders Heads Sectors/Track Sectors Total
10MB 306 4 17 20808
20MB 615 4 17 41820
30MB 615 6 17 62730
46MB 940 6 17 95880
62MB 940 8 17 127840
112MB 900 15 17 229500
126MB 256 16 63 258048
483MB 1024 15 63 967680
504MB 1024 16 63 1032192

For a typical MS-DOS installation, I used a 62MB image, which I created with dd(1):

% dd if=/dev/zero of=62M.img bs=512 count=127840

The block size (bs) is the same as a disk sector size (512), the count is the number of sectors total (940*8*17). I chose 62M.img as the name of the image. To create a blank 1.44MB floppy image, you'd use the same method:

% dd if=/dev/zero of=floppy.flp bs=512 count=2880

Since I want to install MS-DOS on this virtual hard drive, I need floppy images of the MS-DOS installation set. MS-DOS 6.22 comes with a 3 disk set, so I created 3 images:

% dd if=/dev/rfd0 of=/home/user/dos1.flp
% dd if=/dev/rfd0 of=/home/user/dos2.flp
% dd if=/dev/rfd0 of=/home/user/dos3.flp

The next step is to configure your ~/.bochsrc file. Put the following lines in it:

# amount of memory you want to emulate
megs: 16
# vga rom bios and bios image
vgaromimage: /usr/local/lib/bochs/bios/VGABIOS-elpin-2.20
romimage: file=/usr/local/lib/bochs/bios/BIOS-bochs-990925a, address=0xf0000
# disk C: definitions
diskc: file=./62M.img, cyl=940, heads=8, spt=17
# floppy A: definitions
floppya: 1_44=./1.44M, status=inserted
# log file
log: ./bochs.out
# misc delays
keyboard_serial_delay: 200
floppy_command_delay: 500
# vga update interval (the default is 300000 (3Hz))
# but I got better results with 100000
vga_update_interval: 100000
# instructions per second (see below for details)
ips: 1300000

In order to find out what value to use for ips directive in your .bochsrc, do the following when you install Bochs:

# cd /usr/ports/emulators/bochs && make patch
# cd work/bochs-2000_0325a/

Edit config.h.in and change line 54 from:

#define BX_SHOW_IPS	0

to:

#define BX_SHOW_IPS	1

Then install the port as usual:

# cd /usr/ports/emulators/bochs
# make install clean

When you run Bochs, it will print the ips rating. Use the average value from this rating for the ips directive. After finding that out, you'll have to rebuild bochs with the default value for #define BX_SHOW_IPS, which is 0, to avoid ips rating printing.

As you can see in your .bochsrc, the name of the floppy drive is 1.44M, so you'll need to rename dos1.flp to 1.44M, like so:

% mv dos1.flp 1.44M

If you don't do that, you will not be able to boot off the first DOS floppy.

Now we're ready to run Bochs for the first time. Do the following:

% bochs boot:a

If you get this message:

# bochs: Cannot open vga font
bochs exited, log file was './bochs.out'

Be sure to double-check that you have the VGA font installed. See the Getting Ready section of this article for information on doing that.

The MS-DOS installation is quite simple, just follow the instructions as usual. When the install process is finished, bochs shuts down, and you will have to launch it again with:

% bochs boot:a

After installing everything from the first floppy, the install process will ask you for the next one. Click on the floppy A icon in the toolbar. You should see a cross through it, which means the floppy is ejected. Then do the following:

% mv dos2.flp 1.44M

Click on the floppy A icon again and insert the new floppy to continue the installation. You'll have to do the same thing with the third floppy. It took about 10 minutes to install MS-DOS on my Celeron 433. When the installation is done, you have to reboot bochs from the virtual hard drive, like this:

bochs boot:c

You should see something like this:

Figure 1.0
Figure 1.0 (click to enlarge)

I ran into a keyboard problem with my french keymap. Bochs emulates an 83-key keyboard. To obtain proper keyboard functionality, I switched to the US keymap and removed all lines pertaining to the keyboard from autoexec.bat.

Use

There are plenty of great, old DOS programs lying around. As on a real DOS machine, you'll have to tune your config.sys and autoexec.bat files in order to run many DOS applications. Also, avoid the use of emm386.exe, since it tends to hang Bochs.

To install DOS applications, using the virtual floppy isn't always the best solution. I thought it would be interesting to access the virtual hard drive directly from FreeBSD to copy the programs I wanted to run, so I installed the mtools port:

# cd /usr/ports/emulators/mtools && make install clean

Create ~/.mtoolsrc with the following line in it:

drive c: file="/home/user/62M.img" partition=1

To copy a file onto the virtual hard drive:

% mcopy the_file c:/the_directory/

For more about mtools, take a look at it's man page. Be aware that you must power down Bochs before doing that if you're running any software that does disk caching.

To use the mouse, you'll have to load the mouse driver (just like on a real DOS machine):

lh mouse.com

Launch the application that needs the mouse, and then click on the mouse icon in the toolbar to enable it.

The CDROM and SoundBlaster emulation didn't run during my tests.

Conclusion

Bochs is rather slow, but it's free and can run most DOS applications. Next month, I'll cover the use of other operating systems with Bochs.

- Marc Fonvieille

Return to the April 2001 Issue



Issues
2001
· April
· March
· February
· January

2000
· December
· August
· July
· June
· May
· April
· March
· February

1999
· January

Other issues from 1999 are available in the attic for now.

Other News
· Slashdot
· FreeBSD Diary
· BSD Today
· FreshPorts
· Daemon News
· OS Online
· Rootprompt
· Maximum BSD

Miscellaneous
· Jim's site

IRC
#freebsdzine
If you'd like to hang out with us and talk about the site, join us in #freebsdzine on Undernet.

Backend
You can add a list of our latest issue's articles to your site by using our RDF/RSS file. You can also add it to your My Netscape page, or add our slashbox once you log in over at Slashdot.

[ Home  · Latest BSD News  · Site Statistics  · Wanted Articles  · Request an Article  · Submit an Article ]

Copyright © 1998-2001 · The FreeBSD 'zine · All rights reserved.