allow dtrfs to grab local mods from OS

This commit is contained in:
ghe0 2024-11-12 20:26:11 +02:00
parent ced0d86c4c
commit 68e25068b5
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
5 changed files with 38 additions and 20 deletions

@ -25,9 +25,7 @@ install_guest_api
echo_cyan "Installing scripts..." echo_cyan "Installing scripts..."
install_init_script install_init_script
echo_cyan "Installing kernel modules..." echo_cyan "Installing kernel modules mandatory for DTRFS..."
# # Uncomment this section if you want to grab modules from the guest OS
# scan_modules
install_module virtio_net install_module virtio_net
install_module ext4 install_module ext4
install_module virtio_blk install_module virtio_blk
@ -42,6 +40,11 @@ install_module sha256
install_module rng install_module rng
install_module aes install_module aes
[[ "$GRAB_LOCAL_MODS" == "YES" ]] && {
scan_modules
backup_active_modules
}
echo_cyan "Building module dependency tree..." echo_cyan "Building module dependency tree..."
cp /lib/modules/${KERNEL}/modules.{order,builtin,builtin.modinfo} "${ROOT}/lib/modules/${KERNEL}/" cp /lib/modules/${KERNEL}/modules.{order,builtin,builtin.modinfo} "${ROOT}/lib/modules/${KERNEL}/"
depmod -b "$ROOT" "$KERNEL" depmod -b "$ROOT" "$KERNEL"

@ -2,7 +2,17 @@
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# root of the initrd, that will be used to create the cpio archive # root of the initrd, that will be used to create the cpio archive
[[ -n "$ROOT" ]] ||
export ROOT="${script_dir}/build/initrd_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" 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)" 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" 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"

@ -135,8 +135,19 @@ _install_module() {
done <<< "$( echo "$depends" )" 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() { scan_modules() {
local drivers='' mod='' local drivers='' mod=''
echo_yellow "Installing kernel modules based on current hardware..."
install_module "$(df -T / | awk '{ print $2 }' | tail -1)" install_module "$(df -T / | awk '{ print $2 }' | tail -1)"
drivers=$(lshw -c disk 2>/dev/null | grep -oE 'driver=[a-z\_\-]+' | cut -d '=' -f2; drivers=$(lshw -c disk 2>/dev/null | grep -oE 'driver=[a-z\_\-]+' | cut -d '=' -f2;
@ -158,7 +169,7 @@ install_guest_api() {
create_archive() { create_archive() {
local archive="detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz" local archive="detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz"
echo_cyan "Creating archive $archive" echo_cyan "Creating archive build/$archive"
echo $archive > .archive_name echo $archive > .archive_name
my_location="$(pwd)" my_location="$(pwd)"
cd ${ROOT} cd ${ROOT}

@ -35,4 +35,7 @@ try_hot_decrypt || {
github_ssh_key github_ssh_key
detee_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 "$@" exec switch_root /mnt /sbin/init "$@"

@ -13,11 +13,11 @@ fi
server="$1" server="$1"
scp_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 if ! [ -z $2 ]; then
server="${2}@${server}" server="${2}@${server}"
echo $1 | grep -F ':' && scp_server="${2}@${scp_server}" echo $1 | grep -F ':' > /dev/null && scp_server="${2}@${scp_server}"
fi fi
if [ -z $3 ]; then if [ -z $3 ]; then
@ -28,15 +28,6 @@ else
scp="scp -P $3" scp="scp -P $3"
fi fi
echo "ssh: $ssh"
echo "scp: $scp"
echo "server: $server"
echo "scp_server: $scp_server"
echo
echo Starting installation...
echo
set -e set -e
mkdir -p tmp mkdir -p tmp
@ -45,7 +36,7 @@ $ssh $server rm -rf ${dir}
$ssh $server mkdir -p ${dir} $ssh $server mkdir -p ${dir}
$scp tmp/dtrfs.tar ${scp_server}:${dir} $scp tmp/dtrfs.tar ${scp_server}:${dir}
$ssh $server tar -xf ${dir}/dtrfs.tar -C ${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) archive=$($ssh $server cat ${dir}/build/.archive_name)
$scp ${scp_server}:${dir}/build/${archive} tmp/ $scp ${scp_server}:${dir}/build/${archive} tmp/
echo echo