Skip to content

Commit

Permalink
Bugfix on Overlay Dracut module resilient without verity. (#8597)
Browse files Browse the repository at this point in the history
Co-authored-by: lanzeliu <[email protected]>
  • Loading branch information
liulanze and lanzeliu committed Apr 2, 2024
1 parent d5689fc commit 80d513e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
47 changes: 43 additions & 4 deletions SPECS/dracut/20overlayfs/overlayfs-mount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ parse_kernel_cmdline_args() {
# Ensure that the 'dracut-lib' is present and loaded.
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh

VERITY_MOUNT="/mnt/verity_mnt_$$"
OVERLAY_MOUNT="/mnt/overlay_mnt_$$"
VERITY_MOUNT="/mnt/verity_mnt"
OVERLAY_MOUNT="/mnt/overlay_mnt"
OVERLAY_MNT_OPTS="rw,nodev,nosuid,nouser,noexec"

# Retrieve the verity root. It is expected to be predefined by the dracut cmdline module.
Expand Down Expand Up @@ -102,14 +102,19 @@ mount_overlayfs() {
else
echo "Mounting regular root"
mkdir -p "${VERITY_MOUNT}"
mount -o ro,defaults "$root" "${VERITY_MOUNT}" || \
# Remove 'block:' prefix if present.
root_device=$(expand_persistent_dev "${root#block:}")
mount -o ro,defaults "$root_device" "${VERITY_MOUNT}" || \
die "Failed to mount root"
fi

echo "Starting to create OverlayFS"
for _group in ${overlayfs}; do
IFS=',' read -r overlay upper work volume <<< "$_group"

# Resolve volume to its full device path.
volume=$(expand_persistent_dev "$volume")

if [[ "$volume" == "" ]]; then
overlay_mount_with_cnt="${OVERLAY_MOUNT}/${cnt}"
mount_volatile_persistent_volume "volatile" $overlay_mount_with_cnt
Expand All @@ -135,5 +140,39 @@ mount_overlayfs() {
mount --rbind "${VERITY_MOUNT}" "${NEWROOT}"
}

# Keep a copy of this function here from verity-read-only-root package.
expand_persistent_dev() {
local _dev=$1

case "$_dev" in
LABEL=*)
_dev="/dev/disk/by-label/${_dev#LABEL=}"
;;
UUID=*)
_dev="${_dev#UUID=}"
_dev="${_dev,,}"
_dev="/dev/disk/by-uuid/${_dev}"
;;
PARTUUID=*)
_dev="${_dev#PARTUUID=}"
_dev="${_dev,,}"
_dev="/dev/disk/by-partuuid/${_dev}"
;;
PARTLABEL=*)
_dev="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
;;
esac
printf "%s" "$_dev"
}

# Parse kernel command line arguments to set environment variables.
# This function populates variables based on the kernel command line, such as overlayfs.
parse_kernel_cmdline_args
mount_overlayfs

# Check if the overlayfs variable is set, indicating that overlay filesystem parameters were found.
# If not set, the process to enable and mount the overlay filesystem will be skipped.
if [ -n "${overlayfs}" ]; then
mount_overlayfs
else
echo "OverlayFS parameter not found in kernel cmdline, skipping mount_overlayfs."
fi
2 changes: 1 addition & 1 deletion SPECS/dracut/dracut.signatures.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"lgpl-2.1.txt": "dc626520dcd53a22f727af3ee42c770e56c97a64fe3adb063799d8ab032fe551",
"megaraid.conf": "914824cdbe0c525b71efa05a75e453335b0068beb8bc28bef2a5866d74bf7dd4",
"module-setup.sh": "330af5c105793fb37434730ce0ff59467a9cc60a81a5e32193dc53235e9744c1",
"overlayfs-mount.sh": "d6c064e383f00abae1ee621b9657e439e698dba5d49807e38c94fac795f45ea4"
"overlayfs-mount.sh": "e0d009b765fea58319f9b4b33f5399d6fea90f3ba98a4fdad43d80256e555027"
}
}

0 comments on commit 80d513e

Please sign in to comment.