2 # support for GRUB version 2
4 error
=0; trap 'error=$(($?>$error?$?:$error))' ERR
# save maximum error code
9 # do not set up grub during dirinstall
10 if [ "$FAI_ACTION" = "dirinstall" ] ; then
13 # during softupdate use this file
14 [ -r $LOGDIR/disk_var.sh
] && .
$LOGDIR/disk_var.sh
16 if [ -z "$BOOT_DEVICE" ]; then
20 # disable os-prober because of #802717
21 ainsl
/etc
/default
/grub
'GRUB_DISABLE_OS_PROBER=true'
23 # skip the rest, if not an initial installation
24 if [ $FAI_ACTION != "install" ]; then
29 get_stable_devname
() {
35 # prefer SCSI over ATA over WWN over path
38 for i
in $
($ROOTCMD udevadm info
-r --query=symlink
"$_DEV"); do
39 if [[ "$i" =~
/by-id
/scsi
]]; then
41 elif [[ "$i" =~
/by-id
/ata
]]; then
43 elif [[ "$i" =~
/by-id
/wwn
]]; then
51 # handle /boot in lvm-on-md
52 _bdev
=$
(readlink
-f $BOOT_DEVICE)
53 if [ "${_bdev%%-*}" = "/dev/dm" ]; then
54 BOOT_DEVICE
=$
( lvs
--noheadings -o devices
$BOOT_DEVICE |
sed -e 's/^*\([^(]*\)(.*$/\1/' )
57 # Check if RAID is used for the boot device
58 if [[ $BOOT_DEVICE =~
'/dev/md' ]]; then
59 GROOT
=$
($ROOTCMD grub-probe
-tdrive -d $BOOT_DEVICE)
60 raiddev
=${BOOT_DEVICE#/dev/}
61 # install grub on all members of RAID
62 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
63 pdevice
=$
(get_stable_devname
/dev
/$device)
64 if [ -z "$pdevice" ]; then
65 # if we cannot find a persistent name (for e.g. in a VM) use old name
66 pdevice
="/dev/$device"
68 mbrdevices
+="$pdevice, "
69 echo Installing grub on
/dev
/$device = $pdevice
70 $ROOTCMD grub-install
--no-floppy "/dev/$device"
73 mbrdevices
=${mbrdevices%, }
75 for dev
in $BOOT_DEVICE; do
76 mbrdev
=$
(get_stable_devname
$dev)
77 if [ -z "$mbrdevices" ]; then
78 # if we cannot find a persistent name (for e.g. in a VM) use old name
81 echo "Installing grub on $dev = $mbrdev"
82 $ROOTCMD grub-install
--no-floppy "$mbrdev"
85 mbrdevices
=${mbrdevices%, }
88 echo "grub-pc grub-pc/install_devices multiselect $mbrdevices" |
$ROOTCMD debconf-set-selections
89 $ROOTCMD dpkg-reconfigure grub-pc