Skip to content

Instantly share code, notes, and snippets.

@brandonros
Last active October 27, 2023 02:12
Show Gist options
  • Save brandonros/b840f32a4e636b9679b3107f358777c0 to your computer and use it in GitHub Desktop.
Save brandonros/b840f32a4e636b9679b3107f358777c0 to your computer and use it in GitHub Desktop.
rush + c-ward + eyra + mustang proof of concept

rush + c-ward + eyra + mustang proof of concept

Build kernel

# start clean kubernetes pod
kubectl run -n default alpine --restart=Never --rm -i --tty --image=alpine:3.18 -- /bin/bash
# install dependencies to build kernel
apk update && apk add bash curl make gcc musl-dev linux-headers g++ build-base ncurses-dev openssl-dev elfutils-dev bc diffutils perl
# change shells
/bin/bash
# change directories
cd /root
# pull + extract sources
curl -O https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.5.9.tar.xz &&
tar -xf linux-6.5.9.tar.xz &&
rm linux-6.5.9.tar.xz &&
cd linux-6.5.9
# build config
make defconfig ARCH=x86_64 V=1
# build bzImage
make -j$(nproc) bzImage ARCH=x86_64 V=1
# in another tab: kubectl cp default/alpine:/root/linux-6.5.9/arch/x86/boot/bzImage ./bzImage
exit

Build userspace

# start clean kubernetes pod
kubectl run -n default debian --restart=Never --rm -i --tty --image=debian:12.2-slim -- /bin/bash
# install rust + dependencies
apt-get update && apt-get install -y curl git build-essential
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y
source "$HOME/.cargo/env"
rustup component add rust-src --toolchain nightly
# clone repos
cd /root
git clone https://github.com/sunfishcode/mustang.git
git clone https://github.com/nrabulinski/rush.git
# build rush
export RUST_TARGET_PATH="$PWD/mustang/target-specs"
cd rush && RUSTFLAGS="-C target-feature=+crt-static -C relocation-model=static" cargo +nightly build -Z build-std --target=x86_64-mustang-linux-gnu && cd ..
# in another tab: kubectl cp default/debian:/root/rush/target/x86_64-mustang-linux-gnu/debug/rush ./rush
exit

Run

# start clean kubernetes pod
kubectl run -n default debian --restart=Never --rm -i --tty --image=debian:12.2-slim --overrides='{"spec": {"containers": [{"name": "debian", "image": "debian:12.2-slim", "command": ["/bin/bash"], "stdin": true, "tty": true, "securityContext": {"privileged": true}}]}}'
# install dependencies
apt-get update && apt-get install -y qemu-utils e2fsprogs qemu-system-x86
# get qemu disk ready
cd /root
qemu-img create -f raw mydisk.img 1G
losetup /dev/loop0 mydisk.img
mkfs.ext4 /dev/loop0 # TODO: partitions so we can have root=/dev/sda1 instead of root=/dev/sda
mount /dev/loop0 /mnt
# in a different tab: kubectl cp ./rush default/debian:/mnt/rush
chmod +x /mnt/rush
umount /mnt
losetup -d /dev/loop0
# in a different tab: kubectl cp ./bzImage default/debian:/root/bzImage
# boot
qemu-system-x86_64 -kernel bzImage -append "console=ttyS0 root=/dev/sda init=/rush" -hda mydisk.img -nographic
# Ctrl+a then C then quit to exit qemu
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment