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