Saturday, July 10, 2010

kernel develop from zero

from:
http://www.julienlecomte.net/blog/2007/07/3/
http://www.omninerd.com/articles/Installing_GRUB_on_a_Hard_Disk_Image_File
http://kbarr.net/bochs
http://thestarman.pcministry.com/asm/mbr/PartTables.htm
http://members.iinet.net/~herman546/p20/GRUB2%20Bash%20Commands.html

make a fire ready disk image:
1. get a disk image file. There are two ways to get a empty disk image.
One is:
$ dd if=/dev/zero of=disk.img count=10080
The other one if Bochs is installed:
$ bximage: hd, flat, 1500, c.img
cyl=3047
heads=16
sectors per track=63
total sectors=3071376
total size=1499.70 megabytes
2. After having a disk image, we need partition table in it.
$ fdisk disk.img

x -> Extra functionality
c 10 -> 10 cylinders
h 16 -> 16 heads
s 63 -> 63 sectors per track
r -> Return to main menu
n -> Create a new partition
p -> Primary
1 -> Partition #1
1 -> First cylinder
10 -> Last cylinder
a -> Set bootable flag
1 -> Partition number
w -> Write partition to disk
3. to setup the loop back device.
first to find where the first partition start:
$ fdisk -l -u disk.img

Device Boot Start End Blocks Id System
disk.img1 * 63 10079 5008+ 83 Linux

Given one block is 512 bytes size.
Then, 63 * 512 = 32256
$ losetup -o 32256 /dev/loop0 disk.img
4. format the disk image
$ mkfs.ext2 /dev/loop0
5. mount the disk
$ mount -o loop /dev/loop0 /mnt
6. install GRUB
7. umount disk
$ umount /mnt
8. Detach the loopback device:
$ losetup -d /dev/loop0
9. Finish up the GRUB installation:
$ grub --device-map=/dev/null

device (hd0) disk.img
geometry (hd0) 10 16 63
root (hd0,0)
setup (hd0)
quit
10. Setup your .bochsrc file in the same directory as your disk image:
megs: 32
romimage: file=/usr/local/share/bochs/BIOS-bochs-latest, address=0xf0000
vgaromimage: file=/usr/local/share/bochs/VGABIOS-elpin-2.40
ata0-master: type=disk, path="disk.img", mode=flat, cylinders=10, heads=16, spt=63
cpu: count=1, ips=15000000
mouse: enabled=0
log: out.bochs
boot: disk

No comments: