Cleese and Disk Images


Previously I talked about setting up a toolchain to compile i386-elf binaries for hobby OS writing on Mac OS X.

The next step in getting Cleese development working on Mac OS X was working how to build disk images for VMware Fusion for a "hello world" kernel. I got about half way over the weekend, but Brian Rosner worked out the rest Monday night.

VMware can mount a normal disk image as a floppy but can't do the same for hard drives. Turns out, though, you can create floppy images larger than 1.44MB (although I don't know if there's an upper limit).

Here's the make target Brian came up with:

cleese.img: KERNEL.BIN hdiutil create -size 5M -fs "MS-DOS" -layout NONE cleese mv cleese.dmg cleese.img mkdir -p mnt mount_msdos -o nosync `hdid -nomount cleese.img` ./mnt cp -r boot KERNEL.BIN ./mnt umount -f ./mnt rm -r ./mnt

This creates a 5MB disk image, mounts it and copies the "boot" directory from GRUB and our kernel KERNEL.BIN on to the image.

This image isn't bootable by VMware yet. You need to boot off another floppy that has GRUB and is bootable but this is a one off operation. You can easily create a bootable GRUB disk with just

cat boot/grub/stage1 boot/grub/stage2 > grub.img

Once you've booted to the GRUB command line, you can switch to cleese.img as your floppy and type

setup (fd0)

and that will copy GRUB onto the boot sector. From that point on, cleese.img is all you need.

To avoid having to do that step every time KERNEL.BIN updates, I wrote an additional make target that just updates KERNEL.BIN on an existing image.

update-image: mkdir -p mnt mount_msdos -o nosync `hdid -nomount cleese.img` ./mnt cp KERNEL.BIN ./mnt umount -f ./mnt rm -r ./mnt

As a quick guide to what that's doing:

I'm not sure why the -o nosync is needed. Maybe it isn't.

In the original target, the -layout NONE option to hdiutil ensures no partition map is created for the drive.

The original post was in the categories: os_x cleese but I'm still in the process of migrating categories over.

The original post had 1 comment I'm in the process of migrating over.