Towards GNU/MINIX - Bootloader

 

GNU/MINIX = GNU Tools with MINIX kernel

Repackage MINIX 3.3 kernel to boot with GRUB 2.06

MINIX CD has three partitions - boot, ramdisk image and usr filesystem image. It uses NetBSD bootloader and userland tools.

$ sudo sfdisk -l minix.iso 
Disk minix.iso: 577.53 MiB, 605581312 bytes, 1182776 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start     End Sectors   Size Id Type
minix.iso1          0   12287   12288     6M 81 Minix / old Linux
minix.iso2      12288   82087   69800  34.1M 81 Minix / old Linux
minix.iso3      82088 1182775 1100688 537.4M 81 Minix / old Linux
 


Extract files required for booting from boot partition by mounting it and copy the files to isodir.

$ sudo mount minix.iso /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
$ ls /mnt
boot      mod01_ds  mod04_sched   mod07_tty  mod10_pfs   version.txt
boot.cfg  mod02_rs  mod05_vfs     mod08_mfs  mod11_init
kernel    mod03_pm  mod06_memory  mod09_vm   readme.txt
$ mkdir isodir
$ cp /mnt/* isodir/
$ sudo umount /mnt
 


Extract RAM and filesystem images using dd.

dd if=minix.iso of=cd2.img skip=12288 bs=512 count=69800
dd if=minix.iso of=cd3.img skip=82088 bs=512 count=1100688
 


We need GRUB El Torito image to boot from CD. You can create one using grub-mkimage.

$ grub-mkimage -v -p /boot/grub -O i386-pc-eltorito -o core.img biosdisk iso9660
 


Create a text file grub.cfg .

insmod part_msdos

menuentry "GNU MINIX 3" {

    multiboot /kernel bootcd=1 cdproberoot=1 rootdevname=ram disable=inet
    
    module /mod01_ds
    module /mod02_rs
    module /mod03_pm
    module /mod04_sched
    module /mod05_vfs
    module /mod06_memory
    module /mod07_tty
    module /mod08_mfs
    module /mod09_vm
    module /mod10_pfs
    module /mod11_init
}
 


Copy grub files to isodir

$ cp core.img isodir/boote

$ mkdir -p isodir/boot/grub/i386-pc
$ cp -t isodir/boot/grub/i386-pc /usr/lib/grub/i386-pc/*
$ cp grub.cfg isodir/boot/grub/
 


Generate the bootable ISO image. (Important: Volume id MINIX is required.)

$ cp /usr/lib/grub/i386-pc/boot.img .
 
$ xorriso -outdev myos.iso -blank as_needed \
    -volid MINIX \
    -map isodir / \
    -boot_image any bin_path=boote \
    -boot_image any partition_cyl_align=on \
    -boot_image any iso_mbr_part_type=0x81 \
    -boot_image any system_area=boot.img \
    -boot_image any emul_type=no_emulation \
    -boot_image any boot_info_table=on \
    -append_partition 2 0x81 cd2.img \
    -append_partition 3 0x81 cd3.img
 


Boot MINIX in QEMU. BIOS reads boot catalog (boot.cat) from CD and runs the GRUB El Torrito boot image listed there.

$ kvm -cdrom myos.iso
 
# Limit CPU if you want to monitor progress
$ cpulimit -l 2 -f -- kvm -cdrom myos.iso


 

Lessons learnt

  • Use mkisofs -l option if filename is longer than 8 characters.
  • Use sfdisk for scripting partition operations.
  • If you are installing GRUB2 on a disk image file, you MUST provide a /boot/grub/device.map file. Otherwise, GRUB will default to host machine partition settings which might not be what you want. Also, it's safer to provide appropriate --target (usually --target=i386-pc) option instead of skipping it.
 

References






Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

HTML Renderer (Emacs)

Mozilla Readability in GNU Emacs