Sunday, November 9, 2014

Creating a bootable HD image using grub

It is nicely documented here - http://tomermargalit.wordpress.com/tag/create-grub2-bootable-image-over-loopback-device/

#!/bin/sh -x

dd if=/dev/zero of=out.img seek=8MB count=1k bs=1


outlo=`sudo losetup -f --show out.img`


parted -s ${outlo} mklabel msdos

parted  ${outlo} mkpart primary ext2 32k 100% -a minimal

parted ${outlo} set 1 boot on

partx -a ${outlo}


mke2fs ${outlo}p1

mkdir -p /mnt/out

mount -t ext2 ${outlo}p1 /mnt/out

grub-install --boot-directory=/mnt/out/boot/ --modules="ext2 part_msdos" ${outlo}

#####


umount /mnt/out
partx -d ${outlo}p1
losetup -d ${outlo}


No comments:

Post a Comment