-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repeatable minimal boot linux with openssh & ip utils
- Loading branch information
1 parent
85de59d
commit 83b2098
Showing
13 changed files
with
239 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
INITAL_WORKING_DIR=$PWD | ||
|
||
git clone git://git.busybox.net/busybox | ||
|
||
cd busybox | ||
git checkout 1_37_0 | ||
make defconfig | ||
echo CONFIG_STATIC=y >> .config | ||
sed -i 's/CONFIG_TC=y/# CONFIG_TC is not set/g' .config | ||
make -j$(nproc) | ||
|
||
mkdir "$BUILD_ARTIFACTS_DIR"/busybox | ||
cp ./busybox "$BUILD_ARTIFACTS_DIR"/busybox | ||
|
||
cd $INITAL_WORKING_DIR |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
INITAL_WORKING_DIR=$PWD | ||
|
||
mkdir linux-kernel | ||
cd linux-kernel | ||
wget https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.9.tar.xz | ||
|
||
tar xf linux-6.9.tar.xz | ||
cd linux-6.9 | ||
mkdir -p $BUILD_ARTIFACTS_DIR/linux-kernel | ||
make defconfig | ||
make -j$(nproc) | ||
cp ./arch/x86_64/boot/bzImage $BUILD_ARTIFACTS_DIR/linux-kernel | ||
|
||
|
||
cd $INITAL_WORKING_DIR |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# Via https://wiki.musl-libc.org/getting-started.html | ||
|
||
set -xu | ||
|
||
INITAL_WORKING_DIR=$PWD | ||
|
||
git clone git://git.musl-libc.org/musl | ||
cd musl/ | ||
git checkout v1.2.5 | ||
./configure --prefix=$HOME/musl --exec-prefix=$HOME/bin --syslibdir=$HOME/musl/lib --disable-shared | ||
|
||
make | ||
make install | ||
|
||
|
||
cd $INITAL_WORKING_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# 1. clone openssh-portable | ||
git clone https://github.com/openssh/openssh-portable | ||
cd openssh-portable | ||
git checkout V_9_9_P1 | ||
autoconf | ||
|
||
# Note this uses only the **experimental** internal (reduced) cryp algos | ||
# built-into openssh. TODO actuall include libcrypto | ||
CC="musl-gcc -static" ./configure --prefix=/usr/bin --sysconfdir=/etc/ssh --without-zlib --without-openssl | ||
make -j$(nproc) | ||
|
||
# Copy over openssh binaries to build artifacts dir | ||
mkdir -p $BUILD_ARTIFACTS_DIR/openssh | ||
|
||
echo $PWD | ||
|
||
for sshUtility in $(find ./ -maxdepth 1 -type f -executable | grep -E -v '(\.sh|\.in|\.rc|\.sub|\.sample|\.status|\.guess|configure|fixpaths|install-sh|mkinstalldirs|fixalgorithms)'); do | ||
echo Copying over "$sshUtility" | ||
cp "$sshUtility" $BUILD_ARTIFACTS_DIR/openssh | ||
done | ||
|
||
cp $(find ./ -name sshd_config) $BUILD_ARTIFACTS_DIR/openssh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
#!/bin/bash | ||
#!/bin/sh | ||
|
||
set -eux | ||
|
||
echo "#!/usr/bin/bash" > scratch-space/init | ||
echo "exec /usr/bin/bash" >> scratch-space/init | ||
chmod +x scratch-space/init | ||
INIT_FILE_PATH=scratch-space/init | ||
|
||
echo "#!/bin/busybox sh" > $INIT_FILE_PATH | ||
echo 'echo YOLOOooooooooooooooooooooooooooo' >> $INIT_FILE_PATH | ||
echo 'echo YOLOOooooooooooooooooooooooooooo' >> $INIT_FILE_PATH | ||
echo 'echo YOLOOooooooooooooooooooooooooooo' >> $INIT_FILE_PATH | ||
echo 'echo YOLOOooooooooooooooooooooooooooo' >> $INIT_FILE_PATH | ||
echo 'echo YOLOOooooooooooooooooooooooooooo' >> $INIT_FILE_PATH | ||
echo 'mount -t sysfs sysfs /sys' >> $INIT_FILE_PATH | ||
echo 'mount -t proc proc /proc' >> $INIT_FILE_PATH | ||
# (sshd needs openpty: No such file or directory ) | ||
echo 'mount -t devtmpfs udev /dev' >> $INIT_FILE_PATH | ||
echo 'mkdir /dev/pts' >> $INIT_FILE_PATH | ||
echo 'mount -t devpts devpts /dev/pts' >> $INIT_FILE_PATH | ||
echo 'sysctl -w kernel.printk="2 4 1 7"' >> $INIT_FILE_PATH | ||
echo 'chown -R root:root /var/empty' >> $INIT_FILE_PATH | ||
echo 'chmod -R 400 /var/empty' >> $INIT_FILE_PATH | ||
|
||
echo 'echo Bringing up loopback interface' >> $INIT_FILE_PATH | ||
echo 'ip link set lo up' >> $INIT_FILE_PATH | ||
echo 'ip addr show lo' >> $INIT_FILE_PATH | ||
|
||
echo 'echo Generating ssh host keys' >> $INIT_FILE_PATH | ||
echo 'ssh-keygen -A' >> $INIT_FILE_PATH | ||
echo 'ls -l /etc/ssh' >> $INIT_FILE_PATH | ||
|
||
echo 'echo Starting sshd' >> $INIT_FILE_PATH | ||
echo '/usr/bin/sshd -E ssh_log' >> $INIT_FILE_PATH | ||
|
||
# Curious? See https://github.com/brgl/busybox/blob/master/shell/cttyhack.c | ||
echo 'setsid cttyhack /bin/sh' >> $INIT_FILE_PATH | ||
|
||
chmod +x $INIT_FILE_PATH | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
INITAL_WORKING_DIR=$PWD | ||
SCRATCH_DIR=./scratch-space | ||
BUILD_ARTIFACTS_FOLDER=../build-dir/build-artifacts | ||
|
||
rm -rf "$SCRATCH_DIR" | ||
mkdir "$SCRATCH_DIR" | ||
|
||
cd $SCRATCH_DIR | ||
|
||
|
||
mkdir bin dev proc sys etc root usr var | ||
mkdir -p usr/bin/libexec # (sshd-session by (default?) compiles into /usr/bin/libexec | ||
mkdir -p etc/ssh | ||
mkdir -p var/run # (otherwise sshd cannot write its pid file) | ||
|
||
# Crate users/groups | ||
|
||
echo 'root:x:0:' > ./etc/group | ||
|
||
# Copy over busybox | ||
cp "$BUILD_ARTIFACTS_FOLDER"/busybox/busybox ./bin | ||
cd ./bin | ||
for utility in $(./busybox --list); do | ||
ln -s ./busybox ./$utility | ||
done | ||
cd - | ||
|
||
# ssh/sshd etc bootstraping | ||
|
||
# Copy over default sshd_config config | ||
cp "$BUILD_ARTIFACTS_FOLDER"/openssh/sshd_config ./etc/ssh/sshd_config | ||
|
||
for sshUtility in $(find "$BUILD_ARTIFACTS_FOLDER"/openssh -maxdepth 1 -type f -executable | grep -E -v '(\.sh|\.in|\.rc|\.sub|\.sample|\.status|\.guess|configure|fixpaths|install-sh|mkinstalldirs|fixalgorithms)'); do | ||
|
||
echo Copying over "$sshUtility" | ||
cp "$sshUtility" ./usr/bin | ||
done | ||
mv ./usr/bin/sshd-session ./usr/bin/libexec | ||
|
||
# Bootstrap ssh users/config setup | ||
|
||
cd - && cd ../ | ||
echo $PWD | ||
|
||
# Layout minimal user accounts | ||
echo 'root:x:0:0:root:/root:/bin/sh' > ./etc/passwd | ||
# Without sshd user, you get 'Privilege separation user sshd does not exist' | ||
echo 'sshd:x:128:65534::/run/sshd:/usr/sbin/nologin' >> ./etc/passwd | ||
|
||
echo 'root:*:19216:0:99999:7:::' > ./etc/shadow | ||
|
||
echo 'echo 'root:x:0:' > ./etc/groups' | ||
mkdir var/empty # TODO Missing privilege separation directory: /var/empty (sshd wants it) | ||
# NOTE ownership of /var/empty is altered during init | ||
|
||
|
||
# TODO generate host keys (ssh-keygen -A) | ||
|
||
cd $INITAL_WORKING_DIR | ||
|
||
./create-init.sh |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters