This was contributed by Greg Alexander in October 2001 and updated by Volker Ruppert in October 2013.
What you need:
An executable version of Bochs. See Downloading Bochs and Compiling Bochs.
The bximage program, included with Bochs.
A FreeDOS boot disk, or a boot disk from another OS capable of producing DOS partitions (e.g. a Linux install disk).
(Optional) mtools, a program for manipulating DOS disks/images.
Option 1: Using the Unix dd utility:
You will need to know the geometry of the disk you want to create. You have to compute the disk sector count:
Sectors = Cylinders * Heads * SectorsPerTrack
Use the dd command to create your file:
dd if=/dev/zero of=teaching.img bs=512 count=sectors(replace "sectors" with the number you computed at the previous step).
When you'll update your configuration file, please fill in the same cylinders, heads and sector per track values.
Option 2: Run bximage to create a disk image file. You will be greeted with the following prompt:
======================================================================== bximage Disk Image Creation / Conversion / Resize and Commit Tool for Bochs $ID: bximage.cc 11906 2013-10-23 08:35:21Z vruppert $ ======================================================================== 1. Create new floppy or hard disk image 2. Convert hard disk image to other format (mode) 3. Resize hard disk image 4. Commit 'undoable' redolog to base image 0. Quit Please choose one [0]
Since we want to create a new image, we have to type '1' and then Enter.
Do you want to create a floppy disk image or a hard disk image? Please type hd or fd. [hd]
Since we are creating a hard disk image, accept the default of hd by pressing Enter or typing 'hd' and pressing Enter. Next, bximage will ask for the type of hd to create:
What kind of image should I create? Please type flat, sparse, growing or vpc. [flat]
We want to create a simple flat image, so accept the default by pressing Enter. Then, bximage will ask for the size of the disk image you want to create, in Megabytes:
Enter the hard disk size in megabytes, between 1 and 8257535 [10]
Enter the size of the hard disk you want to create, and press Enter. Then bximage will ask you for a filename to use for the file it is creating.
What should be the name of the image? [c.img]
At this point, type in the filename you want to use for the image. The default of "c.img" is appropriate if this will be your only hard disk image. After you have typed in the name of the filename you want to use, press Enter. Bximage will tell you it is writing the disk and then it will show you a line that should be added to your bochsrc when you want to use this disk image. I named my 10 Megabyte image "teaching.img" and the output of bximage looked like this:
[c.img] teaching.img Creating hard disk image 'c.img' with CHS=20/16/63
The following line should appear in your bochsrc:
ata0-master: type=disk, path="teaching.img", mode=flat, cylinders=20, heads=16, spt=63
At this point, a file called "teaching.img" was created in my current directory and is ready to be used as an image file for a Bochs session.
Tip: You may want to name your image teaching_20-16-63.img so that you always know the values to use for CHS.
Option 1: Using FreeDOS (Advantage: Creates a MBR on the partition.)
First, you need to edit the bochsrc file that Bochs uses for configuration information (see Section 5.2). Open bochsrc with a text editor. Remove all lines in the file which start with "ata0-master:". Add the "ata0-master:" line that was displayed when you ran bximage to bochsrc at the same place where you removed the old "ata0-master:" lines from.
Also, you need to download or create a FreeDOS (or DOS, or Windows, or Linux) disk image. Modify the "floppya:" line in your bochsrc to point at the downloaded FreeDOS floppy image and change its status to "status=inserted".
Save and close your bochsrc. Now run Bochs (see Chapter 5).
Use the standard FreeDOS commands fdisk and format to format your hard drive image. You must make the image bootable to be able to boot without a floppy disk. However, creating a bootable disk image is best done with a boot disk from the OS you intend to install on the image.
Option 2: Using mtools (Disadvantage: Cannot create bootable images without a MBR image.)
Use a text editor to add the following line to the file ~/.mtoolsrc:
drive c: file="path/filename.img" partition=1
Save and close .mtoolsrc. Next, execute the following commands to create a partition table for the drive image:
mpartition -I -s spt -t cyl -h heads c: mpartition -cpv -s spt -t cyl -h heads c:
For example, for my 10 meg drive, I used:
mpartition -I -s 63 -t 20 -h 16 c: mpartition -cpv -s 63 -t 20 -h 16 c:
Next, format the partition you just created using the mformat command:
mformat c:
And you now have a formatted disk image containing a single DOS partition.
Note: The mpartition command doesn't handle images larger than 1024 cylinders properly. The partition size reported by fdisk is okay, but mformat reports only 504 MB (tested with mtools 3.9.9).