2 # support for GRUB version 2
4 error
=0; trap 'error=$(($?>$error?$?:$error))' ERR
# save maximum error code
6 # do only execute for Debian and similar distros
7 if ! ifclass DEBIAN
; then
13 # do not set up grub during dirinstall
14 if [ "$FAI_ACTION" = "dirinstall" ] ; then
17 # during softupdate use this file
18 [ -r $LOGDIR/disk_var.sh
] && .
$LOGDIR/disk_var.sh
20 if [ -z "$BOOT_DEVICE" ]; then
24 # disable os-prober because of #802717
25 ainsl
/etc
/default
/grub
'GRUB_DISABLE_OS_PROBER=true'
27 # efivars may still be mounted from the host system during fai-diskimage
28 if [ -d $target/sys
/firmware
/efi
/efivars
]; then
29 umount
$target/sys
/firmware
/efi
/efivars
32 # skip the rest, if not an initial installation
33 if [ $FAI_ACTION != "install" ]; then
38 get_stable_devname
() {
44 # prefer SCSI over ATA over WWN over path
47 for i
in $
($ROOTCMD udevadm info
-r --query=symlink
"$_DEV"); do
48 if [[ "$i" =~
/by-id
/scsi
]]; then
50 elif [[ "$i" =~
/by-id
/ata
]]; then
52 elif [[ "$i" =~
/by-id
/wwn
]]; then
60 # handle /boot in lvm-on-md
61 _bdev
=$
(readlink
-f $BOOT_DEVICE)
62 if [ "${_bdev%%-*}" = "/dev/dm" ]; then
63 BOOT_DEVICE
=$
( lvs
--noheadings -o devices
$BOOT_DEVICE |
sed -e 's/^*\([^(]*\)(.*$/\1/' )
66 # Check if RAID is used for the boot device
67 if [[ $BOOT_DEVICE =~
'/dev/md' ]]; then
68 raiddev
=${BOOT_DEVICE#/dev/}
69 # install grub on all members of RAID
70 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
71 pdevice
=$
(get_stable_devname
/dev
/$device)
72 if [ -z "$pdevice" ]; then
73 # if we cannot find a persistent name (for e.g. in a VM) use old name
74 pdevice
="/dev/$device"
76 mbrdevices
+="$pdevice, "
77 echo Installing grub on
/dev
/$device = $pdevice
78 $ROOTCMD grub-install
--no-floppy "/dev/$device"
81 mbrdevices
=${mbrdevices%, }
83 mbrdevices
=$
(get_stable_devname
$BOOT_DEVICE)
84 if [ -z "$mbrdevices" ]; then
85 # if we cannot find a persistent name (for e.g. in a VM) use old name
86 mbrdevices
=$BOOT_DEVICE
88 echo "Installing grub on $BOOT_DEVICE = $mbrdevices"
89 $ROOTCMD grub-install
--no-floppy "$mbrdevices"
92 echo "grub-pc grub-pc/install_devices multiselect $mbrdevices" |
$ROOTCMD debconf-set-selections
93 $ROOTCMD dpkg-reconfigure grub-pc