update to db59a1a2dd 2019-03-07
[automated-distro-installer] / fai / config / scripts / GRUB_PC / 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 set -a
7
8 # do not set up grub during dirinstall
9 if [ "$FAI_ACTION" = "dirinstall" ] ; then
10 exit 0
11 fi
12 # during softupdate use this file
13 [ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh
14
15 if [ -z "$BOOT_DEVICE" ]; then
16 exit 189
17 fi
18
19 # disable os-prober because of #788062
20 ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'
21
22 # skip the rest, if not an initial installation
23 if [ $FAI_ACTION != "install" ]; then
24 $ROOTCMD update-grub
25 exit $error
26 fi
27
28 GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
29
30 # handle /boot in lvm-on-md
31 _bdev=$(readlink -f $BOOT_DEVICE)
32 if [ "${_bdev%%-*}" = "/dev/dm" ]; then
33 BOOT_DEVICE=$( lvs --noheadings -o devices $BOOT_DEVICE | sed -e 's/^*\([^(]*\)(.*$/\1/' )
34 fi
35
36 # Check if RAID is used for the boot device
37 if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
38 raiddev=${BOOT_DEVICE#/dev/}
39 # install grub on all members of RAID
40 for device in `LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; print }' /proc/mdstat`; do
41 echo Install grub on /dev/$device
42 $ROOTCMD grub-install --no-floppy "/dev/$device"
43 done
44 else
45 $ROOTCMD grub-install --no-floppy "$GROOT"
46 if [ $? -eq 0 ]; then
47 echo "Grub installed on $BOOT_DEVICE = $GROOT"
48 fi
49 fi
50 $ROOTCMD update-grub
51
52 exit $error