Skip to content

Instantly share code, notes, and snippets.

@PkmX
Last active August 29, 2015 14:19
Show Gist options
  • Save PkmX/11615c8ef2e0d29d9520 to your computer and use it in GitHub Desktop.
Save PkmX/11615c8ef2e0d29d9520 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
mkdir -p initramfs{/,/bin,/dev,/etc,/proc,/sbin,/sys,/usr,/usr/bin,/usr/sbin}
pushd initramfs
if [[ ! -x sbin/busybox ]]; then
wget -O sbin/busybox http://www.busybox.net/downloads/binaries/latest/busybox-x86-64
chmod a+x sbin/busybox
fi
if [[ ! -x init ]]; then
cat > init << EOF
#!/sbin/busybox sh
set -e
/sbin/busybox --install -s
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mknod -m 666 /dev/null c 1 3
mknod -m 666 /dev/zero c 1 5
mknod -m 666 /dev/ptmx c 5 2
mknod -m 666 /dev/tty c 5 0
mknod -m 444 /dev/random c 1 8
mknod -m 444 /dev/urandom c 1 9
mknod -m 620 /dev/tty1 c 4 1
mknod -m 620 /dev/tty2 c 4 2
mknod -m 620 /dev/tty3 c 4 3
mknod -m 620 /dev/tty4 c 4 4
mknod -m 620 /dev/tty5 c 4 5
mknod -m 620 /dev/tty6 c 4 6
mknod -m 620 /dev/tty7 c 4 7
mknod -m 620 /dev/tty8 c 4 8
ip link set eth0 up
ip link set lo up
exec /sbin/init
EOF
chmod a+x init
fi
find . | cpio -H newc -o > ../initramfs.cpio
popd
gzip - < initramfs.cpio > initramfs.cpio.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment