Skip to content

Instantly share code, notes, and snippets.

@MatiasVara
Last active November 20, 2022 22:12
Show Gist options
  • Save MatiasVara/2c357d016920953cd9b6c043a5544dc6 to your computer and use it in GitHub Desktop.
Save MatiasVara/2c357d016920953cd9b6c043a5544dc6 to your computer and use it in GitHub Desktop.
This gist enables to build a minimal initramfs with a shell by relying on busybox. This only requires the busybox binary. The busybox binary must be statically linked (see https://gist.github.com/chrisdone/02e165a0004be33734ac2334f215380e).
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
setsid cttyhack sh
exec /bin/sh
dir /dev 755 0 0
nod /dev/console 644 0 0 c 5 1
dir /proc 755 0 0
dir /sys 755 0 0
nod /dev/hvc0 644 0 0 c 229 0
nod /dev/tty0 644 0 0 c 4 0
nod /dev/loop0 644 0 0 b 7 0
dir /bin 755 1000 1000
slink /bin/mount busybox 777 0 0
slink /bin/sh busybox 777 0 0
slink /bin/setsid busybox 777 0 0
slink /bin/cttyhack busybox 777 0 0
slink /bin/ls busybox 777 0 0
slink /bin/cut busybox 777 0 0
file /bin/busybox usr/initramfs/busybox 755 0 0
file /init usr/initramfs/init.sh 755 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment