Skip to content

Instantly share code, notes, and snippets.

@sameo
Last active March 21, 2024 20:53
Show Gist options
  • Save sameo/c2b825002836167f0f9281f9b50b7948 to your computer and use it in GitHub Desktop.
Save sameo/c2b825002836167f0f9281f9b50b7948 to your computer and use it in GitHub Desktop.

Overview

Build an initramfs

(Copied from Manohar's gist: https://gist.github.com/mcastelino/74dc46bdfddc9943f2c04466d605a65b which is copied from https://gist.github.com/pacalet/660fa6472e0bcd53f71fc31f167c628f)

  • Use a busybox based rootfs for ease of use
git clone https://github.com/mirror/busybox
cd busybox
make defconfig
make menuconfig (enable Busybox Settings ---> Build Options ---> Build BusyBox as a static binary (no shared libs) ---> yes)
make
make install
  • Create the initramfs
mkdir $HOME/rootfs
cd $HOME/rootfs
mkdir -p bin sbin etc proc sys usr/bin usr/sbin
cp -a $BUSYBOX_BUILD/_install/* .
rm linuxrc
sudo mknod -m 644 dev/console c 5 1 
sudo mknod -m 644 dev/loop0 b 7 0
  • Create an init binary with appropriate contents with executeable perms
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
echo -e "Hello World\n"
exec /bin/sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment