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_MOUNT_PREFIX - where the target partitions are mounted (the
17 # "root" directory of the file-system we install gummiboot to)
21 # This is a helper function which prints an error message and exits
24 printf "%s\n" "$PROG: error: $1" 1>&2
28 # Make sure the installer framework variables are defined
29 [ "${INSTALLERFW_PART_COUNT:+x}" == "x" ] ||
30 fatal "installer framework environment variables not found"
32 # Find the required root and boot parition parameters
37 while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
38 mountpoint="INSTALLERFW_PART${pnum}_MOUNTPOINT"
39 mountpoint="$(eval printf "%s" '$'$mountpoint)"
41 # Find out all the required data for the root and boot partition
42 if [ "$mountpoint" == "/" ]; then
43 root_partuuid="INSTALLERFW_PART${pnum}_PARTUUID"
44 root_partuuid="$(eval printf "%s" '$'$root_partuuid)"
45 # The boot parition has to be at "/boot"
46 elif [ "$mountpoint" == "/boot" ]; then
47 boot_mountpoint="$mountpoint"
53 # Get the ESP location
54 esp="$INSTALLERFW_MOUNT_PREFIX/$boot_mountpoint"
56 # Make sure gummiboot is installed in the system
57 if ! ([ -f /usr/lib/gummiboot/gummibootia32.efi ] || \
58 [ -f /usr/lib/gummiboot/gummibootx64.efi ]); then
59 fatal "\"/usr/lib/gummiboot/gummiboot*.efi\" files not found!"
63 mkdir -p "$esp/EFI/boot"
64 [ -f "/usr/lib/gummiboot/gummibootia32.efi" ] &&
65 cp "/usr/lib/gummiboot/gummibootia32.efi" "$esp/EFI/boot/bootia32.efi"
66 [ -f "/usr/lib/gummiboot/gummibootx64.efi" ] &&
67 cp "/usr/lib/gummiboot/gummibootx64.efi" "$esp/boot/EFI/boot/bootx64.efi"
69 # Generate the list of installed kernels
70 kernels="$(ls -1 "$esp" | grep "^vmlinuz-" | sort -r | head -n1)"
71 # Get the newest kernel
72 newest_kernel="$(printf "%s" "$kernels" | head -n1)"
74 # Create the gummiboot configuration file
75 mkdir -p "$esp/loader"
77 cat > "$esp/loader/loader.conf" <<-EOF
79 default $newest_kernel.conf
82 # Create a gummiboot entry for each kernel
83 mkdir -p "$esp/loader/entries"
84 printf "%s\n" "$kernels" | while IFS= read -r kernel; do
86 kernel_version="$(printf "%s" $kernel | sed -e 's/vmlinuz-\(.*\)/\1/')"
88 cat > "$esp/loader/entries/$kernel.conf" <<-EOF
90 version $kernel_version
92 options $INSTALLERFW_KERNEL_OPTS root=PARTUUID=$root_partuuid