Das Boot

How to Create Bootable Media


These are just some preliminary notes - still working on it .

To boot an operating system, the BIOS executes the "Master Boot Record" - a set of instructions at the beginning of a hard disk or an other bootable medium - outside any partitions that might be present on that medium. On of these instructions calls the "boot sector", another set of instructions on a (bootable) partition. The instructions in the boot sector will get the operating system started. It is possible to copy the MBR and the boot sector into a file, which you can then use as a backup (to restore MBR, boot sector and partition tables in case something's gone wrong). You can also use these files to create other bootable media such as diskettes, USB sticks, CD's, CD iso images, ...). In this tutorial, we will explore some techniques to create and use bootable media.

An other way of creating bootable media (such as CD's and USB Drives) is to 'emulate' a boot diskette. Most operating systems support the creation of boot diskettes, and these can be 'transferred' to other media. This is kind of a workaround in case a real boot CD doesn't work, or if you want to run an operating system of a CD in stead of a hard disk.

In the following examples, we'll be using Linux tools, so you need a working linux environment.

Creating a Windows 98 boot CD - emulating a Windows 98 boot floppy

Windows 98 Setup.exe requires a DOS environment, usually set up from a windows 98 setup disk. By integrating a windows 98 setup disk in a CD, you can create a bootable Windows 98 CD, possibly with a customized setup for unattended installations. Here's how.

Create a working directory, e.g. $HOME/remaster/win98bootcd.

		mkdir ~/remaster
		cd ~/remaster
		mkdir win98bootcd
	

Create content for the CD in this working directory (.../remaster/win98bootcd/win98setup). You can e.g. create a customized setup for an unattended installation, and copy the contents of the distribution point to ~/remaster/win98bootcd/. Think of .../remaster/win98bootcd as the root of the CD.

creating a boot image

The 'boot image' is what the CD will use to boot of. In this case, it's an image of a genuine Windows 98 Startup Disk, that you can create on a working Windows 98 system or that came with your installation disks / CD. The 'image' is a single file that contains the content of the diskette. Insert the diskette in the floppy drive and create an image :

	dd if=/dev/fd0 of=win98bootcd/w98setupdisk.img 
	

optionally : modify the boot image

Because we're emulating a floppy, the files in the boot image will appear to be on drive A:, while the rest of the contents of your "winbootcd" directory will end up on the CD. A Windows setup disk includes the necessary routines to load the CD driver and assign drive letters. You may want to edit the files in the floppy image, eg add a statement to the a:\autoexec.bat that calls %CDROM%\w98setup\setup.exe, so that setup starts automatically.

To edit a disk image, you can quite simply mount it to your filesystem :

	mkdir -p /mnt/img
	mount -t msdos -o loop remaster/win98bootcd/w98setupdisk.img  /mnt/img

	vim autoexec.bat
	umount /mnt/img
	

To auto-start windows 98 setup, you'd add something like this to the autoexec.bat - after the line where the CD drive gets its drive letter :

	cd %CDROM%
	CDROM%:\w98setup\setup.exe
	

Creating a CD

The remaster working directory now contains all files you need on the CD so you can create the bootable CD. This is done in 2 steps : first create an iso image (.iso file), then burn the iso image to a disk. To create the iso image, you use the mkisofs command, with -b to make it bootable, -J for Joliet (Microsoft file names), and a path to the files. Note that the floppy image needs to be inside the working directory for this to work : paths to boot images are relative to the 'content' folder in the mkisofs statement

		#create iso image with floppy boot emulation 
		##(man mkisofs for suitable command line options)

		mkisofs -o win98setup.iso -r -l -J -b w98setupdisk.img ./win98bootcd/
	

burn the CD image in _output/win98setup.iso to a disk using any suitable CD writing application - or just boot it in a Virtual Machine.

		#command line to burn a CD from an iso image
		cdrecord -v -eject dev=0,0 ./win98setup.iso
	

When booting from this CD, you'll find that it really emulates a floppy drive. You'll find a drive A: that contains the files that were on the original boot floppy, and a CD-drive (D: or whatever drive letter was available) that contains the rest of the files. To add or modify boot- and startup files, you need to modify w98setupdisk.img file (as shown earlier), not just add files to the CD. Of course, you can also add content to the CD - but that will only be available after the boot floppy has booted DOS and loaded drivers for the CD station.

Creating a minimal DOS Live CD - emulating a DOS or Windows 98 boot floppy

Just like you can emulate a Windows 98 boot floppy to initiate a Windows 98 setup, you can emulate a DOS or Windows 98 startup diskette to create a minimal DOS environment. To start, you'll need a DOS or Windows 98 startup disk that is bootable and contains at least

Modify config.sys and autoexec.bat as needed to load the CD driver and assign a drive letter to it. Include the CD drive letter in the path. If you use a Windows 98 startup disk, the config.sys and autoexec.bat already have statements to take care of this.

You'll also need a DOS\ or Windows\Command folder from an MS_DOS or Windows 9x system because this contains the "external" DOS commands. This can be added to the floppy, or to the CD itself. Set the path environment variable accordingly (A:\DOS or D:\DOS, ...) by editing the autoexec.bat inside the floppy image. It's also a good idea to create a RAM drive (eg as on the win98 startup disk) and let the TMP and TEMP variables point to the ramdrive - since a CD is not writable, programs that need to create temporary files need a place they can write to.

The procedure to create a boot CD is the same as for the windows 98 setup CD :

As MS-DOS does not require lots of configuration, it's fairly easy to create a MS-DOS bootable CD to do things like

Only for those applications that require modifications to the config.sys (eg to load drivers and 'Terminate and Stay Resident' (TRS) programs), you'll need a more complicated DOS configuration.

Creating a "no emulation" boot CD

In the previous exemples, the CD was made bootable by emulating a bootable floppy or hard disk. This has a few limitations, eg that you need a suitable floppy or hard disk to start from.

More modern applications prefer a no-emulation boot. When, for instance, you want to create a windows 2000 or XP boot CD and you base the boot on boot sectors from a DOS floppy or a hard disk, you have a so-called DOS-initiated setup, which will have trouble dealing with NTFS file systems. For such situations, it is better to create a "no emulation" boot CD.

Copying a MBR to a file

you can copy the MBR of a bootable medium to a file. Under linux, you can use the command 'dd'. You need to specify the bootable medium by its device name / alias, eg hda (IDE device : master on controller1 - usually a harddisk), hdc (IDE device : master on controller2 - this is often a CD-station), fd0 (1st floppy disk drive), etc.

Command syntax : copying the boot sector of a (Windows 98 boot) floppy to a file named win98floppy.mbr : get the first 512 bytes of the floppy - that's the boot record

	dd if=/dev/fd0 of=win98setupdisk.mbr bs=512 count=1
	

On Windows, download and use MKMBR.

next

related

Koen Noens
October 2006