commit: 2cae4bd941ef9cfa552ddf2da92017cdc6da9b59
parent 2e86b75877467429483d21dd4fb04b1e22c2d082
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 30 Apr 2024 17:26:55 +0200
Switch to APKs for binary seed
Diffstat:
8 files changed, 108 insertions(+), 33 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -4,3 +4,7 @@
/initramfs-tcc
/initramfs-tcc.cpio.xz
+/container-tcc
+/distfiles
+/*-stub
+/mrsh_tcc.h
diff --git a/README.md b/README.md
@@ -7,7 +7,7 @@ SPDX-License-Identifier: MPL-2.0
A initrd generator for Linux to bootstrap a POSIX-ish system from a reasonably small binary seed.
Full source bootstrap isn't intended as a goal but no further binaries than TCC and musl are allowed (enforced by [deblob](https://hacktivis.me/projects/deblob)). A possible further goal could be to try stripping out as much unreviewable code like autoconf loves to generate.
-Status: Very early experiments, has yet to build enough to bootstrap any distro, generator very likely doesn't runs on your machine.
+Status: Very early experiments, has yet to build enough to bootstrap any distro.
## Rationales
Each of those roughly by their build order.
@@ -70,7 +70,7 @@ Meanwhile:
## Launching in QEMU
```
-$ qemu-system-x86_64 -enable-kvm -cpu host -m 1536 -kernel /boot/vmlinuz-6.6.21-gentoo -initrd /tmp/initramfs-tcc.cpio.xz -append 'init=/init console=ttyS0 panic=1' -nographic -no-reboot
+$ qemu-system-x86_64 -enable-kvm -m 512 -kernel /boot/vmlinuz-6.6.21-gentoo -initrd /tmp/initramfs-tcc.cpio.xz -append 'init=/init console=ttyS0 panic=1' -nographic -no-reboot
```
* Combination of `panic=1` and `-no-reboot` allows to exit+relaunch
diff --git a/common.sh b/common.sh
@@ -0,0 +1,20 @@
+APKS_main="
+ musl-1.2.5-r0.apk
+ musl-dev-1.2.5-r0.apk
+ musl-libintl-1.2.5-r0.apk
+"
+APKS_testing="
+ tcc-0.9.27_git20240117-r0.apk
+ tcc-libs-0.9.27_git20240117-r0.apk
+ tcc-dev-0.9.27_git20240117-r0.apk
+ tcc-libs-static-0.9.27_git20240117-r0.apk
+"
+ALPINE_MIRROR="http://dl-cdn.alpinelinux.org/alpine"
+# Alpine edge is definitely not a good way to do it but I need TCC with musl and /testing/ means edge-only
+ALPINE_BRANCH="edge"
+ALPINE_ARCH="x86_64"
+
+die() {
+ echo "[Error] die: ${*}"
+ exit 1
+}
diff --git a/distfiles.SHA512SUM b/distfiles.SHA512SUM
@@ -0,0 +1,18 @@
+50622aee8024b3e0385974a8f446a4b5df0ba494b6133ab91ebbe63c408154b112f62c9df8521f4f1beaf28cdd6e7da178c3334337f6b14c8bced532029d8ba5 distfiles/bmake-20230909.tar.gz
+083f5e675d73f3233c7930ebe20425a533feedeaaa9d8cc86831312a6581cefbe6ed0d08d2fa89be81082f2a5abdabca8b3c080bf97218a1bd59dc118a30b9f3 distfiles/bzip2-1.0.8.tar.gz
+a054917c975f65dfb5f8eb35665044ddacacdbd2d1e1113e6bf62d5cd8d5f4fd775ff5f20e28191d2417016684a310f23115af102b834aa33083e2be41034477 distfiles/loksh-7.3.tar.xz
+9d81ba58f5460e341d9de7c4b2af38c7bf39ae40fdcfac1652e7ad64bd903d58222128880daeb30ef5c1726a244d815ab9c7b22b9cb92c7aeaaa7728f29c4116 distfiles/minised-1.16.tar.gz
+6acd3ee911442934082f4f877d795b07c5e23022eaa9c0874799d97e92a2f5a663cb45f94b7f9745c49cbbce6b7e755a29e381ccfb9e68a0be1eedbd22fd5d3b distfiles/mk-20210330.tar.gz
+8bb997e077850195621916ee0722be7e054086fa5c2907c7d290ee8892910c073e3aece13a2839589966987711f4af6b2f4bffdc6c45d636a24655ef9cbec101 distfiles/musl-1.2.5-r0.apk
+5d93191c3c9bf03b466dc169b57e519f0165c6551d117ae09538907c57a49f58afa3c9225aafc7a61625f224276eff4ee2dbe79d65cf684d03a46c24dd78aa4c distfiles/musl-dev-1.2.5-r0.apk
+dacee8ce46c236fcc09ae767bd2f1bc1dfcba026a49134cb8f915d2d4ad31eb089fc8edeb8b1027276a9450ca14be56043747c93acbcbab334efa1bd20069084 distfiles/musl-libintl-1.2.5-r0.apk
+3d5626b0d6033a9eb8f3d81acbe0b30842e99f4c40563ca3f906ecfebdb72d754de18cd180345131868ad325fead4a6e66bfb765af45267180e256f46a76f316 distfiles/nawk-20240422.tar.gz
+a64d6dcf3f4319cf40af684d0775f8c7e3a21e07a5262fc83b588bf7ea85f2e91d2d171307c93734799af59e1dc50c498543356c78cbaf7fb721a14f71f128c2 distfiles/om4-6.7.tar.gz
+ae3d9d593e1645d65f9ab77aa828600c9af4bb30d0a073da7ae3dd805e65b87efaf6a0efb980f2d0168e475ae506eba194547d6479956dabb9d88293a9078a7f distfiles/pigz-2.8.tar.gz
+87b951c39d35684bb7c8ddb9952009294de1f39ae3632a8cb5d27233fa1ef2551af1cd5d7c10220c0035011c68569bc85c382878180bb51d3a55241646e587ee distfiles/tcc-0.9.27_git20240117-r0.apk
+a9329a3fccbdeb033c2352355e4ac09d7d1bde62e375d9e13ee8c4e2c5c67b923f770e8d54b4b25fadbd5f74d46132f781d618db6b3e6fdb3db60222dc746217 distfiles/tcc-dev-0.9.27_git20240117-r0.apk
+6511c496d31d33ad7a14f1be6dee3383ffd178046fc6a717f63ccfe8b65174c4a49a48b08eea5ab0e751e93daf59d0979fd6020329d26e54523b1a8d623cd66e distfiles/tcc-libs-0.9.27_git20240117-r0.apk
+b89b489fbee7c19a21175ad61168d250856801175fa000261b35202312148ee8e7b6cb1994d042503ad36f2651ee1ba68c4f83d96051abb50fb4e0e5dbc78960 distfiles/tcc-libs-static-0.9.27_git20240117-r0.apk
+dae7980af4686e8375fbe46455b378e4e694cf00cbceebbbc20a692dd3f0d0a1fc09bbf7efdf3c7d9875e90192cd0ecf4fa3095c170259c4825009191986d4d6 distfiles/utils-std-f998e53.tar.gz
+6adb51c5f07e8084a86688589f52d9eee0183fb4d77508e36621a6b0ba91a5c4195feb87db3401ec69560554f71f2f6984dec01266e41e0fd54fa72ef1780e80 distfiles/yacc-1.9.1.tar.Z
+1e8e70b362d64a233591906a1f50b59001db04ca14aaffad522198b04680be501736e7d536b4191e2f99767e7001ca486cd802362cca2be05d5d409b83ea732d distfiles/zlib-1.3.1.tar.xz
diff --git a/fetch.sh b/fetch.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+URLS="
+ https://hacktivis.me/releases/utils-std-f998e53.tar.gz
+ http://void.crufty.net/ftp/pub/sjg/bmake-20230909.tar.gz
+ http://void.crufty.net/ftp/pub/sjg/mk-20210330.tar.gz
+ http://dl.exactcode.de/oss/minised/minised-1.16.tar.gz
+ https://distfiles.gentoo.org/distfiles/ec/yacc-1.9.1.tar.Z
+ https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
+ https://zlib.net/zlib-1.3.1.tar.xz
+ https://www.zlib.net/pigz/pigz-2.8.tar.gz
+"
+WORKDIR="$(dirname "$0")"
+
+. "${WORKDIR}/common.sh"
+
+set -ex
+
+mkdir -p "${WORKDIR}/distfiles"
+cd "${WORKDIR}/distfiles"
+
+for url in $URLS
+do
+ file="$(basename "$url")"
+ test -e "$file" || curl -L -o "$file" "$url"
+done
+
+for apk in $APKS_main
+do
+ test -e "$apk" || curl -L -o "$apk" "${ALPINE_MIRROR}/${ALPINE_BRANCH}/main/${ALPINE_ARCH}/${apk}"
+done
+
+for apk in $APKS_testing
+do
+ test -e "$apk" || curl -L -o "$apk" "${ALPINE_MIRROR}/${ALPINE_BRANCH}/testing/${ALPINE_ARCH}/${apk}"
+done
+
+# Only has ./CVS and .travis-ci.yml removed compared to Github autogenerated tarball
+test -e om4-6.7.tar.gz || curl -L -o om4-6.7.tar.gz https://github.com/ibara/m4/releases/download/om4-6.7/om4-6.7.tar.gz
+
+test -e nawk-20240422.tar.gz || curl -L -o nawk-20240422.tar.gz https://github.com/onetrueawk/awk/archive/20240422.tar.gz
+
+# TODO: Sanity check between provided tarball and github-generated tarball
+test -e loksh-7.3.tar.xz || curl -L -o loksh-7.3.tar.xz https://github.com/dimkr/loksh/releases/download/7.3/loksh-7.3.tar.xz
+
+cd -
+
+sha512sum -c distfiles.SHA512SUM
diff --git a/init.c b/init.c
@@ -62,7 +62,7 @@ e_mknod(const char *path, mode_t mode, dev_t dev)
int
main(int argc, char *argv[])
{
- setenv("PATH", "/bin", 1);
+ setenv("PATH", "/bin:/usr/bin:/usr/local/bin", 1);
if(build_loksh() < 0) return 1;
if(mount("sysfs", "/sys", "sysfs", MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_RELATIME, NULL) < 0)
diff --git a/make-initrd.sh b/make-initrd.sh
@@ -3,16 +3,14 @@
# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
-WORKDIR="$(pwd)"
+WORKDIR="$(dirname "$0")"
+WORKDIR="$(realpath "$WORKDIR")"
name_base="initramfs-tcc"
out_base="${WORKDIR}/${name_base}"
-die() {
- echo "[Error] die: ${*}"
- exit 1
-}
+. "$WORKDIR/common.sh"
-set -e
+set -ex
./make-root.sh || die "Failed: make-root"
@@ -20,6 +18,7 @@ cd "$out_base" || die "Failed: cd $out_base"
deblob -n
-find . -print0 | cpio --null -o --format=newc | xz -9 --check=crc32 > "${out_base}.cpio.xz"
+find . -print0 | cpio --null -o --format=newc > "${out_base}.cpio"
+xz -9 --check=crc32 -f -k "${out_base}.cpio"
cd "${WORKDIR}"
diff --git a/make-root.sh b/make-root.sh
@@ -3,7 +3,6 @@
# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
-#elves="mksh"
tarballs="
utils-std-f998e53.tar.gz
mk-20210330.tar.gz
@@ -16,26 +15,26 @@ tarballs="
zlib-1.3.1.tar.xz
pigz-2.8.tar.gz
"
-WORKDIR="$(pwd)"
+WORKDIR="$(dirname "$0")"
+WORKDIR="$(realpath "$WORKDIR")"
name_base="initramfs-tcc"
out_base="${WORKDIR}/${name_base}"
-die() {
- echo "[Error] die: ${*}"
- exit 1
-}
+. "$WORKDIR/common.sh"
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 '"%s", ' /usr/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"
}
set -e
+sha512sum -c distfiles.SHA512SUM
+
if test -e "$out_base"; then
rm -fr "$out_base"
fi
@@ -43,7 +42,7 @@ mkdir -p "$out_base" || die "Failed: mkdir $out_base"
cd "$out_base" || die "Failed: cd $out_base"
for i in $tarballs; do
- tar xf "/var/cache/distfiles/$i" || die "Failed extracting $i"
+ tar xf "${WORKDIR}/distfiles/$i" || die "Failed extracting $i"
done
rm yacc-1.9.1/yacc || die
@@ -54,21 +53,12 @@ ln -s /proc/mounts etc/mtab || die "Failed symlink for /etc/mtab"
ln -s . usr
chmod 777 tmp
-for elf in $elves; do
- origin=$(command -v "$elf")
- cp "$origin" bin/ || die
-done
-
-for lib in $(find bin -type f -exec lddtree -l {} + | grep -v bin/ | sort | uniq); do
- cp "$lib" lib/ || die
-done
-
for i in fd stderr stdin stdout; do
ln -fs proc/self/$i dev/$i
done
cp "${WORKDIR}/init.c" ./init || die "copying init"
-sed -i '1i#!/bin/tcc -run' ./init || die "failed adding tcc shebang to init"
+sed -i '1i#!/usr/bin/tcc -run' ./init || die "failed adding tcc shebang to init"
chmod 755 init || die "init chmod"
for i in init.sh ls-stub.c mv-stub.c grep-stub.c cp-stub.c
@@ -76,12 +66,9 @@ do
cp -p "${WORKDIR}/$i" ./ || die "failed copying $i"
done
-QMERGE=1 qmerge -yOKv --root $PWD dev-lang/tcc || die "Failed qmerge'ing tcc"
-
-qlist musl | grep -v -e /bin/ -e /etc/ -e /sbin/ | while read f
+for apk in $APKS_main $APKS_testing
do
- mkdir -p "$(dirname "./$f")" || die
- cp -pr "$f" "./$f" || die
+ tar xf "${WORKDIR}/distfiles/$apk" --exclude '.*'
done
# For CLOCK_MONOTONIC and clock_gettime