update to 72d79e141d3aaf430bb44f6036a2980f3f5865bd
[automated-distro-installer] / fai / config / scripts / GRUB_PC / 10-setup
index cbff2d84b606f876be230e092bcdeaac8d91aa2a..270b356b3f372b3eb8c386c7c3c049b56a7d0fec 100755 (executable)
@@ -16,7 +16,7 @@ if [ -z "$BOOT_DEVICE" ]; then
     exit 189
 fi
 
-# disable os-prober because of #788062
+# disable os-prober because of #802717
 ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'
 
 # skip the rest, if not an initial installation
@@ -25,7 +25,27 @@ if [ $FAI_ACTION != "install" ]; then
     exit $error
 fi
 
-GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
+get_stable_devname() {
+
+    local _DEV="$1"
+    local i
+    declare -a _RES
+
+    # prefer SCSI over ATA over WWN over path
+    # do not use by-path
+
+    for i in $($ROOTCMD udevadm info -r --query=symlink "$_DEV"); do
+        if [[ "$i" =~ /by-id/scsi ]]; then
+            _RES[10]="$i"
+        elif [[ "$i" =~ /by-id/ata ]]; then
+            _RES[20]="$i"
+        elif [[ "$i" =~ /by-id/wwn ]]; then
+            _RES[99]="$i"
+        fi
+    done
+
+    echo "${_RES[@]::1}"
+}
 
 # handle /boot in lvm-on-md
 _bdev=$(readlink -f $BOOT_DEVICE)
@@ -38,15 +58,27 @@ if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
     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
-       echo Install grub on /dev/$device
+       pdevice=$(get_stable_devname /dev/$device)
+       if [ -z "$pdevice" ]; then
+           # if we cannot find a persistent name (for e.g. in a VM) use old name
+           pdevice="/dev/$device"
+       fi
+       mbrdevices+="$pdevice, "
+       echo Installing grub on /dev/$device = $pdevice
        $ROOTCMD grub-install --no-floppy "/dev/$device"
     done
+    # remove last ,
+    mbrdevices=${mbrdevices%, }
 else
-    $ROOTCMD grub-install --no-floppy "$GROOT"
-    if [ $? -eq 0 ]; then
-        echo "Grub installed on $BOOT_DEVICE = $GROOT"
+    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
     fi
+    echo "Installing grub on $BOOT_DEVICE = $mbrdevices"
+    $ROOTCMD grub-install --no-floppy "$mbrdevices"
 fi
-$ROOTCMD update-grub
 
+echo "grub-pc grub-pc/install_devices multiselect $mbrdevices" | $ROOTCMD debconf-set-selections
+$ROOTCMD dpkg-reconfigure grub-pc
 exit $error