Use UUIDs in /boot/grub/grub.cfg for VM builds rather than hardcoding /dev/sda
authorPatrick Schleizer <adrelanos@riseup.net>
Mon, 13 Oct 2014 11:05:01 +0000 (13:05 +0200)
committerMichael Prokop <mika@grml.org>
Mon, 13 Oct 2014 19:05:18 +0000 (21:05 +0200)
This allows booting the image in KVM as either sda or vda without
requiring any manual changes in /boot/grub/grub.cfg.  Use
FIXED_DISK_IDENTIFIERS="yes" for VM builds by default.

Patch rebased by Michael Prokop <mika@grml.org>
Fixes #29 @ github

config
grml-debootstrap

diff --git a/config b/config
index 670f608..665353b 100644 (file)
--- a/config
+++ b/config
 
 # Use fixed disk identifiers for Virtual Machine builds.
 # Useful for reproducible builds.
 
 # Use fixed disk identifiers for Virtual Machine builds.
 # Useful for reproducible builds.
-# Default: 'no'
-# FIXED_DISK_IDENTIFIERS='yes'
+# Default: 'yes'
+# FIXED_DISK_IDENTIFIERS='no'
 
 # Disk identifier when using FIXED_DISK_IDENTIFIERS='yes'.
 # Default: '26ada0c0-1165-4098-884d-aafd2220c2c6'
 
 # Disk identifier when using FIXED_DISK_IDENTIFIERS='yes'.
 # Default: '26ada0c0-1165-4098-884d-aafd2220c2c6'
index 007d0be..cd259fc 100755 (executable)
@@ -23,7 +23,7 @@ MNTPOINT="/mnt/debootstrap.$$"
 [ -n "$DISK_IDENTIFIER" ] || DISK_IDENTIFIER='26ada0c0-1165-4098-884d-aafd2220c2c6'
 [ -n "$EXTRAPACKAGES" ] || EXTRAPACKAGES='yes'
 [ -n "$FALLBACK_MIRROR" ] || FALLBACK_MIRROR='http://http.debian.net/debian'
 [ -n "$DISK_IDENTIFIER" ] || DISK_IDENTIFIER='26ada0c0-1165-4098-884d-aafd2220c2c6'
 [ -n "$EXTRAPACKAGES" ] || EXTRAPACKAGES='yes'
 [ -n "$FALLBACK_MIRROR" ] || FALLBACK_MIRROR='http://http.debian.net/debian'
-[ -n "$FIXED_DISK_IDENTIFIERS" ] || FIXED_DISK_IDENTIFIERS="no"
+[ -n "$FIXED_DISK_IDENTIFIERS" ] || FIXED_DISK_IDENTIFIERS="yes"
 [ -n "$FORCE" ] || FORCE=''
 [ -n "$HOSTNAME" ] || HOSTNAME='grml'
 [ -n "$INITRD" ] || INITRD='yes'
 [ -n "$FORCE" ] || FORCE=''
 [ -n "$HOSTNAME" ] || HOSTNAME='grml'
 [ -n "$INITRD" ] || INITRD='yes'
@@ -1104,9 +1104,12 @@ finalize_vm() {
   umount "${MNTPOINT}"/dev
 
   einfo "Adjusting grub.cfg for successful boot sequence."
   umount "${MNTPOINT}"/dev
 
   einfo "Adjusting grub.cfg for successful boot sequence."
-  # ugly but needed to boot grub acordingly
-  sed -i "s;set root=.*;set root='(hd0,msdos1)';" "${MNTPOINT}"/boot/grub/grub.cfg
-  sed -i "s;root=[^ ]\+;root=/dev/sda1;" "${MNTPOINT}"/boot/grub/grub.cfg
+  if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ]; then
+    sed -i "s;root=[^ ]\+;root=UUID=$DISK_IDENTIFIER;" /boot/grub/grub.cfg
+  else
+    sed -i "s;set root=.*;set root='(hd0,msdos1)';" "${MNTPOINT}"/boot/grub/grub.cfg
+    sed -i "s;root=[^ ]\+;root=/dev/sda1;" "${MNTPOINT}"/boot/grub/grub.cfg
+  fi
 
   umount "${MNTPOINT}"
   kpartx -d "${ORIG_TARGET}" >/dev/null
 
   umount "${MNTPOINT}"
   kpartx -d "${ORIG_TARGET}" >/dev/null