Skip to content

Instantly share code, notes, and snippets.



Last active Apr 4, 2020
What would you like to do?
Init script to go in the root of a Debian install for booting entirely from the initrd file
# Kenneth Finnegan, 2020
# Huge thanks to for most of this code
set -x
set -e
# Create the mount points for all of the virtual file systems which don't
# actually map to disks, but are views into the kernel
[ -d /dev ] || mkdir -m 0755 /dev
[ -d /root ] || mkdir -m 0700 /root
[ -d /sys ] || mkdir /sys
[ -d /proc ] || mkdir /proc
[ -d /tmp ] || mkdir /tmp
mkdir -p /var/lock || true
# Mount the required virtual file systems
mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
mount -t proc -o nodev,noexec,nosuid proc /proc
if ! mount -t devtmpfs -o size=$tmpfs_size,mode=0755 udev /dev; then
echo "W: devtmpfs not available, falling back to tmpfs for /dev"
mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev
[ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
[ -e /dev/null ] || mknod /dev/null c 1 3
unset tmpfs_size
mkdir /dev/pts
mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
# Set dmesg to private if you want
echo 1 > /proc/sys/kernel/dmesg_restrict
# Replace ourselves with the actual init daemon which will handle starting every other daemon
exec /sbin/init
ifopen net0
set net0/ip
set net0/netmask
set net0/gateway
set net0/dns
echo Configuring network...
sleep 3
echo And away we go!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.