Skip to content

Instantly share code, notes, and snippets.

@PhirePhly

PhirePhly/init

Last active Dec 21, 2020
Embed
What would you like to do?
Init script to go in the root of a Debian install for booting entirely from the initrd file
#!/bin/sh
# Kenneth Finnegan, 2020
# https://blog.thelifeofkenneth.com/
# Huge thanks to Gandi.net 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
tmpfs_size=10240k
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
fi
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
#!gpxe
ifopen net0
set net0/ip 192.0.2.100
set net0/netmask 255.255.255.0
set net0/gateway 192.0.2.1
set net0/dns 192.0.2.1
echo Configuring network...
sleep 3
kernel http://example.com/vmlinux1
initrd http://example.com/init1
echo And away we go!
boot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment