3 # Copyright 2013-2014 Intel Corporation
4 # Author: Artem Bityutskiy
7 PROG="setup-scripts-boot"
10 srcdir="$(readlink -ev -- ${0%/*})"
11 PATH="/usr/share/setup-scripts:$srcdir:$PATH"
13 if [ -f "$srcdir/setup-scripts-sh-functions" ]; then
14 . "$srcdir/setup-scripts-sh-functions"
15 . "$srcdir/installerfw-sh-functions"
17 . /usr/share/setup-scripts/setup-scripts-sh-functions
18 . /usr/share/setup-scripts/installerfw-sh-functions
21 # This is a small trick which I use to make sure my scripts are portable -
22 # check if 'dash' is present, and if yes - use it.
23 if can_switch_to_dash; then
24 exec dash -euf -- "$srcdir/$PROG" "$@"
30 verbose "installing gummiboot to $bootdir"
32 local installdir="$bootdir/EFI/boot"
33 local gummiboot_path="$(installerfw_mnt_prefix "/usr/lib/gummiboot")"
34 local src32="$gummiboot_path/gummibootia32.efi"
35 local src64="$gummiboot_path/gummibootx64.efi"
39 # Autoboot from fs0 by default
40 local efi_bootdir="fs0:"
42 # Make sure gummiboot is installed in the system
43 if ! ([ -f "$src32" ] || [ -f "$src64" ]); then
44 fatal "\"$gummiboot_path/gummiboot*.efi\" files not found!"
48 mkdir -p $verbose -- "$installdir" >&2
50 if [ -f "$src64" ] ; then
52 dst="$installdir/bootx64.efi"
53 elif [ -f "$src32" ] ; then
55 dst="$installdir/bootia32.efi"
58 if [ -f "$src" ] ; then
59 local basename=$(basename -- "$dst")
60 cp $verbose "$src" "$dst" 2>&2
61 echo "${efi_bootdir}\\EFI\\boot\\$basename" > "${bootdir}/startup.nsh"
64 verbose "installed gummiboot to $bootdir"
69 local installdir="$bootdir/extlinux"
70 local extlinux="extlinux"
73 # Check if extlinux is available
74 if ! command -v "extlinux" >/dev/null 2>&1; then
75 extlinux="$(installerfw_mnt_prefix "/sbin/extlinux")"
77 fatal "cannot find \"$extlinux\""
80 # Get device node name for the boot partition
82 installerfw_get_part_info "/boot" "DEVNODE_NOW" "boot_devnode"
83 [ -n "$boot_devnode" ] || \
84 fatal "cannot find device node of the boot disk, probably" \
85 "INSTALLERFW_PARTx_DEVNODE_NOW environment" \
86 "variable is not defined"
89 verbose "installing extlinux to $bootdir, boot device node is" \
91 mkdir -p $verbose -- "$installdir" >&2
92 output="$("$extlinux" --device "$boot_devnode" -i "$installdir" 2>&1)" \
93 || fatal "cannot install extlinux to \"$installdir\" (note," \
94 "extlinux version 5 or greater is required)" \
97 # Get device node name for the boot disk
99 installerfw_get_part_info "/boot" "DISK_DEVNODE_NOW" "mbr_devnode"
100 [ -n "$mbr_devnode" ] || \
101 fatal "cannot find device node of the boot disk, probably" \
102 "INSTALLERFW_PARTx_DISK_DEVNODE_NOW environment" \
103 "variable is not defined"
105 # Install the MBR part of extlinux
106 local mbr_bin="$(installerfw_mnt_prefix \
107 "/usr/share/syslinux/gptmbr.bin")"
108 verbose "setting up MBR, writing \"$mbr_bin\" to \"$mbr_devnode\""
109 output="$(dd if="$mbr_bin" of="$mbr_devnode" count=1 2>&1)" || \
110 fatal "cannot install MBR, dd if=$mbr_bin of=$mbr_devnode" \
111 "failed${br}${output}"
113 verbose "installed extlinux to $bootdir"
119 Usage: $PROG [options]
121 Install the EFI bootloader (gummiboot) and create the initial configuration
122 for all the currently installed kernels. This program depends on various
123 "installer framework" variables.
126 -v, --verbose be verbose
127 --version show the program version and exit
128 -h, --help show this text and exit
134 IFS= printf "%s\n\n" "$PROG: error: $*" >&2
140 tmp=`getopt -n $PROG -o v,h --long verbose,version,help -- "$@"` ||
141 show_usage_fail "cannot parse command-line options"
160 *) show_usage_fail "unrecognized option \"$1\""
166 bootdir="$(installerfw_mnt_prefix "/boot")"
168 if installerfw_available; then
171 installerfw_restore_env
175 get_os_name "os_name"
177 if installerfw_is_efi_boot_system; then
183 # Create bootloader entries for each kernel
184 kernels="$(ls -1 "$bootdir" | LC_ALL=C grep -- "^vmlinuz-" | sort -r)"
186 [ -n "$kernels" ] || \
187 fatal "no kernels (vmlinuz-*) found in \"$bootdir\""
189 printf "%s\n" "$kernels" | while IFS= read -r kernel; do
190 setup-scripts-bootloader-conf $verbose add --force "$kernel"
193 # Set the default kernel to the kernel with highest version
194 newest_kernel="$(get_newest_kernel "$bootdir")"
195 setup-scripts-bootloader-conf $verbose default "$newest_kernel"
197 # And finally, create the /etc/fstab file
198 setup-scripts-fstab $verbose --force