logo

bootstrap-initrd

Linux initrd generator to bootstrap a POSIX-ish system from a reasonably small binary seed git clone https://hacktivis.me/git/make-initrd.git
commit: d4d7c943e5855c502baed180ea769e4db2594242
parent 0fba2f7e0b0c48fb36af12677fb53c1ce76d8b3c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 28 Apr 2024 15:56:06 +0200

replace mrsh with loksh, drop mksh

Diffstat:

MREADME.md8+++-----
Minit.c18+++++++++---------
Minit.sh10+++++-----
Mmake-initrd.sh26+++++++++++++++++---------
4 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/README.md b/README.md @@ -18,12 +18,10 @@ The reason to not pick Guile+MesCC instead is because I find Guile Scheme to be ### musl (binary) Need a libc to start somewhere, tryhards could maybe compile it from source with TCC to reduce the seed further but this hasn't been tried. -### mksh (binary) -Temporary workaround to mrsh lack of working interactivity in the console (Due to some missing TTY initialization?). - -### mrsh -emersion POSIX shell, somewhat incomplete but buildable with only a C Compiler. +### loksh +Linux/portable-port of OpenBSD Korn Shell, buildable with only a C compiler while being nicely complete (maybe even too much). Meanwhile: +- mrsh: Too incomplete for actual use, but trivial to build with only a C Compiler - heirloom-sh: Also buildable with only a C Compiler but fails to allocate memory at launch - bash, yash: autoconf, so needs an existing shell - dash: autoconf and generator scripts, so needs an existing shell diff --git a/init.c b/init.c @@ -13,7 +13,7 @@ #include <sys/mount.h> #include <fcntl.h> // O_RDONLY -#include "mrsh_tcc.h" +#include "loksh_tcc.h" static int exec_wait(char *args[]) @@ -35,15 +35,15 @@ exec_wait(char *args[]) } static int -build_mrsh() +build_loksh() { - chdir("/mrsh-a858396b79ba217760b0982dd6f45c91c5192c3b"); + chdir("/loksh-7.3"); - fprintf(stderr, "Compiling mrsh\n"); + fprintf(stderr, "Compiling loksh-7.3\n"); - if(exec_wait(mrsh_tcc_cmd) < 0) return -1; + if(exec_wait(loksh_tcc_cmd) < 0) return -1; - fprintf(stderr, "Compiled mrsh !\n"); + fprintf(stderr, "Compiled loksh !\n"); return 0; } @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) { setenv("PATH", "/bin", 1); - if(build_mrsh() < 0) return 1; + if(build_loksh() < 0) return 1; if(mount("sysfs", "/sys", "sysfs", MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_RELATIME, NULL) < 0) fprintf(stderr, "Failed to mount /sys: %s\n", strerror(errno)); @@ -70,11 +70,11 @@ main(int argc, char *argv[]) if(mount("devtmpfs", "/dev", "devtmpfs", MS_NOSUID|MS_NOEXEC, NULL) < 0) fprintf(stderr, "Failed to mount /proc: %s\n", strerror(errno)); - fprintf(stderr, "Launching: /bin/mrsh /init.sh\n"); + fprintf(stderr, "Launching: /bin/loksh /init.sh\n"); setenv("PS1", "> ", 1); - if(execl("/bin/mrsh", "/bin/mrsh", "/init.sh", NULL) < 0) + if(execl("/bin/loksh", "/bin/loksh", "/init.sh", NULL) < 0) { fprintf(stderr, "Failed to execute: %s\n", strerror(errno)); return 1; diff --git a/init.sh b/init.sh @@ -1,11 +1,10 @@ -#!/bin/mrsh +#!/bin/loksh die() { echo "die: $*" rescueshell } rescueshell() { - # Note: Strip out -l on switching back to mrsh exec $SHELL -l } @@ -55,7 +54,8 @@ cd /yacc-*/ $CC $CFLAGS -o /bin/yacc *.c cd /utils-std-*/ -mrsh ./makeless.sh +M4="true" loksh ./makeless.sh +./cmd/ln -s test './cmd/[' profile_export PATH="$PATH:$PWD/cmd/" profile_export YACC="yacc" @@ -63,8 +63,8 @@ profile_export YACC="yacc" profile_export CC="$CC" profile_export CFLAGS="$CFLAGS" -export SHELL="/bin/mksh" -ln -s $SHELL /bin/sh || die "Failed creating /bin/sh symlink" +export SHELL="/bin/loksh" +ln -s loksh /bin/sh || die "Failed creating /bin/sh symlink" cd /minised-1.16 $CC $CFLAGS sedcomp.c sedexec.c -o /bin/sed diff --git a/make-initrd.sh b/make-initrd.sh @@ -2,7 +2,7 @@ # Copyright 2017 Haelwenn (lanodan) Monnier <contact@hacktivis.me> # SPDX-License-Identifier: ISC -elves="mksh" +#elves="mksh" tarballs=" utils-std-656199b.tar.gz mk-20210330.tar.gz @@ -11,7 +11,7 @@ tarballs=" yacc-1.9.1.tar.Z byacc-20240109.tgz nawk-20240422.tar.gz - mrsh-a858396b79ba217760b0982dd6f45c91c5192c3b.tar.gz + loksh-7.3.tar.xz " WORKDIR="$(pwd)" name_base="initramfs-tcc" @@ -22,12 +22,12 @@ die() { exit 1 } -gen_mrsh_tcc_h() { - cd mrsh-a858396b79ba217760b0982dd6f45c91c5192c3b || die - printf 'char *mrsh_tcc_cmd[] = {' - printf -- '"%s", ' /bin/tcc -Iinclude -o /bin/mrsh - find -name '*.c' | grep -v readline | grep -v example | sed -e 's;^./;";' -e 's;$;",;' | tr '\n' ' ' | sed 's;$;NULL;' - printf '};' +gen_loksh_tcc_h() { + cd loksh-*/ || die + printf 'char *loksh_tcc_cmd[] = {' + # -DSMALL to not need ncurses + printf '"%s", ' /bin/tcc -D_GNU_SOURCE -DEMACS -DVI -DSMALL -DHAVE_STRLCPY -DHAVE_STRLCAT -DHAVE_ISSETUGID -I./subprojects/lolibc/include/ -o /bin/loksh *.c subprojects/lolibc/sys_signame.c subprojects/lolibc/strsignals.c subprojects/lolibc/unvis.c subprojects/lolibc/vis.c subprojects/lolibc/strtonum.c + printf 'NULL};' cd "$out_base" || die "Failed: cd $out_base" } @@ -81,7 +81,15 @@ do cp -pr "$f" "./$f" || die done -gen_mrsh_tcc_h > mrsh_tcc.h +# For CLOCK_MONOTONIC and clock_gettime +sed -i -e '1a#include <time.h>' loksh-*/c_sh.c || die "Failed patching loksh/c_sh.c" +# For u_char +sed -i -e '1a#include <sys/types.h>' loksh-*/edit.c || die "Failed patching loksh/c_sh.c" +# For int64_t +sed -i -e '1a#include <stdint.h>' loksh-*/table.h || die "Failed patching loksh/table.h" +sed -i -e '1a#include <limits.h>' -e 's;_PW_NAME_LEN;LOGIN_NAME_MAX;' loksh-*/main.c || die "Failed patching loksh/main.c" + +gen_loksh_tcc_h > loksh_tcc.h deblob -n