-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy path99-balena-bootloader
35 lines (24 loc) · 1016 Bytes
/
99-balena-bootloader
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
#!/bin/sh
#
# Script which configures bootenv to use an updated root partition
#
set -o errexit
. /usr/sbin/balena-config-vars
. /usr/libexec/os-helpers-logging
DURING_UPDATE=${DURING_UPDATE:-0}
if [ "${DURING_UPDATE}" = "1" ]; then
SYSROOT="/mnt/sysroot/inactive"
else
SYSROOT="/mnt/sysroot/active"
fi
NEW_ROOT_PART=$(findmnt --noheadings --canonicalize --output SOURCE ${SYSROOT} -t ext4)
NEW_ROOT_LABEL=$(lsblk -nlo label "${NEW_ROOT_PART}")
NEW_ROOT=$(echo "${NEW_ROOT_LABEL}" | sed -e "s,^\(resin\|balena\)-root\([AB]\)$,\2,")
info "Switching root partition to ${NEW_ROOT}"
BOOTENV_FILE="${BALENA_NONENC_BOOT_MOUNTPOINT}/bootenv"
# When migrating to balena bootloader make sure no alternative is present
rm -f "${BALENA_NONENC_BOOT_MOUNTPOINT}/resinOS_uEnv.txt"
rm -f "${BALENA_NONENC_BOOT_MOUNTPOINT}/grubenv"
grub-editenv "${BOOTENV_FILE}" set "resin_root_part=${NEW_ROOT}"
grub-editenv "${BOOTENV_FILE}" set "upgrade_available=${DURING_UPDATE}"
info "Will use root ${NEW_ROOT} during next boot"