improve handling of kernel modules

This commit is contained in:
ghe0 2024-11-07 19:12:10 +02:00
parent 95162c581c
commit 99d46a0ac2
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
3 changed files with 39 additions and 13 deletions

@ -8,17 +8,19 @@ cd build
echo_blue "Starting installation at $ROOT."
create_dirs
echo_blue "Adding kernel binaries..."
install_busybox
install_binary $(which modprobe)
echo_blue "Adding binaries and libs..."
install_binary $(which switch_root)
install_binary $(which bash)
install_binary $(which mount)
install_kmod
install_busybox
echo_blue "Adding scripts..."
install_init_script
echo_blue "Adding kernel modules..."
install_module "$(df -T / | awk '{ print $2 }' | tail -1)"
install_module btrfs
install_module msr
install_module sev-guest
install_module dm_crypt

@ -63,6 +63,17 @@ install_binary() {
done <<< "$( echo "$ldd_deps" | grep -F ' => ' | awk '{ print $3 }' )"
}
install_kmod() {
echo_blue "Installing kmod (depmod, insmod, lsmod, modinfo, modprobe, rmmod)..."
install_binary /usr/bin/kmod || return 1
ln -s kmod ${ROOT}/usr/bin/lsmod
ln -s kmod ${ROOT}/usr/bin/rmmod
ln -s kmod ${ROOT}/usr/bin/insmod
ln -s kmod ${ROOT}/usr/bin/modinfo
ln -s kmod ${ROOT}/usr/bin/modprobe
ln -s kmod ${ROOT}/usr/bin/depmod
}
install_busybox() {
echo_blue "Installing busybox..."
[[ -f "$BUSYBOX_PATH" ]] || {
@ -82,21 +93,32 @@ install_init_script() {
}
install_module() {
local module="$1" depends='' dep='' filename=''
filename="$( modinfo -k $KERNEL $module | grep '^filename:' | awk '{ print $2 }' )"
[[ "$filename" == "(builtin)" ]] && {
local module="$1"
echo "modprobe $module" >> "${ROOT}/load_modules.sh.tmp"
_install_module "$module"
}
_install_module() {
local module="$1" depends='' dep='' filename='' filenames=''
filenames="$( modinfo -k $KERNEL $module | grep '^filename:' | awk '{ print $2 }' )"
[[ "$filenames" == "(builtin)" ]] && {
echo_yellow "Module $module is builtin. Installation not needed."
return 0
}
install_dep "$filename"
echo "insmod $filename" >> "${ROOT}/load_modules.sh"
while read -r filename; do
[[ -z $filename ]] && continue
install_dep "$filename"
done <<< "$( echo "$filenames" )"
depends="$(modinfo -k $KERNEL $module |
grep '^depends:' | awk '{ print $2 }' | sed 's/,/\n/g')"
depends="$( \
modinfo -k $KERNEL $module |
grep '^depends:' | awk '{ print $2 }' | sed 's/,/\n/g';
modinfo -k $KERNEL $module | grep '^softdep:' | awk '{ print $3 }'
)"
while read -r dep; do
[[ -z $dep ]] && continue
install_module "$dep"
_install_module "$dep"
done <<< "$( echo "$depends" )"
}
@ -106,7 +128,8 @@ create_archive() {
echo $archive > .archive_name
my_location="$(pwd)"
cd ${ROOT}
find . | cpio -o -H newc | gzip > "${my_location}/detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz"
find . | cpio -o -H newc | gzip \
> "${my_location}/detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz"
cd $my_location
}

@ -9,7 +9,7 @@ echo_red() {
}
load_modules() {
cat /load_modules.sh | sort -u | bash
cat /load_modules.sh | bash
}
create_mounts() {
@ -34,5 +34,6 @@ create_mounts() {
}
mount_root() {
mkdir /mnt
mount /dev/vda3 /mnt
}