Skip to content

Instantly share code, notes, and snippets.

@clojens
Last active August 29, 2015 14:11
Show Gist options
  • Save clojens/a7030919ad2b7f7e2f5e to your computer and use it in GitHub Desktop.
Save clojens/a7030919ad2b7f7e2f5e to your computer and use it in GitHub Desktop.
#!/bin/bash
size_in_mib=32
bytes=$((2 ** 20 * $size_in_mib))
sectors=$(($bytes / 512))
heads=16
cylinders=$(($sectors / $heads / 63))
dd if=/dev/zero of=baremetal.img bs=512 count=$sectors
dd if=fat16mbr.bin of=baremetal.img conv=notrunc
losetup /dev/loop0 baremetal.img
sfdisk -D -H $heads -C $cylinders -S 63 /dev/loop0 <<EOF
,,6,*
EOF
blockdev --rereadpt /dev/loop0
mkdosfs -F 16 /dev/loop0p1
if [ ! -e baremetal ]; then mkdir baremetal; fi
mount -t vfat /dev/loop0p1 baremetal
cp -v pure64.sys kernel64.sys baremetal
sync
umount baremetal
losetup -d /dev/loop0
dd if=boot16b.bin of=baremetal.img conv=notrunc bs=1 seek=32318 skip=62
if [ -e baremetal.vdi ]; then
rm -i baremetal.vdi
fi
if [ ! -e baremetal.vdi ]; then
VBoxManage convertdd baremetal.img baremetal.vdi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment