Skip to content

Commit

Permalink
factory: do not mount /lib/{modules,firmware} if there is a drivers tree
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alfonsosanchezbeato committed Jun 5, 2024
1 parent a0ef0e0 commit 96794bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion factory/usr/lib/core/extra-paths
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@

set -eu

cat <<EOF >>/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
12 changes: 12 additions & 0 deletions factory/usr/lib/systemd/system-generators/kernel-snap-generator
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 96794bd

Please sign in to comment.