bug fix
[automated-distro-installer] / fai / config / scripts / GRUB_PC / 10-setup
index 270b356b3f372b3eb8c386c7c3c049b56a7d0fec..7ea23fd34295565d806df14fb8bd27af5f9af84b 100755 (executable)
@@ -3,6 +3,12 @@
 
 error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
 
+set -x
+# do only execute for Debian and similar distros
+if ! ifclass DEBIAN ; then
+    exit 0
+fi
+
 set -a
 
 # do not set up grub during dirinstall
@@ -19,6 +25,11 @@ fi
 # disable os-prober because of #802717
 ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'
 
+# efivars may still be mounted from the host system during fai-diskimage
+if [ -d $target/sys/firmware/efi/efivars ]; then
+    umount $target/sys/firmware/efi/efivars
+fi
+
 # skip the rest, if not an initial installation
 if [ $FAI_ACTION != "install" ]; then
     $ROOTCMD update-grub
@@ -55,6 +66,7 @@ fi
 
 # Check if RAID is used for the boot device
 if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
+    GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
     raiddev=${BOOT_DEVICE#/dev/}
     # install grub on all members of RAID
     for device in $(LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; s/(nvme.+?)p/$1/g; print }' /proc/mdstat); do
@@ -70,13 +82,18 @@ if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
     # remove last ,
     mbrdevices=${mbrdevices%, }
 else
-    mbrdevices=$(get_stable_devname $BOOT_DEVICE)
-    if [ -z "$mbrdevices" ]; then
-       # if we cannot find a persistent name (for e.g. in a VM) use old name
-       mbrdevices=$BOOT_DEVICE
+  for dev in $BOOT_DEVICE; do
+    mbrdev=$(get_stable_devname $dev)
+    if [ -z "$mbrdev" ]; then
+      # if we cannot find a persistent name (for e.g. in a VM) use old name
+      mbrdev="$dev"
     fi
-    echo "Installing grub on $BOOT_DEVICE = $mbrdevices"
-    $ROOTCMD grub-install --no-floppy "$mbrdevices"
+    mbrdevices+="$mbrdev, "
+    echo "Installing grub on $dev = $mbrdev"
+    $ROOTCMD grub-install --no-floppy "$mbrdev"
+  done
+  # remove trailing ,
+  mbrdevices=${mbrdevices%, }
 fi
 
 echo "grub-pc grub-pc/install_devices multiselect $mbrdevices" | $ROOTCMD debconf-set-selections