Debian Codegraph @

examples/simple/scripts/GRUB_EFI/10-setup

raw
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 # do only execute for Debian and similar distros
15 if ! ifclass DEBIAN ; then
16 exit 0
17 fi
18
19 set -a
20
21 # do not set up grub during dirinstall
22 if [ "$FAI_ACTION" = "dirinstall" ] ; then
23 exit 0
24 fi
25 # during softupdate use this file
26 [ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh
27
28 if [ -z "$BOOT_DEVICE" ]; then
29 exit 189
30 fi
31
32 # disable os-prober because of #802717
33 ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'
34
35 # skip the rest, if not an initial installation
36 if [ $FAI_ACTION != "install" ]; then
37 $ROOTCMD update-grub
38 exit $error
39 fi
40
41 GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
42
43 # handle /boot in lvm-on-md
44 _bdev=$(readlink -f $BOOT_DEVICE)
45 if [ "${_bdev%%-*}" = "/dev/dm" ]; then
46 BOOT_DEVICE=$( lvs --noheadings -o devices $BOOT_DEVICE | sed -e 's/^*\([^(]*\)(.*$/\1/' )
47 fi
48
49 # ARM64 or AMD64
50 arch=$(uname -m)
51 if [ "$arch" == "aarch64" ]; then
52 opts="--no-floppy --modules=part_gpt"
53 else
54 opts="--no-floppy --target=x86_64-efi --modules=part_gpt"
55 fi
56
57 # Check if RAID is used for the boot device
58 if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
59 raiddev=${BOOT_DEVICE#/dev/}
60 # install grub on all members of RAID
61 for device in $(LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; print }' /proc/mdstat); do
62 echo Install grub on /dev/$device
63 $ROOTCMD grub-install $opts --force-extra-removable "/dev/$device"
64 done
65
66 elif [[ $BOOT_DEVICE =~ '/dev/loop' ]]; then
67 # do not update vmram when using a loop device
68 $ROOTCMD grub-install $opts --force-extra-removable --no-nvram $BOOT_DEVICE
69 if [ $? -eq 0 ]; then
70 echo "Grub installed on hostdisk $BOOT_DEVICE"
71 fi
72
73 else
74 $ROOTCMD grub-install $opts "$GROOT"
75 if [ $? -eq 0 ]; then
76 echo "Grub installed on $BOOT_DEVICE = $GROOT"
77 fi
78 fi
79 $ROOTCMD update-grub
80 if [[ $BOOT_DEVICE =~ '/dev/loop' ]]; then
81 :
82 else
83 efibootmgr -v
84 fi
85
86 exit $error