diff --git a/create.sh b/create.sh index 1bccb0c..1cc0283 100755 --- a/create.sh +++ b/create.sh @@ -25,9 +25,7 @@ install_guest_api echo_cyan "Installing scripts..." install_init_script -echo_cyan "Installing kernel modules..." -# # Uncomment this section if you want to grab modules from the guest OS -# scan_modules +echo_cyan "Installing kernel modules mandatory for DTRFS..." install_module virtio_net install_module ext4 install_module virtio_blk @@ -42,6 +40,11 @@ install_module sha256 install_module rng install_module aes +[[ "$GRAB_LOCAL_MODS" == "YES" ]] && { + scan_modules + backup_active_modules +} + echo_cyan "Building module dependency tree..." cp /lib/modules/${KERNEL}/modules.{order,builtin,builtin.modinfo} "${ROOT}/lib/modules/${KERNEL}/" depmod -b "$ROOT" "$KERNEL" diff --git a/creator_exports.sh b/creator_exports.sh index 2790efb..5d8adcc 100755 --- a/creator_exports.sh +++ b/creator_exports.sh @@ -2,7 +2,17 @@ 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)" -export GUEST_API_URL="https://gitea.detee.cloud/ghe0/stuff/releases/download/v0.0.0/guest_api.zst" +[[ -n "$ROOT" ]] || + export ROOT="${script_dir}/build/initrd_root" +# you need busybox to be able to instsall +[[ -n "$BUSYBOX_PATH" ]] || + export BUSYBOX_PATH="/usr/lib/initcpio/busybox" +# choose a kernel if you don't want to use the active one +[[ -n "$KERNEL" ]] || + export KERNEL="$(uname -r)" +# this is the DeTEE Guest API that allows you to control the initrd +[[ -n "$GUEST_API_URL" ]] || + export GUEST_API_URL="https://gitea.detee.cloud/ghe0/stuff/releases/download/v0.0.0/guest_api.zst" +# this will allow you to grab modules from the machine where the installer is running +[[ -n "$GRAB_LOCAL_MODS" ]] || + export GRAB_LOCAL_MODS="no" diff --git a/creator_functions.sh b/creator_functions.sh index ec4a897..d630a19 100644 --- a/creator_functions.sh +++ b/creator_functions.sh @@ -135,8 +135,19 @@ _install_module() { done <<< "$( echo "$depends" )" } +backup_active_modules() { + local modules='' mod='' + echo_yellow "Installing to the initrd all kernel modules currently loaded..." + modules="$(lsmod | awk '{ print $1 }' | grep -v Module)" + while read -r mod; do + [[ -z $mod ]] && continue + _install_module "$mod" + done <<< "$( echo "$modules" )" +} + scan_modules() { local drivers='' mod='' + echo_yellow "Installing kernel modules based on current hardware..." install_module "$(df -T / | awk '{ print $2 }' | tail -1)" drivers=$(lshw -c disk 2>/dev/null | grep -oE 'driver=[a-z\_\-]+' | cut -d '=' -f2; @@ -158,7 +169,7 @@ install_guest_api() { create_archive() { local archive="detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz" - echo_cyan "Creating archive $archive" + echo_cyan "Creating archive build/$archive" echo $archive > .archive_name my_location="$(pwd)" cd ${ROOT} diff --git a/init.sh b/init.sh index 99bcfe3..cb4a9d3 100755 --- a/init.sh +++ b/init.sh @@ -35,4 +35,7 @@ try_hot_decrypt || { github_ssh_key detee_ssh_key +# copy kernel modules in case the user deleted the old modules +cp -rn /lib/modules/* /mnt/lib/modules/ + exec switch_root /mnt /sbin/init "$@" diff --git a/install.sh b/install.sh index 73edc1a..d5d7ab2 100755 --- a/install.sh +++ b/install.sh @@ -13,11 +13,11 @@ fi server="$1" scp_server="$1" -echo $1 | grep -F ':' && scp_server="[${1}]" +echo $1 | grep -F ':' > /dev/null && scp_server="[${1}]" if ! [ -z $2 ]; then server="${2}@${server}" - echo $1 | grep -F ':' && scp_server="${2}@${scp_server}" + echo $1 | grep -F ':' > /dev/null && scp_server="${2}@${scp_server}" fi if [ -z $3 ]; then @@ -28,15 +28,6 @@ else scp="scp -P $3" fi -echo "ssh: $ssh" -echo "scp: $scp" -echo "server: $server" -echo "scp_server: $scp_server" - -echo -echo Starting installation... -echo - set -e mkdir -p tmp @@ -45,7 +36,7 @@ $ssh $server rm -rf ${dir} $ssh $server mkdir -p ${dir} $scp tmp/dtrfs.tar ${scp_server}:${dir} $ssh $server tar -xf ${dir}/dtrfs.tar -C ${dir} -$ssh $server ${dir}/create.sh +$ssh $server GRAB_LOCAL_MODS=YES ${dir}/create.sh archive=$($ssh $server cat ${dir}/build/.archive_name) $scp ${scp_server}:${dir}/build/${archive} tmp/ echo