3 # Copyright 2013 Intel Corporation
4 # Author: Artem Bityutskiy
8 # This is a simple script which installs gummiboot to the ESP and creates the
9 # gummiboot configuration files. This script requires a number of environment
10 # variables to be defined. Namely:
12 # 1. INSTALLERFW_PART_COUNT - count of paritions
13 # 2. INSTALLERFW_PARTX_MOUNTPOINT - mount point of partition number X
14 # (0 <= x < $INSTALLERFW_PART_COUNT)
15 # 3. INSTALLERFW_PARTX_PARTUUID - GPT GUID (AKA PARTUUID) of partition number X
16 # 4. INSTALLERFW_PARTX_FSTYPE - which file-system format partition number X has
17 # 5. INSTALLERFW_MOUNT_PREFIX - where the target partitions are mounted (the
18 # "root" directory of the file-system we install gummiboot to)
22 # This is a helper function which prints an error message and exits
25 printf "%s\n" "$PROG: error: $1" 1>&2
29 # Make sure the installer framework variables are defined
30 [ "${INSTALLERFW_PART_COUNT:+x}" == "x" ] ||
31 fatal "installer framework environment variables not found"
33 # Find the root and boot paritions
38 while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
39 mountpoint="INSTALLERFW_PART${pnum}_MOUNTPOINT"
40 mountpoint="$(eval printf "%s" '$'$mountpoint)"
42 # Find out all the required data for the root and boot partition
43 if [ "$mountpoint" == "/" ]; then
44 root_partuuid="INSTALLERFW_PART${pnum}_PARTUUID"
45 root_partuuid="$(eval printf "%s" '$'$root_partuuid)"
46 # The boot parition has to be at "/boot"
47 elif [ "$mountpoint" == "/boot" ]; then
48 boot_fstype="INSTALLERFW_PART${pnum}_FSTYPE"
49 boot_fstype="$(eval printf "%s" '$'$boot_fstype)"
55 # Make sure that the boot partition has a FAT file-system
56 [ "$boot_fstype" == "vfat" ] || \
57 fatal "boot partition has to have type \"vfat\""
59 # Get the ESP location
60 esp="$INSTALLERFW_MOUNT_PREFIX/boot"
62 # Make sure gummiboot is installed in the system
63 if ! ([ -f /usr/lib/gummiboot/gummibootia32.efi ] || \
64 [ -f /usr/lib/gummiboot/gummibootx64.efi ]); then
65 fatal "\"/usr/lib/gummiboot/gummiboot*.efi\" files not found!"
69 mkdir -p "$esp/EFI/boot"
70 [ -f "/usr/lib/gummiboot/gummibootia32.efi" ] &&
71 cp "/usr/lib/gummiboot/gummibootia32.efi" "$esp/EFI/boot/bootia32.efi"
72 [ -f "/usr/lib/gummiboot/gummibootx64.efi" ] &&
73 cp "/usr/lib/gummiboot/gummibootx64.efi" "$esp/boot/EFI/boot/bootx64.efi"
75 # Generate the list of installed kernels
76 kernels="$(ls -1 "$esp" | grep "^vmlinuz-" | sort -r | head -n1)"
77 # Get the newest kernel
78 newest_kernel="$(printf "%s" "$kernels" | head -n1)"
80 # Create the gummiboot configuration file
81 mkdir -p "$esp/loader"
83 cat > "$esp/loader/loader.conf" <<-EOF
85 default $newest_kernel.conf
88 # Create a gummiboot entry for each kernel
89 mkdir -p "$esp/loader/entries"
90 printf "%s\n" "$kernels" | while IFS= read -r kernel; do
92 kernel_version="$(printf "%s" $kernel | sed -e 's/vmlinuz-\(.*\)/\1/')"
94 cat > "$esp/loader/entries/$kernel.conf" <<-EOF
96 version $kernel_version
98 options $INSTALLERFW_KERNEL_OPTS root=PARTUUID=$root_partuuid