From 96794bde2e2e0ce93583de80b9ad7e9b8bd87a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?= Date: Thu, 30 May 2024 16:07:12 +0100 Subject: [PATCH] factory: do not mount /lib/{modules,firmware} if there is a drivers tree Do not mount /lib/{modules,firmware} in case snapd created a drivers tree for our kernel snap, as in that case these mounts will be created by snapd-generator from the base or from the snapd deb package for hybrid systems. This situation is expected to happen only for 24+ systems. --- factory/usr/lib/core/extra-paths | 15 ++++++++++++++- .../system-generators/kernel-snap-generator | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/factory/usr/lib/core/extra-paths b/factory/usr/lib/core/extra-paths index 70b2877a..b0db3d55 100755 --- a/factory/usr/lib/core/extra-paths +++ b/factory/usr/lib/core/extra-paths @@ -2,8 +2,21 @@ set -eu -cat <>/sysroot/etc/fstab +cat <<'EOF' >>/sysroot/etc/fstab /run/mnt/data /writable none bind,x-initrd.mount 0 0 +EOF + +# Find out kernel name / revision +kernelPath=$(cat /sys/dev/block/"$(mountpoint --fs-devno /run/mnt/kernel)"/loop/backing_file) +kernelFile=$(basename "$kernelPath") +kernelName=${kernelFile%%_*} +rev=${kernelFile#*_} +rev=${rev%%.*} + +# Mount /lib/{firmware,modules} only if there is no drivers tree created by snapd +if [ ! -d /run/mnt/data/system-data/var/lib/snapd/kernel/"$kernelName"/"$rev" ]; then + cat <<'EOF' >>/sysroot/etc/fstab /run/mnt/kernel/firmware /usr/lib/firmware none bind,x-initrd.mount 0 0 /run/mnt/kernel/modules /usr/lib/modules none bind,x-initrd.mount 0 0 EOF +fi diff --git a/factory/usr/lib/systemd/system-generators/kernel-snap-generator b/factory/usr/lib/systemd/system-generators/kernel-snap-generator index e9b8dcf4..dbad82c6 100755 --- a/factory/usr/lib/systemd/system-generators/kernel-snap-generator +++ b/factory/usr/lib/systemd/system-generators/kernel-snap-generator @@ -35,6 +35,18 @@ if ! grep -q "^ID=ubuntu$" "${OS_RELEASE}"; then exit 0 fi +# Find out kernel name / revision +kernelPath=$(cat /sys/dev/block/"$(mountpoint --fs-devno "$KERNEL_MNT_POINT")"/loop/backing_file) +kernelFile=$(basename "$kernelPath") +kernelName=${kernelFile%%_*} +rev=${kernelFile#*_} +rev=${rev%%.*} + +# Mount /lib/{firmware,modules} only if there is no drivers tree created by snapd +if [ -d /run/mnt/data/var/lib/snapd/kernel/"$kernelName"/"$rev" ]; then + exit 0 +fi + for entry in firmware modules; do what="${KERNEL_MNT_POINT}/${entry}" where="${sysroot}/usr/lib/${entry}"