From 3dd7e915e1cc3c603df4b2a41a457f26220a1993 Mon Sep 17 00:00:00 2001 From: ghe0 Date: Wed, 6 Nov 2024 05:44:54 +0200 Subject: [PATCH] also add kernel modules --- create.sh | 5 +++++ creator_exports.sh | 1 + creator_functions.sh | 32 ++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/create.sh b/create.sh index 76f5841..b204762 100755 --- a/create.sh +++ b/create.sh @@ -12,4 +12,9 @@ install_busybox install_binary $(which modprobe) install_binary $(which switch_root) install_init_script +install_module btrfs +install_module sev-guest +install_module dm_crypt +cp /lib/modules/${KERNEL}/modules.{order,builtin,builtin.modinfo} "${ROOT}/lib/modules/${KERNEL}/" +depmod -b "$ROOT" "$KERNEL" create_archive diff --git a/creator_exports.sh b/creator_exports.sh index 16baf15..7ceeaa5 100755 --- a/creator_exports.sh +++ b/creator_exports.sh @@ -4,3 +4,4 @@ script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) # root of the initrd, that will be used to create the cpio archive export ROOT="${script_dir}/build/initrd_root" export BUSYBOX_PATH="/usr/lib/initcpio/busybox" +export KERNEL="$(uname -r)" diff --git a/creator_functions.sh b/creator_functions.sh index 999571d..5bc64f4 100644 --- a/creator_functions.sh +++ b/creator_functions.sh @@ -4,21 +4,27 @@ echo_blue() { echo -e "\033[34m$1\033[0m" } +echo_yellow() { + echo -e "\033[0;33m$1\033[0m" +} + echo_red() { echo -e "\033[0;31m$1\033[0m" } # Installs a library. Expects absolute path. -install_lib() { +install_dep() { local lib="$1" [[ -f "$lib" ]] || { echo "Did not find library at path: $lib" exit 1 } - mkdir -p $(dirname "${ROOT}${lib}") - echo_blue "Adding library to root: $lib" - cp "$lib" "${ROOT}${lib}" + [[ -f "${ROOT}${lib}" ]] || { + mkdir -p $(dirname "${ROOT}${lib}") + echo_blue "Adding dependency to root: $lib" + cp "$lib" "${ROOT}${lib}" + } } # Expects to receive the absolute path as the full argument. @@ -40,7 +46,7 @@ install_binary() { fi while read -r lib; do - install_lib "$lib" + install_dep "$lib" done <<< "$( echo "$ldd_deps" | grep -F ' => ' | awk '{ print $3 }' )" } @@ -64,5 +70,19 @@ install_init_script() { create_archive() { echo_blue "Creating archive..." - find . | cpio -o -H newc | gzip > detee-$(hostnamectl hostname)-$(uname -r).cpio.gz + find . | cpio -o -H newc | gzip > detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz +} + +install_module() { + local module="$1" depends='' dep='' filename='' + + filename="$( modinfo -k $KERNEL $module | grep '^filename:' | awk '{ print $2 }' )" + install_dep "$filename" + + depends="$(modinfo -k $KERNEL $module | + grep '^depends:' | awk '{ print $2 }' | sed 's/,/\n/g')" + while read -r dep; do + [[ -z $dep ]] && continue + install_module "$dep" + done <<< "$( echo "$depends" )" }