This is the first step that i learnt before two years when i learning OS. But inspite of seniors best effort to make us understand i think we understood only half. It was proved when we were trying to run bochs for our final year project. The task was to create the disk images and to install grub in the disk images to boot our kernel. We had a vague idea about the steps that we followed in our second year and finally figured out the right way and understood a lot. Some juniors were also asking us about how to run bochs for the first time. So thought of posting about it.
Creating disk images : The first step would be to create disk images. The utility available with bochs called as bximage can be used to reate disk images. Create a floppy disk image by specifying fd as the disk type and a hard disk image of size 10MB by specifying hd as the disk type while using bximage.
Partitioning the hard disk image : Then the harddisk should be partitioned. For this purpose we use some small linux distributions ike dlxlinux. Using bochs boot with dlxlinux image as the master disk nd the created disk image as the slave. Once dlxlinux is booted use fdisk to partition the slave disk as "fdisk /dev/hdb". Create a new partition and then create ext2 filesystem on the partition using the command mk2efs /dev/hdb1.
Copying the grub files into the disk image: After partitioning the disk image file we should copy the grub files into the image. To do this attach the image file as a loop device and then mount the loop device. These steps will require root previlege
losetup -o 32256 /dev/loop/0 diskimage
mount /dev/loop/0 /mnt/loop
cp /boot/ /mnt/loop/
cp kernel /mnt/loop/boot
Edit the menu.lst file to boot the kernel.
losetup -d /dev/loop/0
Installing grub in the disk image: After the grub files are copied the next step is to install grub on the hard disk image. This is where the floppy disk image we created earlier comes into use. Attach the floppy disk image as a loop device and use grub-floppy command tocreate bootable floppy disk image. The commands would look like
losetup /dev/loop/0 floppyimage
losetup -d /dev/loop/0
Once the boot floppy image is created edit the bochsrc file to boot from the floppy with our hard disk image as the master disk. Now bochs boots the floppy disk image and u get the grub command prompt. Once the grub command prompt is obtained follow the long established steps of root (hd0,0) and setup (hd0) to install grub on the harddisk image. Now u can test ur own kernel using bochs. Bochs reads its configuration setting from the file bochsrc. This is the file that instructs bochs about the master disk or slave disk or disk to boot etc.