Update runit paper

This commit is contained in:
Neale Pickett 2014-10-27 01:15:39 +00:00
parent 8b7b85b057
commit 73afd3b4c0
1 changed files with 133 additions and 62 deletions

View File

@ -122,6 +122,18 @@ You might want to play with that and understand what the initrd is,
before you are put into a position where you *have* to use it and can't start a web browser. before you are put into a position where you *have* to use it and can't start a web browser.
WARNING
-------
This document is now pretty old.
It's unlikely it will work at all on a modern Arch installation.
[My AUR](https://aur.archlinux.org/packages/runit-init/)
is usually only a few days behind the latest change in Arch's packages.
I've left this here because it might help people trying similar things
with different distributions.
But if you're using Arch, I strongly recommend you start with the AUR.
Let's go Let's go
-------- --------
@ -159,10 +171,10 @@ Be sure to move the old `init` to soming like `init.sysv`,
then create a new `init` similar to this then create a new `init` similar to this
(don't forget to `chmod +x`): (don't forget to `chmod +x`):
#! /bin/sh #! /bin/sh
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin PATH=/usr/bin; export PATH
export PATH
if [ $$ -ne 1 ]; then if [ $$ -ne 1 ]; then
case $1 in case $1 in
@ -178,49 +190,104 @@ then create a new `init` similar to this
exit 1 exit 1
fi fi
# Run arch's sysinit echo
if ! /etc/rc.sysinit; then echo 'Arch Linux'
# Kludge it if there's no rc.sysinit echo 'http://www.archlinux.org/'
echo '-----------------------------'
echo
mount -t proc proc /proc -o nosuid,noexec,nodev echo ":: Mounting initial filesystems"
mount -t sysfs sys /sys -o nosuid,noexec,nodev mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
mount -t tmpfs run /run -o mode=0755,nosuid,nodev mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
mount -t devtmpfs dev /dev -o mode=0755,nosuid mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
mkdir -p /dev/{pts,shm} mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
mount -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
mount -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
# This doesn't ever run fsck :< mkdir -p -m0755 /run/runit /run/lock /run/lock/lvm /run/lvm /run/user /dev/pts /dev/shm
mount -o remount,rw / mountpoint -q /dev/pts || mount -n -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
mountpoint -q /dev/shm || mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
: < /etc/hostname > /proc/sys/kernel/hostname mount -o remount,ro /
hwclock --systz echo ":: Setting up Unicode"
for i in /dev/tty[0-9]*;do
unicode_start <$i
done &
# Start/trigger udev, load MODULES, and settle udev echo ":: Setting system clock"
udevd_modprobe sysinit hwclock --utc --hctosys
echo ":: Enabling devices"
touch /dev/mdev.seq
/usr/bin/mdev -s &
echo ":: Loading drivers"
for i in $(seq 2); do
find /sys -name modalias -type f -exec cat {} + | sort -u | xargs modprobe -b -a
done 2>/dev/null
echo ":: Bringing up network"
ip link set up dev lo
cat /etc/hostname >/proc/sys/kernel/hostname
echo ":: Setting up cryptographic devices"
grep "^[^#]" /etc/crypttab | while read name device password options; do
case $options in
*swap*)
cryptsetup --key-file /dev/urandom open --type plain $device $name
mkswap /dev/mapper/$name
;;
*)
cryptsetup luksOpen $device $name < /dev/console
;;
esac
done
echo ":: Checking filesystems"
[ -f /forcefsck ] || grep -q forcefsck /proc/cmdline && FORCEFSCK=-f
if ! [ -f /fastboot ] && ! grep -q fastboot /proc/cmdline; then
fsck -A -T -C -a -t noopts=_netdev $FORCEFSCK
if [ $? -gt 1 ]; then
sulogin
fi
fi fi
echo ":: Mounting filesystems"
mount -o remount,rw /
mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev
echo ":: Enabling swap"
swapon -a
echo ":: Tidying up"
install -m0664 -o root -g utmp /dev/null /run/utmp &
rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot &
if grep -q 'break=init' /proc/cmdline; then if grep -q 'break=init' /proc/cmdline; then
echo 'Breaking before init, type "exit" to continue booting' echo 'Breaking before init, type "exit" to continue booting'
/bin/sh /bin/sh
fi fi
if [ -x /etc/rc.local ]; then
echo ":: Sourcing /etc/rc.local"
. /etc/rc.local
fi
# XXX: Who creates this? echo ":: Passing control to runit"
rm /run/nologin echo
# Hand off to runit
exec runsvdir -P -s runit-signal /service exec runsvdir -P -s runit-signal /service
This will still run `udev` and `bootlogd` from `/etc/rc.sysinit`. This does a couple things:
I tried to set up `mdev` from busybox as a `udev` replacement,
but Xorg wants `udev`, 1. Mounts /proc, /sys, /dev, and some other directories.
and I was having other problems getting drivers loaded, 2. Turns on Unicode for 9 TTYs
so I'm just trusting the the Arch devs here. 3. Sets the system clock from the hardware clock
If you can figure out another way, 4. Runs an initial mdev to populate /dev
please email me about it, I'd love to know. 5. Loads modules for things in /sys
6. Bring up the loopback interface
7. Initialize your cryptfs, if you have any in /etc/crypttab
8. fsck then mount everything in /etc/fstab
9. Run whatever's in /etc/rc.local
10. Start runsvdir
You may also want to install the `dash` package, You may also want to install the `dash` package,
and link `/bin/sh` to that, and link `/bin/sh` to that,
@ -292,17 +359,17 @@ Here's my `/usr/local/sbin/runit-signal`
15) # SIGTERM: reboot 15) # SIGTERM: reboot
cleanup cleanup
echo "Rebooting..." echo "Rebooting..."
reboot -f busybox reboot -f
;; ;;
10) # SIGUSR1: halt 10) # SIGUSR1: halt
cleanup cleanup
echo "Halting..." echo "Halting..."
halt -f busybox halt -f
;; ;;
12) # SIGUSR2: power 12) # SIGUSR2: power
cleanup cleanup
echo "Shutting down..." echo "Shutting down..."
poweroff -f busybox poweroff -f
;; ;;
*) # Everything else *) # Everything else
;; ;;
@ -363,8 +430,12 @@ You're an Arch Linux sysadmin,
you should know what you need, you should know what you need,
and I can't help you past here. and I can't help you past here.
Removing `udev` Hotplug events won't work, though.
--------------- For that, you need to either run udev or some other hotplug listener.
Setting up `mdev` as a hotplug listener
---------------------------------------
The `mdev` utility of busybox can replace most of what `udev` does. The `mdev` utility of busybox can replace most of what `udev` does.
You just need to have the kernel run `mdev` as the hotplug userspace thingy. You just need to have the kernel run `mdev` as the hotplug userspace thingy.