diff --git a/create.sh b/create.sh index 55b2195..df6f484 100755 --- a/create.sh +++ b/create.sh @@ -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 diff --git a/creator_functions.sh b/creator_functions.sh index 29e10cf..7e692be 100644 --- a/creator_functions.sh +++ b/creator_functions.sh @@ -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 } diff --git a/init_functions.sh b/init_functions.sh index 38dfc4f..3e50d92 100644 --- a/init_functions.sh +++ b/init_functions.sh @@ -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 }