diff --git a/create.sh b/create.sh index 568e7c4..76f5841 100755 --- a/create.sh +++ b/create.sh @@ -8,5 +8,8 @@ cd build echo_blue "Starting installation at $ROOT." -install_busybox || exit 1 +install_busybox +install_binary $(which modprobe) +install_binary $(which switch_root) +install_init_script create_archive diff --git a/creator_functions.sh b/creator_functions.sh index 079bca8..999571d 100644 --- a/creator_functions.sh +++ b/creator_functions.sh @@ -8,15 +8,14 @@ echo_red() { echo -e "\033[0;31m$1\033[0m" } - # Installs a library. Expects absolute path. install_lib() { local lib="$1" [[ -f "$lib" ]] || { echo "Did not find library at path: $lib" - return 1 + exit 1 } - + mkdir -p $(dirname "${ROOT}${lib}") echo_blue "Adding library to root: $lib" cp "$lib" "${ROOT}${lib}" @@ -29,7 +28,7 @@ install_binary() { local binary="$1" lib='' [[ -f "$binary" ]] || { echo_red "Did not find binary at path: $binary" - return 1 + exit 1 } echo_blue "Adding binary to root: $binary" @@ -50,14 +49,20 @@ install_busybox() { [[ -f "$BUSYBOX_PATH" ]] || { echo_red "Did not find busybox at $BUSYBOX_PATH" echo_red "Please compile or download busybox. You can also change the path." - return 1 + exit 1 } - install_binary "$BUSYBOX_PATH" + install_binary "$BUSYBOX_PATH" || return 1 for applet in $(/usr/lib/initcpio/busybox --list); do ln -s busybox "${ROOT}/usr/bin/$applet" done } +install_init_script() { + cp ../init.sh ${ROOT}/init + cp ../init_functions.sh ${ROOT}/ +} + create_archive() { + echo_blue "Creating archive..." find . | cpio -o -H newc | gzip > detee-$(hostnamectl hostname)-$(uname -r).cpio.gz } diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..06a02cc --- /dev/null +++ b/init.sh @@ -0,0 +1,5 @@ +#!/bin/bash +source /init_functions.sh +load_modules +mount_root +exec switch_root /mnt /sbin/init "$@" diff --git a/init_functions.sh b/init_functions.sh new file mode 100644 index 0000000..cc034fe --- /dev/null +++ b/init_functions.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +echo_blue() { + echo -e "\033[34m$1\033[0m" +} + +echo_red() { + echo -e "\033[0;31m$1\033[0m" +} + +load_modules() { + modprobe btrfs msr sev-guest || exit 1 +} + +create_mounts() { + mount -t proc proc /proc -o nosuid,noexec,nodev + mount -t sysfs sys /sys -o nosuid,noexec,nodev + mount -t devtmpfs dev /dev -o mode=0755,nosuid + mount -t tmpfs run /run -o nosuid,nodev,mode=0755 + mkdir -m755 /run/initramfs + + if [ -e /sys/firmware/efi ]; then + mount -t efivarfs efivarfs /sys/firmware/efi/efivars -o nosuid,nodev,noexec + fi + + # Setup /dev symlinks + if [ -e /proc/kcore ]; then + ln -sfT /proc/kcore /dev/core + fi + ln -sfT /proc/self/fd /dev/fd + ln -sfT /proc/self/fd/0 /dev/stdin + ln -sfT /proc/self/fd/1 /dev/stdout + ln -sfT /proc/self/fd/2 /dev/stderr +} + +mount_root() { + mount /dev/vda1 /mnt +}