Skip to content

Commit ede8b9f

Browse files
committed
Handle /dev/mmcblk0p1-style names; deal with ro efivarfs
Bump version to 1.0.31
1 parent 1a2b10b commit ede8b9f

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

buildkernel

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ shopt -s nullglob
3131
# ********************** variables *********************
3232
PROGNAME="$(basename "${0}")"
3333
CONFFILE="/etc/${PROGNAME}.conf"
34-
VERSION="1.0.30"
34+
VERSION="1.0.31"
3535
ETCPROFILE="/etc/profile"
3636
DEFAULTEFIBOOTFILE="bootx64.efi"
3737
EFIBOOTFILE="${DEFAULTEFIBOOTFILE}"
@@ -165,6 +165,11 @@ done
165165

166166
# running under EFI?
167167
declare -i USINGEFI=0
168+
# efivarfs mounted ro on entry? (OpenRC does, systemd doesn't)
169+
declare -i ONENTRYROEFIVARFS=0
170+
# and subsequently remounted rw?
171+
declare -i EFIVARFSREMOUNTEDRW=0
172+
168173
# has support for kernel modules
169174
declare -i USINGMODULES=1
170175

@@ -184,6 +189,7 @@ cleanup_and_exit_with_code() {
184189
set +e
185190
trap - EXIT
186191
umount_all_remembered_mountpoints
192+
restore_efivarfs_mount_state
187193
exit $1
188194
}
189195
fn_exists() {
@@ -354,6 +360,21 @@ umount_all_remembered_mountpoints() {
354360
umount_and_forget "${M}"
355361
done
356362
}
363+
ensure_efivarfs_rw_if_present() {
364+
if ((USINGEFI==1 && ONENTRYROEFIVARFS==1)); then
365+
warning "Temporarily remounting efivarfs read-write"
366+
mount -o remount,rw "/sys/firmware/efi/efivars"
367+
EFIVARFSREMOUNTEDRW=1
368+
fi
369+
}
370+
restore_efivarfs_mount_state() {
371+
if ((USINGEFI==1 && ONENTRYROEFIVARFS==1 && EFIVARFSREMOUNTEDRW==1)); then
372+
warning "Remounting efivarfs read-only"
373+
if mount -o remount,ro "/sys/firmware/efi/efivars"; then
374+
EFIVARFSREMOUNTEDRW=0
375+
fi
376+
fi
377+
}
357378
check_is_luks_volume() {
358379
cryptsetup isLuks "${1}" || die "Path '${1}' is not a LUKS volume"
359380
}
@@ -456,9 +477,10 @@ setup_final_variables() {
456477
# has been set explicitly in buildkernel.conf
457478
KEYFILEPARTUUID="${KEYFILEPARTUUID:-${EFIPARTUUID}}"
458479
KEYFILEPATHMAP="${PARTUUIDDEVDIR}/${KEYFILEPARTUUID}"
459-
# get the real root filesystem type
480+
# get the real root filesystem type if not specified
481+
# falling back to ext4 if the findmnt-based lookup fails
460482
if [[ ! -v CMDLINE_ROOTFSTYPE ]]; then
461-
CMDLINE_ROOTFSTYPE="$(/bin/findmnt -n -o FSTYPE -S ${CMDLINE_REAL_ROOT})"
483+
CMDLINE_ROOTFSTYPE="$(/bin/findmnt -n -o FSTYPE -S ${CMDLINE_REAL_ROOT} 2>/dev/null || echo ext4)"
462484
fi
463485
# we use path syntax rather than "=PARTUUID=" syntax, as more reliable
464486
KERNEL_CMD_LINE="root=${CMDLINE_ROOT} crypt_root=${CRYPTPATHMAP} dolvm "
@@ -490,6 +512,12 @@ setup_final_variables() {
490512
check_if_booted_under_efi() {
491513
if [ -d "/sys/firmware/efi" ]; then
492514
USINGEFI=1
515+
# efivarfs mounted ro?
516+
if findmnt "/sys/firmware/efi/efivars" --options "ro" &>/dev/null; then
517+
ONENTRYROEFIVARFS=1
518+
else
519+
ONENTRYROEFIVARFS=0
520+
fi
493521
else
494522
USINGEFI=0
495523
fi
@@ -548,9 +576,10 @@ find_all_luks_partitions() {
548576
local NEXTUUID="${NEXTPART##*/}"
549577
local NEXTPARTNAME="$(readlink --canonicalize "${NEXTPART}")" # e.g. /dev/sda3
550578
# nvme devices have paths of form e.g. /dev/nvme0n1p1
579+
# mmc devices have paths of form e.g. /dev/mmcblk0p1
551580
# standard drives have form e.g. /dev/sda3
552-
if [[ ${NEXTPARTNAME} =~ ^/dev/nvme.*$ ]]; then
553-
local NEXTDEVNAME="${NEXTPARTNAME%%p[[:digit:]]*}" # e.g. /dev/nvme0n1
581+
if [[ ${NEXTPARTNAME} =~ ^/dev/.*[[:digit:]]p[[:digit:]]+$ ]]; then
582+
local NEXTDEVNAME="${NEXTPARTNAME%%p[[:digit:]]*}" # e.g. /dev/nvme0n1, /dev/mmcblk0
554583
else
555584
local NEXTDEVNAME="${NEXTPARTNAME%%[[:digit:]]*}" # e.g. /dev/sda
556585
fi
@@ -582,9 +611,10 @@ find_all_efi_system_partitions() {
582611
local NEXTUUID="${NEXTPART##*/}"
583612
local NEXTPARTNAME="$(readlink --canonicalize "${NEXTPART}")" # e.g. /dev/sda3
584613
# nvme devices have paths of form e.g. /dev/nvme0n1p1
614+
# mmc devices have paths of form e.g. /dev/mmcblk0p1
585615
# standard drives have form e.g. /dev/sda3
586-
if [[ ${NEXTPARTNAME} =~ ^/dev/nvme.*$ ]]; then
587-
local NEXTDEVNAME="${NEXTPARTNAME%%p[[:digit:]]*}" # e.g. /dev/nvme0n1
616+
if [[ ${NEXTPARTNAME} =~ ^/dev/.*[[:digit:]]p[[:digit:]]+$ ]]; then
617+
local NEXTDEVNAME="${NEXTPARTNAME%%p[[:digit:]]*}" # e.g. /dev/nvme0n1, /dev/mmcblk0
588618
else
589619
local NEXTDEVNAME="${NEXTPARTNAME%%[[:digit:]]*}" # e.g. /dev/sda
590620
fi
@@ -1457,9 +1487,10 @@ conform_efi_boot_order_if_possible() {
14571487
local PARTNAME="$(readlink --canonicalize "${EFIPARTPATH}")" # e.g. /dev/sda3
14581488
local DEVNAME
14591489
# nvme devices have paths of form e.g. /dev/nvme0n1p1
1490+
# mmc devices have paths of form e.g. /dev/mmcblk0p1
14601491
# standard drives have form e.g. /dev/sda3
1461-
if [[ ${PARTNAME} =~ ^/dev/nvme.*$ ]]; then
1462-
DEVNAME="${PARTNAME%%p[[:digit:]]*}" # e.g. /dev/nvme0n1
1492+
if [[ ${PARTNAME} =~ ^/dev/.*[[:digit:]]p[[:digit:]]+$ ]]; then
1493+
DEVNAME="${PARTNAME%%p[[:digit:]]*}" # e.g. /dev/nvme0n1, /dev/mmcblk0
14631494
else
14641495
DEVNAME="${PARTNAME%%[[:digit:]]*}" # e.g. /dev/sda
14651496
fi
@@ -1489,6 +1520,7 @@ conform_efi_boot_order_if_possible() {
14891520
fi
14901521
fi
14911522
if ((NEWBOOTENTRYNEEDED==1)); then
1523+
ensure_efivarfs_rw_if_present
14921524
# remove any existing bootnums with the same name first
14931525
declare -i I=0
14941526
for I in "${!EBOOTNAMES[@]}"; do
@@ -1499,6 +1531,7 @@ conform_efi_boot_order_if_possible() {
14991531
done
15001532
show "Adding ('${BOOTLABEL}') to top of the EFI boot list"
15011533
efibootmgr --create --disk "${DEVNAME}" --part "${PARTNUM}" --loader "${SMBOOTPATH}" --label "${BOOTLABEL}"
1534+
restore_efivarfs_mount_state
15021535
else
15031536
show "Appropriate entry already exists at the top of EFI boot list"
15041537
fi

buildkernel.8

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH BUILDKERNEL 8 "Version 1.0.30: May 2018"
1+
.TH BUILDKERNEL 8 "Version 1.0.31: October 2018"
22
.SH NAME
33
buildkernel \- build secure boot kernel, save to EFI system partition
44
.SH SYNOPSIS
@@ -83,7 +83,12 @@ backs up the old kernel and config on the EFI system partition, if any are prese
8383
.IP \(bu 2
8484
copies the newly built kernel (which is configured so as to be an EFI executable), into \fI/boot/efi/EFI/Boot/bootx64.efi\fR (the magic location expected by most UEFI BIOSes; you can override this \(em see \fBgenkenrnel.conf\fR(5)); and also copies the config to the same directory;
8585
.IP \(bu 2
86-
ensures that an EFI boot entry for the new kernel exists, and that it is placed at the top of the EFI boot order (N.B., it is only possible to do this if the system is currently booted under EFI);
86+
ensures that an EFI boot entry for the new kernel exists, and that it
87+
is placed at the top of the EFI boot order (N.B., it is only possible
88+
to do this if the system is currently booted under EFI); note that
89+
\fBbuildkernel\fR will temporarily make the special
90+
\fI/sys/firmware/efi/efivars\fR filesystem read-write, if required for
91+
these modifications to be made;
8792
.IP \(bu 2
8893
performs a filesystem sync and then unmounts the EFI system partition (if you so specify, see the \fB--unmount-at-end\fR option text).
8994
.RE

buildkernel.conf.5

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH BUILDKERNEL 5 "Version 1.0.30: May 2018"
1+
.TH BUILDKERNEL 5 "Version 1.0.31: October 2018"
22
.SH NAME
33
buildkernel.conf \- a configuration file for \fBbuildkernel\fR(8)
44
.SH SYNOPSIS
@@ -184,6 +184,15 @@ intruct the kernel to XZ compress its integral initrams (the default
184184
behaviour prior to version 1.0.30); doing so may cause boot
185185
issues on certain systems with modest RAM.
186186

187+
Most users will not need to override the default.
188+
.br
189+
.TP
190+
.BR CMDLINE_ROOTFSTYPE
191+
If you wish to explicitly specify your root filesystem's type, do so
192+
via this variable. Otherwise, \fBbuildkernel\fR will attempt to
193+
automatically detect the filesystem type of \fBCMDLINE_REAL_ROOT\fR
194+
(falling back to \fBext4\fR, in case of error).
195+
187196
Most users will not need to override the default.
188197

189198
.RE

0 commit comments

Comments
 (0)