update to db59a1a2dd 2019-03-07
[automated-distro-installer] / fai / config / scripts / GRUB_EFI / 10-setup
1 #! /bin/bash
2 # support for GRUB version 2
3
4 error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
5
6 # This script assumes that the disk has a GPT partition table and
7 # that the extended system partition (ESP) is mounted on /boot/efi.
8 # When building a disk image, we don't change the NVRAM to point at
9 # the boot image we made available, because the disk image is likely
10 # not installed on the current system. As a result, we force
11 # installation into the removable media paths as well as the standard
12 # debian path.
13
14 set -a
15
16 # do not set up grub during dirinstall
17 if [ "$FAI_ACTION" = "dirinstall" ] ; then
18 exit 0
19 fi
20 # during softupdate use this file
21 [ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh
22
23 if [ -z "$BOOT_DEVICE" ]; then
24 exit 189
25 fi
26
27 # disable os-prober because of #788062
28 ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'
29
30 # skip the rest, if not an initial installation
31 if [ $FAI_ACTION != "install" ]; then
32 $ROOTCMD update-grub
33 exit $error
34 fi
35
36 GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
37
38 # handle /boot in lvm-on-md
39 _bdev=$(readlink -f $BOOT_DEVICE)
40 if [ "${_bdev%%-*}" = "/dev/dm" ]; then
41 BOOT_DEVICE=$( lvs --noheadings -o devices $BOOT_DEVICE | sed -e 's/^*\([^(]*\)(.*$/\1/' )
42 fi
43
44 # Check if RAID is used for the boot device
45 if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
46 raiddev=${BOOT_DEVICE#/dev/}
47 # install grub on all members of RAID
48 for device in `LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; print }' /proc/mdstat`; do
49 echo Install grub on /dev/$device
50 $ROOTCMD grub-install --no-floppy --force-extra-removable "/dev/$device"
51 done
52
53 elif [[ $BOOT_DEVICE =~ '/dev/loop' ]]; then
54 # do not update vmram when using a loop device
55 $ROOTCMD grub-install --no-floppy --force-extra-removable --modules=part_gpt --no-nvram $BOOT_DEVICE
56 if [ $? -eq 0 ]; then
57 echo "Grub installed on hostdisk $BOOT_DEVICE"
58 fi
59
60 else
61 $ROOTCMD grub-install --no-floppy --modules=part_gpt "$GROOT"
62 if [ $? -eq 0 ]; then
63 echo "Grub installed on $BOOT_DEVICE = $GROOT"
64 fi
65 fi
66 $ROOTCMD update-grub
67
68 exit $error