Skip to content

Instantly share code, notes, and snippets.

@ericdwhite
Created August 17, 2011 21:24
Show Gist options
  • Select an option

  • Save ericdwhite/1152678 to your computer and use it in GitHub Desktop.

Select an option

Save ericdwhite/1152678 to your computer and use it in GitHub Desktop.
Writing the grub MBR from within the VM
THIS IS A WORK AROUND
Installing Grub manually from within the Image:
Steps:
0) Comment out the grub --device-map=/dev/null (Until the end of EOF)
This is the part that is executed from host.
diff --git a/06-install-grub.bash b/06-install-grub.bash
index f052c01..4f76aee 100755
--- a/06-install-grub.bash
+++ b/06-install-grub.bash
@@ -50,12 +50,12 @@ EOF' || die "UBE060" "Failed to create /boot/grub/menu.lst"
fi
linfo "Installing the MBR to: ${DISK_IMAGE}"
- grub --device-map=/dev/null <<EOF
-device (hd0) ${DISK_IMAGE}
-root (hd0,0)
-setup (hd0)
-quit
-EOF
+# grub --device-map=/dev/null <<EOF
+#device (hd0) ${DISK_IMAGE}
+#root (hd0,0)
+#setup (hd0)
+#quit
+#EOF
if [ $? -ne 0 ]; then
die "UBE061" "Failed to write MBR."
fi
You still need to run step 6 with the above commented out.
1) Use 12-chroot.bash to get into the VM
2) Make sure that the other parts of step 6 executed properly (e.g. that there are stages)
# ls -l /boot/grub
total 132
-rw-r--r-- 1 root root 8344 2011-08-17 21:12 e2fs_stage1_5
-rw-r--r-- 1 root root 1024 2011-08-17 20:41 grubenv
-rw-r--r-- 1 root root 150 2011-08-17 21:12 menu.lst
-rw-r--r-- 1 root root 512 2011-08-17 21:12 stage1
-rw-r--r-- 1 root root 121188 2011-08-17 21:12 stage2
3) Execute grub from within the VM image
BE CAREFUL HERE OR YOU MIGHT WRITE THE WRONG MBR (e.g. the hosts).
'losetup -a' can be used to find the loopback device for the VM. These scripts use /dev/loop5 by default. This is why it's /dev/loop5 in the example.
From within the chrooted VM
# grub --device-map=/dev/null <<EOF
> device (hd0) /dev/loop5
> root (hd0,0)
> setup (hd0)
> quit
> EOF
#
# exit
Exit the chroot.
4) Try to launch the VM image using 13-launch-kvm.bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment