tomsimagetips



A few tips on how to deal with image files:
* what is an image file
* how to make an image file
* how to put an image file on disc
* how to boot the disc
* how to shutdown
* how to run the image file with bochs or qemu
* how to access your bios settings
* hardware requirements for running the image files
* software requirements for developing my own image files


What is an image file ?
**************************
An image file is executable code with direct hardware access.
An image file may have an extension of img. 
The file is usually associated with small hobby operating systems.  
The image file contains the operating system, kernel and drivers 
and applications all in one file. 

The image file interacts with your computer hardware directly. 
This means that your computer hardware must match exactly the 
capabilities of the image file.  Also you can not run the image 
file from Linux or Windows. Instead you must copy the image file 
to a disc and boot the disc.



How do I make an image file ?
*********************************
To build one of my image file projects on Linux, just cd to the 
top level directory where the makefile is located and type "make". 
You must have the GNU "make" utility and NASM assembler installed.
Or you can just build the image file in 4 steps using NASM:

	nasm -f bin krn/boot1.s
    nasm -f bin krn/boot2.s
	nasm -f bin application.s
	nasm -f bin build.s -o tictactoe.img



How do I get the image file onto a floppy disc ?
*************************************************
On Linux use the program "dd" to copy the image file to disc. 
Do not mount the disc first. Insert a blank floppy into the fd0 
drive then issue this command: 

	dd if=myimagefile.img of=/dev/fd0

Note that the filesystem on the disc is destroyed. You will not 
be able to mount or view any files on the disc (no matter).

Or you can also use "cp":

	cp myimagefile.img /dev/fd0

On Windows you can use the program "RawWrite" to write the image 
file to floppy.



How do I get the image file onto a cdrom ?
*****************************************
If your computer is of a modern vintage, you may not have a 
floppy drive at all. Well you can instead make a boot cd.  My 
1998 vintage computer can boot from floppy or cd. My Dell 
desktop at work does not have a floppy drive. Booting from cd
is of course preferred because the drive read speed is several 
times faster than a floppy.

This instructions are for linux users who have the commandline
tools "mkisofs" and "cdrecord" installed.

See instructions above for how to make an image file.
Uncomment the following line in the file "build.s":

	times 1474560 - ($-$$) db 0

It is necessary to generate an image file for cdrom that is
exactly the full size of a floppy disc (1470560 bytes).


Once you have a 1474560 byte size image file, the next step is
to generate an "iso" file. Read up on "man mkisofs" and especially 
the -b option which allows for making the "El Torito" boot cd.

 	mkisofs -b myimagefile.img -R -o file.iso /home/tom/myimagefile.img
 
 
Now use the commandline tool "cdrecord" to burn the file.iso to disc:

	sudo cdrecord -v -tao speed=8  dev=/dev/hdd  file.iso


If you are using CD-RW discs first blank the disc:
	sudo cdrecord -v blank=fast speed=8  dev=/dev/hdd


If all this seems like too much work, the top level directory may
contain a script called "makebootcd" to automate the process.

Windows users may be able to use a program like "Nero" to make a 
bootable cd. I have not tested this.



How do I get the disc image on a usb pendrive ?
************************************************
Sorry but my computer is too old and the bios does not support 
booting from a pen drive. 

On linux you can use the program "dd" to copy to/from the pen drive.

"dd if=/dev/sda of=temp bs=512 count=9" will copy the first 9 blocks/sectors from the pen drive to local file named "temp".

Similarily "dd if=ddusb.img of=/dev/sda" will copy the ddusb.img file to the pen drive starting at lba=0. Note linux requires sudo or root privaledge to do this because if you type /dev/hda by mistake you will copy to the hard drive instead of the pen drive and then ....:(




So how do you boot a disc image ?
************************************
First you must insert the disc into the drive when the computer 
off. With a floppy disc this is easy. With a cdrom disc you cant 
normally push the button to get the door open without power. In 
this case just take a paper clip and bend it straight and insert 
it into the little hole in the front of you cd drive and push 
gently until the door pops open. If you happen to be running your 
favorite operating system (Linux) and want to run the cd image 
just insert the bootcd, and reboot your computer.

Note also that some computers will not automatically boot from 
inserted media.  My Gateway tower at home, on startup will first 
check for a floppy to boot then it checks for a cd to boot then 
lastly if no floppy or cd is found it will boot from the hard drive.

My Dell tower at work is differant. First there is no floppy and 
it will not boot from a cd unless you press F12 during the boot 
process. This will suspend the process and give you a menu to 
select boot from cd or boot from hard drive.

Some computers may only boot well from the first boot drive
listed in the bios. So you may have to go into the bios and if 
you want to boot from floppy make this the first boot drive.



So how do I shutdown ?
***********************
There is no software to control Advanced Power Management. 
All the software is loaded from floppy/cd immediately on startup 
so you can remove the disc any time and just push your computer 
power button to shutdown.



To run your img file with an emulator
********************************************
Bochs and Qemu are swiss army knife programs that can run just 
about any operating system or bootable image file because they 
emulate the cpu instructions directly.  

Bochs:
First edit your bochsrc which is your startup/config file. Locate 
this file in the same directory where your img file is located. 
The file may be called bochsrc with no leading period.  Just cd 
to the directory where your img file is located and type "bochs" 
to run it. Toggle the Scroll Lock key for a full screen window. 
Hit Alt-F4 to close a window. Your img file mouse driver will be 
active immediately. To toggle the mouse driver between yours and 
the Xwindow mouse use Ctrl+Alt+MiddleMouseBut.

Qemu:
You will see slight improvements in speed over bochs without
the accelerator package. Also fullscreen mode works. Download and 
unpack the Linux package in your root directory. To run a bootable 
floppy image from the commandline: 
	"qemu  -no-kqemu -boot a -fda tictactoe.img"
	-full-screen (Ctrl+Alt+f exit to window mode)
	-snapshot    (write to tmp files instead)

Clicking in the window will activate your img file mouse driver.
Ctrl+Alt will return the mouse to the qemu Xwindow for closing.




How do you access the bios setting ?
***************************************
You bios setting may need modification for booting a disc.
How to access the bios settings will depend on your computer. 
Read your boot messages or just use trial and error.

On my Gateway at home, poll the F1 key shortly after startup. 

On a Dell at work you poll the F2 key. 

Another computer I tested used the F2 key.

Poll means to press and release the key about once every second. 
Your bios will detect the key presses and suspend the boot 
process and give you access to the bios menu settings.




Hardware Requirements 
*********************
My image files have been found to work on:
	* Gateway P2 desktop circa 1998
	* Emachines P3 desktop circa 2000 
	* Dell P4 desktop 2006
	* Toshiba laptop circa 1998
	* CBS custom build P3 circa 1999

* processor: 
	32bit (x86) w/MMX (Pentium I or >)
* mouse: 
	ps/2 (6 pin round connector)
	3 button with wheel (pushing wheel is 3rd button)
	2 button without wheel is unsupported
	A USB mouse with usb2ps2 adapter may or may not work.
	Logitech mouse=yes, microsoft mouse=no
* keyboard: ps/2
	usb connector on end of chord unsupported
* video adapter: 
	SVGA, 800x600x8bpp color graphics, 80x25 text modes
* BIOS that is VESA VBE 2.0 or later
* floppy disc: 
	1.44MB,	512 bytes per sector, 18 sectors per cylinder
	80 cylinders/tracks, 2 heads
* usb controller: UHCI Universal Host Controller
	



Development tools
*****************
If you want to develop your own image files.

* Linux host OS
* NASM assembler
* make: to execute the makefile 
* bochs or qemu emulator to test img b4 real hdwre
* dd or cp: to copy the image to floppy disc 
* mkisofs & cdrecord: to make a bootable cd
* a couple old computers laying around for testing
* a cd burner




Enjoy your image file.
Tom Timmermann
December 2007
www.ticon.net/~tatimmer/linux.html
