From bb4afc18c9fcb6250f11323b7f0f38a4415e6eb9 Mon Sep 17 00:00:00 2001 From: aheirman <48590738+aheirman@users.noreply.github.com> Date: Sun, 14 Feb 2021 18:34:51 +0100 Subject: [PATCH] Format partition to ext4 & cp packages there & switch_root --- build_utils | 27 +++++++++++++++++++++++++++ createimg.sh | 24 ++++++++++++++++++++++++ geninitrd.sh | 38 +++++++++++++++----------------------- 3 files changed, 66 insertions(+), 23 deletions(-) create mode 100755 build_utils diff --git a/build_utils b/build_utils new file mode 100755 index 0000000..7b69825 --- /dev/null +++ b/build_utils @@ -0,0 +1,27 @@ + + +cp_packages (){ + #IMPORTANT: must be run from the folder where the iglunix repo is. + #NOTE: this will assume that there always is a '*-dev'/'*-doc' package,\n this is not true. + # That's why the errors are shown to some one who cares. + + echo "Hello this is build-utils" + + + for pkg in ${packages[@]} + do + if [ ! -d pkgs/${pkg}/out ]; then + echo "NOTE: ${pkg} was not yet build, building it now" + cd pkgs/${pkg}/ + ../../iglupkg.sh + cd ../.. + fi + + echo "Going to copy: $pkg to $1" + tar -xf pkgs/${pkg}/out/${pkg}.*.tar.xz -C $1 + tar -xf pkgs/${pkg}/out/${pkg}-dev.*.tar.xz -C $1 2> /dev/null + tar -xf pkgs/${pkg}/out/${pkg}-doc.*.tar.xz -C $1 2> /dev/null + + done +} + diff --git a/createimg.sh b/createimg.sh index ea708a6..b1d0ea8 100755 --- a/createimg.sh +++ b/createimg.sh @@ -1,9 +1,13 @@ #!/bin/sh +echo "Createimg.sh" + rm iglunix.img dd if=../tiny-linux-bootloader/disk of=iglunix.img +source build_utils + FILE_SIZE=$(stat -c %s iglunix.img) echo "FILE_SIZE=${FILE_SIZE}" PARTITION_START=$(($FILE_SIZE / 512)) @@ -24,6 +28,26 @@ ${PARTITION_START} w " | fdisk iglunix.img +PARTITION_START2=$((${PARTITION_START} * 512)) +echo "PARTITION_START2: ${PARTITION_START2}" +LOOPBACK=$(losetup -o ${PARTITION_START2} -s -f iglunix.img) +echo "LOOPBACK: ${LOOPBACK}" +mke2fs -t ext4 -L "__IGLUNIX_ROOT" ${LOOPBACK} + +umount /mnt/__IGLUNIX_ROOT +rm -rf /mnt/__IGLUNIX_ROOT + +mkdir -p /mnt/__IGLUNIX_ROOT +mount ${LOOPBACK} /mnt/__IGLUNIX_ROOT + +packages=(musl mksh bmake gmake libressl cmake curl rsync flex byacc om4 zlib samurai libffi python ca-certificates zlib expat gettext-tiny git kati netbsd-curses kakoune iglunix rust toybox busybox less file pci-ids e2fsprogs) +cp_packages /mnt/__IGLUNIX_ROOT + +echo "Unmounting & closing loopback" + +umount /mnt/__IGLUNIX_ROOT + +losetup -d ${LOOPBACK} exit # losetup -o 32256 /dev/loop0 iglunix.img diff --git a/geninitrd.sh b/geninitrd.sh index b6c06df..5e1c6d6 100755 --- a/geninitrd.sh +++ b/geninitrd.sh @@ -11,37 +11,29 @@ # Create the root fs dir +echo "geninitrd.sh" + +source build_utils + rm -rf isoout isoroot mkdir isoroot mkdir isoout -cp_packages (){ - #NOTE: this will assume that there always is a '*-dev'/'*-doc' package,\n this is not true. - # That's why the errors are shown to some one who cares. - for pkg in ${packages[@]} - do - echo "Going to copy: $pkg to $1" - tar -xf pkgs/${pkg}/out/${pkg}.*.tar.xz -C $1 - tar -xf pkgs/${pkg}/out/${pkg}-dev.*.tar.xz -C $1 2> /dev/null - tar -xf pkgs/${pkg}/out/${pkg}-doc.*.tar.xz -C $1 2> /dev/null - done -} +# This should be a minimal number of packages, if we want fast boot times. +# The remaining packages are in createimg.sh #packages=(musl mksh bmake gmake libressl cmake curl rsync linux flex byacc om4 zlib samurai libffi python ca-certificates zlib expat gettext-tiny git kati netbsd-curses kakoune iglunix) packages=(musl linux mksh busybox toybox iglunix) cp_packages ./isoroot -#packages=(musl mksh busybox toybox llvm bmake gmake libressl cmake curl rsync linux flex byacc om4 zlib samurai libffi python ca-certificates zlib expat gettext-tiny git kati netbsd-curses kakoune iglunix rust less heirloom-doctools file pci-ids) -#cp_packages ./isoroot - cat >isoroot/init << EOF #!/bin/sh exec /sbin/init EOF rm isoroot/sbin/init -cat >isoroot/sbin/init << EOF +cat >isoroot/sbin/init << 'EOF' #!/bin/sh export PATH=/usr/sbin:/usr/bin:/sbin:/bin @@ -55,17 +47,17 @@ mount -t tmpfs tmpfs /tmp busybox mdev -s busybox mdev -d -exec /bin/sh - mkdir /mnt -# while not mount $(blkid -L IGLUNIX_BS_MEDIA) /mnt; do -# echo "Failed to mount boot disk" -# echo "Retrying" -# sleep 0.5 -# done +while ! mount $(findfs LABEL=__IGLUNIX_ROOT) /mnt; do + echo "Failed to mount boot disk" + echo "Retrying" + sleep 0.5 +done -exec switch_root /mnt + +echo "Starting switch_root" +exec switch_root /mnt /bin/sh EOF