also add kernel modules

This commit is contained in:
ghe0 2024-11-06 05:44:54 +02:00
parent 9aad2dadbf
commit 3dd7e915e1
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
3 changed files with 32 additions and 6 deletions

@ -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

@ -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)"

@ -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
}
[[ -f "${ROOT}${lib}" ]] || {
mkdir -p $(dirname "${ROOT}${lib}")
echo_blue "Adding library to 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" )"
}