commit: 210016cccfe4c7e490f6ec77319d328a3147c7a1
parent 194371d8b1c87baf8b520dee82c9e20a19d156c0
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 20 Apr 2025 08:36:02 +0200
Copy only configured modules rather than whole /lib/modules/$kver/
Also has the nice side effect of copying modprobe parameters
and only requiring the much simpler insmod command.
Diffstat:
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/init b/init
@@ -75,7 +75,7 @@ exec 0<"$console" 1>"$console" 2>&1
#
#mount /dev/mapper/root $newroot || die
-modprobe zfs || die
+/load_modules.sh || die
cryptsetup open /dev/sda2 cryptrpool || die
diff --git a/make-initrd.sh b/make-initrd.sh
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: ISC
elves="busybox blkid lsblk cryptsetup mksh zfs zpool"
+modules="zfs"
WORKDIR="$(pwd)"
die() {
@@ -12,8 +13,6 @@ die() {
[ -n "$1" ] || die "make-initrd takes kernel version as argument"
kver="$1"
-modulesdir="/lib/modules/${kver}"
-[ -d "$modulesdir" ] || die "${modulesdir}: Directory not found"
out_base="initramfs-${kver}"
@@ -22,14 +21,12 @@ if test -e "$out_base"; then
fi
mkdir -p "$out_base" || die "Failed: mkdir $out_base"
cd "$out_base" || die "Failed: cd $out_base"
-mkdir -p bin lib/modules dev proc sys newroot etc || die "Failed creating base directories"
+mkdir -p bin dev proc sys newroot etc || die "Failed creating base directories"
ln -s /proc/mounts etc/mtab || die "Failed symlink for /etc/mtab"
ln -s . usr
ln -s lib lib64
ln -s lib lib32
-cp -pr "${modulesdir}" lib/modules/ || die "Failed copying kernel modules"
-
mknod -m 660 dev/console c 5 1
mknod -m 666 dev/urandom c 1 9
mknod -m 666 dev/random c 1 8
@@ -44,6 +41,15 @@ for elf in $elves; do
cp "$origin" bin/ || die
done
+for mod in $modules; do
+ modprobe -S "$kver" --show-depends "$mod" | tee -a ./load_modules.sh | while read -r cmd file params; do
+ mkdir -p "$(dirname ./"$file")" || die
+ cp -p "$file" ./"$file" || die
+ done
+done
+
+test -f ./load_modules.sh && chmod +x ./load_modules.sh
+
if [ -f /root/initrd-keyfile ]; then
cp /root/initrd-keyfile ./keyfile || die "copying keyfile"
fi