aboutsummaryrefslogtreecommitdiff
path: root/fai/config/scripts/GRUB_EFI/10-setup
blob: 5f4a6de8de02ca03cf4883da55e322d54947f553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /bin/bash
# support for GRUB version 2

error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code

# This script assumes that the disk has a GPT partition table and
# that the extended system partition (ESP) is mounted on /boot/efi.
# When building a disk image, we don't change the NVRAM to point at
# the boot image we made available, because the disk image is likely
# not installed on the current system.  As a result, we force
# installation into the removable media paths as well as the standard
# debian path.

set -a

# do not set up grub during dirinstall
if [ "$FAI_ACTION" = "dirinstall" ] ; then
	exit 0
fi
# during softupdate use this file
[ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh

if [ -z "$BOOT_DEVICE" ]; then
	exit 189
fi

# disable os-prober because of #788062
ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'

# skip the rest, if not an initial installation
if [ $FAI_ACTION != "install" ]; then
	$ROOTCMD update-grub
	exit $error
fi

GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)

# handle /boot in lvm-on-md
_bdev=$(readlink -f $BOOT_DEVICE)
if [ "${_bdev%%-*}" = "/dev/dm" ]; then
	BOOT_DEVICE=` lvs --noheadings -o devices $BOOT_DEVICE | sed -e 's/^*\([^(]*\)(.*$/\1/' `
fi

# Check if RAID is used for the boot device
if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
	raiddev=${BOOT_DEVICE#/dev/}
	# install grub on all members of RAID
	for device in `LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ $_=$1; s/\d+\[\d+\]//g; print }' /proc/mdstat`; do
		echo Install grub on /dev/$device
		$ROOTCMD grub-install --no-floppy --force-extra-removable "/dev/$device"
	done

elif [[ $BOOT_DEVICE =~ '/dev/loop' ]]; then
	# do not update vmram when using a loop device
	$ROOTCMD grub-install --no-floppy --force-extra-removable --modules=part_gpt --no-nvram $BOOT_DEVICE
	if [ $? -eq 0 ]; then
		echo "Grub installed on hostdisk $BOOT_DEVICE"
	fi

else
	# Hack for the Dell Venue 8 Pro device series
	if $ROOTCMD dmidecode | grep "Product Name:" | grep -q "Venue 8 Pro"; then

		# wipe all EFI boot entries... Otherwise the dv8p's broken EFI
		# won't boot the device...
		$ROOTCMD efibootmgr | grep -E "^Boot[0-9]{4}.*" | sed -Ee 's/Boot([0-9]+).*/\1/' | while read bootnum; do
			$ROOTCMD efibootmgr --delete-bootnum --bootnum $bootnum
		done

	fi

	$ROOTCMD grub-install --no-floppy --modules=part_gpt "$GROOT"
	if [ $? -eq 0 ]; then
		echo "Grub installed on $BOOT_DEVICE = $GROOT"
	fi

	# Hack for the Dell Venue 8 Pro device series
	if $ROOTCMD dmidecode | grep "Product Name:" | grep -q "Venue 8 Pro"; then

		$ROOTCMD efibootmgr --bootnext 0000

	fi

fi
$ROOTCMD update-grub

exit $error