#!/bin/bash if test $(id -u) -ne 0; then SUDO=sudo fi set -e BUSYBOX=busybox-1.36.1 INITRD=$PWD/initramfs.cpio.gz ## Build busybox echo "[+] configure & build $BUSYBOX ..." [[ ! -d $BUSYBOX ]] && { wget https://busybox.net/downloads/$BUSYBOX.tar.bz2 bunzip2 $BUSYBOX.tar.bz2 && tar xf $BUSYBOX.tar } cd $BUSYBOX make defconfig sed -i 's/# CONFIG_STATIC .*/CONFIG_STATIC=y/' .config make -j$(nproc --ignore=2) busybox make install ## Create initrd echo "[+] create initrd $INITRD ..." cd _install # 1. create initrd folder structure mkdir -p bin sbin etc proc sys usr/bin usr/sbin dev # 2. create init process cat < init #!/bin/sh mount -t proc none /proc mount -t sysfs none /sys mount -t devtmpfs none /dev exec setsid cttyhack sh EOF chmod +x init # 3. created compressed initrd find . -print0 \ | cpio --null -ov --format=newc \ | gzip -9 > $INITRD