From cc2e025ae02131ac6d715fa41a42444fd8a9a4a3 Mon Sep 17 00:00:00 2001 From: ghe0 Date: Fri, 8 Nov 2024 23:10:19 +0200 Subject: [PATCH] install OS from template --- create.sh | 13 ++++++++++++- creator_functions.sh | 17 +++++++++-------- init.sh | 12 +++++++++++- init_functions.sh | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/create.sh b/create.sh index 6c1dbd6..e4f8894 100755 --- a/create.sh +++ b/create.sh @@ -13,6 +13,10 @@ install_binary $(which switch_root) install_binary $(which bash) install_binary $(which mount) install_binary $(which openssl) && cp -r /etc/ssl "${ROOT}/etc/" +install_binary $(which cryptsetup) +install_binary $(which blkid) +install_binary $(which fdisk) +install_binary $(which mkfs.ext4) install_kmod install_busybox @@ -23,11 +27,18 @@ echo_cyan "Installing kernel modules..." # # Uncomment this section if you want to grab modules from the guest OS # scan_modules install_module virtio_net -install_module btrfs +install_module ext4 install_module virtio_blk install_module msr install_module sev-guest install_module dm_crypt +install_module hid-generic +install_module dm-integrity +install_module cbc +install_module hmac +install_module sha256 +install_module rng +install_module aes echo_cyan "Building module dependency tree..." cp /lib/modules/${KERNEL}/modules.{order,builtin,builtin.modinfo} "${ROOT}/lib/modules/${KERNEL}/" diff --git a/creator_functions.sh b/creator_functions.sh index 2f133ff..aba1235 100644 --- a/creator_functions.sh +++ b/creator_functions.sh @@ -25,6 +25,7 @@ create_dirs() { mkdir -p "${ROOT}/etc" mkdir -p "${ROOT}/proc" mkdir -p "${ROOT}/run" + mkdir -p "${ROOT}/sys" mkdir -p "${ROOT}/tmp" mkdir -p "${ROOT}/var" ln -s usr/bin "${ROOT}/bin" @@ -77,12 +78,12 @@ install_binary() { install_kmod() { echo_cyan "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 + 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() { @@ -99,8 +100,8 @@ install_busybox() { } install_init_script() { - cp ../init.sh ${ROOT}/init - cp ../init_functions.sh ${ROOT}/ + cp ../init.sh "${ROOT}/init" + cp ../init_functions.sh "${ROOT}/" } install_module() { diff --git a/init.sh b/init.sh index 2649351..9580f53 100755 --- a/init.sh +++ b/init.sh @@ -4,5 +4,15 @@ create_mounts load_modules create_certs setup_network -mount_root + +# TODO: replace hardcoded URL with guest_api +echo "http://192.168.122.226/base_arch2.tar.xz" > /tmp/install_url +if [[ -f "/tmp/install_url" ]]; then + install_os +else + mount_root +fi + +github_ssh_key + exec switch_root /mnt /sbin/init "$@" diff --git a/init_functions.sh b/init_functions.sh index 6c3eb91..7321f89 100644 --- a/init_functions.sh +++ b/init_functions.sh @@ -65,7 +65,40 @@ setup_network() { echo nameserver $nameserver > /etc/resolv.conf } +install_os() { + local url="$(cat /tmp/install_url)" + blkid | grep vda1 | grep ext4 && { + mount_root + return 0 + } + fdisk /dev/vda <