various fixes, improve flidas
[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 -x
7 set -a
8
9 # do not set up grub during dirinstall
10 if [ "$FAI_ACTION" = "dirinstall" ] ; then
11 exit 0
12 fi
13 # during softupdate use this file
14 [ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh
15
16 if [ -z "$BOOT_DEVICE" ]; then
17 exit 189
18 fi
19
20 # disable os-prober because of #788062
21 ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'
22
23 # skip the rest, if not an initial installation
24 if [ $FAI_ACTION != "install" ]; then
25 $ROOTCMD update-grub
26 exit $error
27 fi
28
29 GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
30
31
32 # Check if RAID is used for the boot device
33 if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
34 GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
35 raiddev=${BOOT_DEVICE#/dev/}
36 # install grub on all members of RAID
37 for device in `LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; print }' /proc/mdstat`; do
38 echo Install grub on /dev/$device
39 $ROOTCMD grub-install --no-floppy "/dev/$device"
40 done
41
42 elif [[ $GROOT =~ 'hostdisk' ]]; then
43 for dev in $BOOT_DEVICE; do
44 $ROOTCMD grub-install --no-floppy --modules=part_msdos $dev
45 if [ $? -eq 0 ]; then
46 echo "Grub installed on hostdisk $BOOT_DEVICE"
47 fi
48 done
49 else
50 for dev in $BOOT_DEVICE; do
51 GROOT=$($ROOTCMD grub-probe -tdrive -d $dev)
52 $ROOTCMD grub-install --no-floppy "$GROOT"
53 if [ $? -eq 0 ]; then
54 echo "Grub installed on $dev = $GROOT"
55 fi
56 done
57 fi
58 $ROOTCMD update-grub
59
60 exit $error