Getting started with Bochs

13989

Author: Mayank Sharma

What if you need to run your legacy Windows application on a Linux box, a Mac, or a Solaris-based workstation? To make the equation even more interesting throw in a few requirements — add transferring old legacy accounting data over the network, or using the backed-up data from a CD-ROM. And yes, you want to keep the costs to a minimum. An open source project called Bochs may be your best option.

VMware is a (costly) commercial application that lets you run a guest operating system on a Windows or a Linux installation. Wine, on the other hand, though free, supports a very limited number of applications, and the same can be said about CrossOver Office. WinLin does a little better, but it doesn’t support Windows NT, 2000, or XP. And none of these alternatives run on Macintosh or SPARC-based hardware.

Bochs, an open source project, may be a better answer. It emulates 286, 386, 486, Pentium, Pentium Pro, and AMD 64-bit CPUs, fooling the guest OS into thinking that it’s running on real hardware. Bochs (pronounced “box”) provides I/O emulation for a computer’s standard parallel port, serial port, VGA card, disk, CD-ROM, timer chip, and network card, along with a custom BIOS.

Emulating the x86 hardware is Bochs’s strongest point. Bochs enables you to install Windows on a SPARC workstation or Debian on a Mac. However, hardware emulation deals a massive blow to the performance of the non-native operating systems.

The Bochs Web site says that Bochs is an ideal operating system and application testing environment. Unfortunately, you need high-performance top-of-the-line hardware to use the emulated environment productively. But Bochs is an ideal teaching tool for operating system classes.

Installing Bochs

You can download the latest release of Bochs, 2.1.1, in various packages for various environment. For Linux, you can download either the source package (.tar.gz) or the RPM. The source package is a better option, as it allows you to specify various options during install.

Change to the directory which houses the tarball, untar it, and run the configure script:

tar zxvf bochs-2.1.1.tar.gz
./configure --enable-ne2000 --enable-cdrom

The configure command tells Bochs to prepare the make files, enabling the network card and the CD-ROM. After configure has finished checking and generating the make files, issue the make command. Then change to the super user (su) and issue the make install command.

Configuring Bochs

The Bochs operating environment is regulated by a single file, .bochsrc, which resides in the base directory.

Before you can install an operating system using the new emulated hardware, you need to create a virtual hard disk. From the base directory issue the following command:

$ bximage

================================================================
                                bximage
                  Disk Image Creation Tool for Bochs
        $Id: bximage.c,v 1.19 2003/08/01 01:20:00 cbothamy Exp $
================================================================

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] hd

What kind of image should I create?
Please type flat, sparse or growing. [flat] flat

Enter the hard disk size in megabytes, between 1 and 32255
[10] 500

I will create a 'flat' hard disk image with
  cyl=1015
  heads=16
  sectors per track=63
  total sectors=1023120
  total size=499.57 megabytes

What should I name the image?
[c.img]

Writing: [] Done.

I wrote 523837440 bytes to c.img.

The following line should appear in your .bochsrc:
ata0-master: type=disk, path="c.img", mode=flat, cylinders=1015, heads=16, spt=63

In the session above I used bximage to create a 500MB drive named c.img.

Now edit the .bochsrc file in your favorite text editor. Scroll down to the ATA[0-3]-MASTER, ATA[0-3]-SLAVE section. Comment out everything below the example section by adding a # character in front of each line, then add the line as suggested by bximage above. Save the file, but don’t close it yet.

Starting from the top of the file under the section ROMIMAGE, verify the location of the BIOS-bochs-latest file. This file resides in the bios/ directory which is under the installation directory.

Next, specify the MEGS (the amount of memory the virtual system should emulate) you want. The default is 32. If you want to run DOS that should be enough. In the section FLOPPYA: make sure floppya: points to the real diskette device. It’s probably /dev/fd0, but check your /etc/fstab file if you’re not sure. In the boot section specify the device you want to boot from. The default is floppy.

Save and exit the file. Now you’re ready to run the new virtual machine.

Next: Running Bochs

To start Bochs, issue this command from the command line:

$ bochs

================================================
                       Bochs x86 Emulator 2.1.1
                           February 08, 2004
================================================
00000000000i[     ] reading configuration from .bochsrc
------------------------------
Bochs Configuration: Main Menu
------------------------------

This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate. Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found. When you are satisfied with the configuration, go
ahead and start the simulation.

You can also start bochs with the -q option to skip these menus.

1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Begin simulation
6. Quit now

Please choose one: [5]

You can begin the simulation by pressing Enter. After a lot of messages scroll across the screen, you’ll see the emulation window, which is like the monitor of your new machine. But since the drive the isn’t formatted, you will get an error. Time to get a disk image.

Installing a disk image

To format and partition the disk you just created, you need FreeDOS, which is a free version of DOS. The latest version of FreeDOS is beta9.

Edit the .bochsrc file and scroll down to the section where you specified the hard disk image. The c.img file is the ata0-master device. Add the following line:

ata0-slave: type=cdrom, path="/home/bodhi/freedos/fdbootcd.iso", status=inserted

Change the path to point to the location where the FreeDOS ISO resides. Save the file and exit.

Run Bochs. From the main menu press 3 to edit the options, then press 8 to change disk options. Finally press 16 to change the boot device. Typing cdrom will change the boot device for this session to CD-ROM. Press enter three times to return to the main menu and start the emulation. This time you’ll see Bochs boot into DOS. Use fdisk to create partitions and format to format them.

After you have formatted your disk, you need to re-edit your .bochsrc. Go to the disk section and comment out the ata0-slave line you added earlier. In its place add this line:

ata0-slave: type=cdrom, path=/dev/hdb, status=inserted

You can find the path to your CD-ROM drive from the /etc/fstab file.

Installing Windows

Now that your disk is partitioned it’s time to install an operating system on it. I installed a licensed copy of Windows 98 Second Edition.

Put the CD in the drive. Start bochs. Edit the Disk options to boot from the CD. Start the emulation. Windows will scan the disk first and then you’ll be taken to the GUI installation. Once you are done, start Bochs by pressing Enter on the main menu. Voila! There’s Windows right on your Linux desktop.

Mayank Sharma is a freelance technology writer and FLOSS migration consultant in New Delhi, India.