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 # Path to the gummiboot files
54 gummiboot_path="$INSTALLERFW_MOUNT_PREFIX/usr/lib/gummiboot"
55 # Make sure gummiboot is installed in the system
56 if ! ([ -f $gummiboot_path/gummibootia32.efi ] || \
57 [ -f $gummiboot_path/gummibootx64.efi ]); then
58 fatal "\"$gummiboot_path/gummiboot*.efi\" files not found!"
61 # Get the ESP location
62 esp="$INSTALLERFW_MOUNT_PREFIX/$boot_mountpoint"
65 mkdir -p "$esp/EFI/boot"
66 [ -f "$gummiboot_path/gummibootia32.efi" ] &&
67 cp "$gummiboot_path/gummibootia32.efi" "$esp/EFI/boot/bootia32.efi"
68 [ -f "$gummiboot_path/gummibootx64.efi" ] &&
69 cp "$gummiboot_path/gummibootx64.efi" "$esp/EFI/boot/bootx64.efi"
71 # Generate the list of installed kernels
72 kernels="$(ls -1 "$esp" | grep "^vmlinuz-" | sort -r | head -n1)"
73 # Get the newest kernel
74 newest_kernel="$(printf "%s" "$kernels" | head -n1)"
76 # Create the gummiboot configuration file
77 mkdir -p "$esp/loader"
79 cat > "$esp/loader/loader.conf" <<-EOF
81 default $newest_kernel.conf
84 # Create a gummiboot entry for each kernel
85 mkdir -p "$esp/loader/entries"
86 printf "%s\n" "$kernels" | while IFS= read -r kernel; do
88 kernel_version="$(printf "%s" $kernel | sed -e 's/vmlinuz-\(.*\)/\1/')"
90 cat > "$esp/loader/entries/$kernel.conf" <<-EOF
92 version $kernel_version
94 options $INSTALLERFW_KERNEL_OPTS root=PARTUUID=$root_partuuid