Upload
finnbarr-p-murphy
View
223
Download
0
Embed Size (px)
Citation preview
8/7/2019 Building a Bootable GRUB Legacy Image for QEMU
1/5
Building a Bootable GRUB Legacy Image for QEMU
Building a Bootable GRUB Legacy
Image for QEMUFinnbarr P. Murphy
Recently, as a moderator on a Unix and GNU/Linux-related forum, I assisted a member who was
having a problem creating a bootable image for use with QEMU. As a result of this experience, I
decided to write this post to demonstrate to others how easy the process is.
Without further ado, here is a simple Bash shell script to create a bootable image containing only
the GRUB Legacy boot loader which is bootable using QEMU.
#!/bin/bash
#
# Finnbarr P. Murphy 01/03/2011
#
# Create a bootable image containing just Legacy Grub
# and use QEMU to test boot it if requested
#
if (( $(id -u) != 0 ))
then
echo "ERROR: This script must be run as root" 1>&2
exit 1
fi
GRUBFILEDIR=/usr/share/grub/x86_64-redhat
IMAGE=myimage
LOOPDEV=$(/sbin/losetup -f)
dd if=/dev/zero of=${IMAGE}.img bs=512 count=2880
if [[ -d ${IMAGE} ]]
then
rm -rf ${IMAGE}
fi
mkdir -p ${IMAGE}/boot/grub
cp ${GRUBFILEDIR}/stage1 ${IMAGE}/boot/grub
cp ${GRUBFILEDIR}/stage2 ${IMAGE}/boot/grub
/sbin/losetup ${LOOPDEV} ${IMAGE}.img
/sbin/mke2fs ${LOOPDEV}
mount ${LOOPDEV} -o loop /mnt
chmod 777 /mnt
cp -aR ${IMAGE}/* /mntumount /mnt
cat