37 Commits

Author SHA1 Message Date
990661bfd9 Split up getty-runit to its own make 2018-05-05 17:55:05 +07:00
bf732c4905 Move stages to rc, remove HASSYSV flag 2018-05-05 17:38:23 +07:00
24306e68c1 log console messages with bootlogd 2018-05-05 17:23:30 +07:00
9ae595db4f Move sysctl to functions 2018-05-05 17:14:50 +07:00
1eaaac7428 Add sysctl init to stage1 initscript 2018-05-05 17:03:47 +07:00
c9e84492fb Make stage 2 init-agnostic 2018-05-05 17:02:59 +07:00
9e4fd67db6 Add cleanup sysinit to stage1 2018-05-05 17:01:43 +07:00
d47df45f50 Remount RO before deactivating cryptsetup and LVM2 2018-05-05 15:26:25 +07:00
0665f7630b Remove Void shutdown binaries (now handled by artix-sysvcompat) 2018-05-05 13:48:48 +07:00
9a9003b255 sync immediately after remount ro 2018-05-05 13:45:08 +07:00
udeved
a67af1e82b fix bootlogd 2018-05-05 03:49:12 +00:00
udeved
b0238301c9 makefile: add HASSYSV param 2018-05-05 02:09:16 +02:00
udeved
c28ea35b41 merge makefiles 2018-05-05 02:01:09 +02:00
7f0feca5b2 Merge branch 'rc-modules' 2018-05-05 06:05:23 +07:00
a47df21b08 Remove unmount tmpfs
runit needs to read /run during shutdown
2018-05-05 06:00:40 +07:00
989a323867 Fix unmount command 2018-05-05 05:55:19 +07:00
3139aa4609 Fix cryptsetup lock on shutdown 2018-05-05 05:30:11 +07:00
7cad901c86 Fix issues with command not found 2018-05-05 05:24:51 +07:00
d145dce79a Integrate some hooks into initscripts 2018-05-05 05:06:54 +07:00
fd63fdca89 Add back securityfs and efivarfs 2018-05-05 04:48:11 +07:00
7d09c40c88 Add sysinit.d and shutdown.d to makefile 2018-05-05 04:30:42 +07:00
d3a6d855ca Integrate rc.sysinit and rc.shutdown in stage1 and 3 2018-05-05 04:21:17 +07:00
5c42be6143 Use crypt.awk instead 2018-05-05 03:45:20 +07:00
90b1e1c301 typo 2018-05-05 03:22:53 +07:00
udeved
65768e39ea wip 2018-05-04 21:55:50 +02:00
ed2bb8edd7 Add efivarfs 2018-05-05 02:52:00 +07:00
a44aab979b Merge old Arch rc functions to runit-artix 2018-05-04 13:55:32 +07:00
udeved
1e6537cb5c makefile: sed RCDIR 2018-05-03 18:49:47 +02:00
udeved
1250ac8e8f provide rc makefile 2018-05-03 18:41:33 +02:00
udeved
9aed8d1e97 split out rc 2018-05-03 16:18:00 +02:00
udeved
46604a1cb9 rename services->sv 2018-05-03 12:25:19 +02:00
udeved
d8dfa64afc create /var/log/boot 2018-05-03 12:20:22 +02:00
udeved
0b464e9da9 runit.conf: fix sed target 2018-05-03 12:01:51 +02:00
udeved
4dcecb7d45 integrate rc scripts in runit stages 2018-05-03 11:53:22 +02:00
20a1ca16bc Update Makefile
- Move back non-sysv packages in /usr/bin
- Split off sysv-compatible binaries into 'install_sysv'
2018-03-28 21:54:05 +07:00
82bf65d4fa Move remaining shutdown services to its own place 2018-03-27 19:39:43 +07:00
f8a8bc673b Separate shutdown services 2018-03-26 16:45:26 +07:00
108 changed files with 1007 additions and 540 deletions

34
1
View File

@@ -1,34 +0,0 @@
#!/bin/sh
# vim: set ts=4 sw=4 et:
PATH=/usr/bin:/usr/sbin
. /etc/runit/functions
[ -r /etc/runit/rc.conf ] && . /etc/runit/rc.conf
msg "Welcome to Artix Linux!"
if [ -x /usr/bin/openrc ] && [ "$SVMANAGER" = "openrc" ]; then
# Start core services: we'll use OpenRC for this.
msg "Initializing runlevel sysinit with OpenRC..."
openrc sysinit || msg_error "Failed to start sysinit runlevel"
else
# Start core services: one-time system tasks.
detect_virt
for f in /etc/runit/core-services/*.sh; do
[ -r $f ] && . $f
done
fi
dmesg >/var/log/dmesg.log
if [ $(sysctl -n kernel.dmesg_restrict 2>/dev/null) -eq 1 ]; then
chmod 0600 /var/log/dmesg.log
else
chmod 0644 /var/log/dmesg.log
fi
mkdir -p /run/runit
install -m100 /dev/null /run/runit/stopit
msg "Initialization complete, running stage 2..."

28
1.in Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
PATH=/usr/bin:/usr/sbin
. @RCDIR@/rc.conf
. @RCDIR@/functions
# Prints distro name and URL
print_welcome
run_hook sysinit_start
for sysinit in @RCDIR@/sysinit.d/*; do
. $sysinit
done
# Remove leftover files
# remove_leftover
cleanup_sysinit
run_hook sysinit_end
install -m100 /dev/null @RUNDIR@/stopit
status "Initialization complete"
bootlogd_stop

28
2
View File

@@ -1,28 +0,0 @@
#!/bin/sh
# vim: set ts=4 sw=4 et:
PATH=/usr/bin:/usr/sbin
runlevel=default
for arg in $(cat /proc/cmdline); do
if [ -d /etc/runit/runsvdir/"$arg" ]; then
echo "Runlevel detected: '$arg' (via kernel cmdline)"
runlevel="$arg"
fi
done
[ -x /etc/runit/rc.local ] && /etc/runit/rc.local
# The reason that boot is not in stage 1 is because if something hangs
# we can still listen for signals, however stage 1 does NOT accept signals
if [ -x /usr/bin/openrc ] && [ "$SVMANAGER" = "openrc" ]; then
openrc boot
openrc default
fi
runsvchdir "${runlevel}"
mkdir -p /run/runit/runsvdir
ln -s /etc/runit/runsvdir/current /run/runit/service
exec env - PATH=$PATH \
runsvdir -P /run/runit/service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'

20
2.in Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
PATH=/usr/bin:/usr/sbin
[ -x @RCDIR@/rc.local ] && . @RCDIR@/rc.local
runlevel=default
for arg in $(cat /proc/cmdline); do
if [ -d @RUNITDIR@/runsvdir/"$arg" ]; then
echo "Runlevel detected: '$arg' (via kernel cmdline)"
runlevel="$arg"
fi
done
runsvchdir "${runlevel}"
# mkdir -p @RUNDIR@/runsvdir
ln -s @RUNSVDIR@/current @SERVICEDIR@
exec env - PATH=$PATH \
runsvdir -P @SERVICEDIR@ 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'

59
3
View File

@@ -1,59 +0,0 @@
#!/bin/sh
# vim: set ts=4 sw=4 et:
PATH=/usr/bin:/usr/sbin
. /etc/runit/functions
detect_virt
[ -r /etc/runit/rc.conf ] && . /etc/runit/rc.conf
if [ -e /run/runit/reboot ]; then
chmod 100 /run/runit/reboot
fi
echo
msg "Waiting for services to stop..."
sv force-stop /run/runit/service/*
sv exit /run/runit/service/*
[ -x /etc/runit/rc.shutdown ] && /etc/runit/rc.shutdown
msg "Saving random seed..."
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then
hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)}
fi
halt -w # for utmp
if [ -z "$VIRTUALIZATION" ]; then
msg "Stopping udev..."
udevadm control --exit
fi
msg "Sending TERM signal to processes..."
pkill --inverse -s0,1 -TERM
sleep 1
msg "Sending KILL signal to processes..."
pkill --inverse -s0,1 -KILL
if [ -z "$VIRTUALIZATION" ]; then
msg "Unmounting filesystems, disabling swap..."
swapoff -a
umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
msg "Remounting rootfs read-only..."
mount -o remount,ro /
fi
sync
if [ -z "$VIRTUALIZATION" ]; then
deactivate_vgs
deactivate_crypt
if [ -e /run/runit/reboot ] && command -v kexec >/dev/null; then
msg "Triggering kexec..."
kexec -e 2>/dev/null
# not reached when kexec was successful.
fi
fi

35
3.in Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
PATH=/usr/bin:/usr/sbin
. @RCDIR@/rc.conf
. @RCDIR@/functions
. @RCDIR@/rc.shutdown
status "Stop services ..." sv force-stop @RUNDIR@/service/*
status "Exit services ..." sv exit @RUNDIR@/service/*
if [ -e @RUNDIR@/reboot ]; then
chmod 100 @RUNDIR@/reboot
fi
# avoid staircase effect
stty onlcr
echo " "
printhl "Initiating shutdown..."
echo " "
run_hook shutdown_start
for shutdown in @RCDIR@/shutdown.d/*; do
. $shutdown
done
run_hook shutdown_poweroff
if [ -e @RUNDIR@/reboot ]; then
[[ -x $(type -P kexec) ]] && kexec -e &>/dev/null
fi
status "Stage 3 completed."

156
Makefile
View File

@@ -1,44 +1,122 @@
PREFIX ?= /usr SYSCONFDIR = /etc
SCRIPTS= 1 2 3 ctrlaltdel PREFIX ?= /usr
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man
LIBDIR = $(PREFIX)/lib
TMPFILESDIR = $(LIBDIR)/tmpfiles.d
RUNITDIR = $(SYSCONFDIR)/runit
SVDIR = $(RUNITDIR)/sv
RUNSVDIR = $(RUNITDIR)/runsvdir
SERVICEDIR = /etc/service
RUNDIR = /run/runit
RCDIR = $(SYSCONFDIR)/rc
all: TMPFILES = tmpfile.conf
$(CC) $(CFLAGS) halt.c -o halt $(LDFLAGS)
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
install: BIN = zzz pause modules-load
install -d ${DESTDIR}${PREFIX}/lib/runit-artix/bin
install -m755 halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/halt STAGES = 1 2 3 ctrlaltdel
install -m755 pause ${DESTDIR}${PREFIX}/lib/runit-artix/bin/pause
install -m755 shutdown ${DESTDIR}${PREFIX}/lib/runit-artix/bin/shutdown RC = rc/rc.local rc/rc.shutdown rc/functions rc/rc.conf
install -m755 modules-load ${DESTDIR}${PREFIX}/lib/runit-artix/bin/modules-load
install -m755 zzz ${DESTDIR}${PREFIX}/lib/runit-artix/bin/zzz LN = ln -sf
ln -sf halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/poweroff CP = cp -R --no-dereference --preserve=mode,links -v
ln -sf halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/reboot RM = rm -f
install -d ${DESTDIR}${PREFIX}/share/man/man1 RMD = rm -fr --one-file-system
install -m644 pause.1 ${DESTDIR}${PREFIX}/share/man/man1 M4 = m4 -P
install -d ${DESTDIR}${PREFIX}/share/man/man8 CHMODAW = chmod a-w
install -m644 zzz.8 ${DESTDIR}${PREFIX}/share/man/man8/zzz-runit.8 CHMODX = chmod +x
install -m644 shutdown.8 ${DESTDIR}${PREFIX}/share/man/man8/shutdown-runit.8
install -m644 halt.8 ${DESTDIR}${PREFIX}/share/man/man8/halt-runit.8 HASRC = yes
install -m644 modules-load.8 ${DESTDIR}${PREFIX}/share/man/man8
ln -sf halt-runit.8 ${DESTDIR}${PREFIX}/share/man/man8/poweroff-runit.8 EDIT = sed \
ln -sf halt-runit.8 ${DESTDIR}${PREFIX}/share/man/man8/reboot-runit.8 -e "s|@RUNITDIR[@]|$(RUNITDIR)|g" \
install -d ${DESTDIR}/etc/runit/sv -e "s|@SERVICEDIR[@]|$(SERVICEDIR)|g" \
install -d ${DESTDIR}/etc/runit/runsvdir -e "s|@RUNSVDIR[@]|$(RUNSVDIR)|g" \
install -d ${DESTDIR}/etc/runit/core-services -e "s|@RUNDIR[@]|$(RUNDIR)|g" \
install -m644 core-services/*.sh ${DESTDIR}/etc/runit/core-services -e "s|@RCDIR[@]|$(RCDIR)|g"
install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
install -m644 functions $(DESTDIR)/etc/runit %: %.in Makefile
install -m644 crypt.awk ${DESTDIR}/etc/runit @echo "GEN $@"
install -m644 rc.conf ${DESTDIR}/etc/runit @$(RM) "$@"
install -m755 rc.local ${DESTDIR}/etc/runit @$(M4) $@.in | $(EDIT) >$@
install -m755 rc.shutdown ${DESTDIR}/etc/runit @$(CHMODAW) "$@"
ln -sf /run/runit/reboot ${DESTDIR}/etc/runit/ @$(CHMODX) "$@"
ln -sf /run/runit/stopit ${DESTDIR}/etc/runit/
cp -R --no-dereference --preserve=mode,links -v runsvdir/* ${DESTDIR}/etc/runit/runsvdir/
cp -R --no-dereference --preserve=mode,links -v services/* ${DESTDIR}/etc/runit/sv/
all: all-runit
ifeq ($(HASRC),yes)
all: all-rc
endif
all-runit:
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
all-rc: $(RC) $(STAGES)
install-runit:
install -d $(DESTDIR)$(RUNITDIR)
install -d $(DESTDIR)$(RUNSVDIR)
mkdir -p $(DESTDIR)$(RUNSVDIR)/default
mkdir -p $(DESTDIR)$(SVDIR)/sulogin
$(LN) $(RUNSVDIR)/default $(DESTDIR)$(RUNSVDIR)/current
$(CP) sv/sulogin $(DESTDIR)$(SVDIR)/
$(CP) runsvdir/single $(DESTDIR)$(RUNSVDIR)/
$(LN) $(RUNDIR)/reboot $(DESTDIR)$(RUNITDIR)/
$(LN) $(RUNDIR)/stopit $(DESTDIR)$(RUNITDIR)/
install -d $(DESTDIR)$(BINDIR)
install -m755 $(BIN) $(DESTDIR)$(BINDIR)
install -d $(DESTDIR)$(TMPFILESDIR)
install -m755 $(TMPFILES) $(DESTDIR)$(TMPFILESDIR)/runit.conf
install -d $(DESTDIR)$(MANDIR)/man1
install -m644 pause.1 $(DESTDIR)$(MANDIR)/man1
install -d $(DESTDIR)$(MANDIR)/man8
install -m644 zzz.8 $(DESTDIR)$(MANDIR)/man8/zzz.8
install -m644 modules-load.8 $(DESTDIR)$(MANDIR)/man8
install-rc:
install -d $(DESTDIR)$(RUNITDIR)
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
install -d $(DESTDIR)$(RCDIR)
install -d $(DESTDIR)$(RCDIR)/sysinit.d
install -d $(DESTDIR)$(RCDIR)/shutdown.d
install -m755 $(RC) $(DESTDIR)$(RCDIR)
install -m644 rc/sysinit.d/* $(DESTDIR)$(RCDIR)/sysinit.d
install -m644 rc/shutdown.d/* $(DESTDIR)$(RCDIR)/shutdown.d
install -m644 rc/crypt.awk $(DESTDIR)$(RCDIR)
install -d $(DESTDIR)$(RUNITDIR)
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
install-getty:
install -d $(DESTDIR)$(SVDIR)
$(CP) sv/agetty-* $(DESTDIR)$(SVDIR)/
install -d $(DESTDIR)$(RUNSVDIR)/default
$(CP) runsvdir/default $(DESTDIR)$(RUNSVDIR)/
install: install-runit
ifeq ($(HASRC),yes)
install: install-rc
endif
clean-runit:
-rm -f pause
clean-rc:
-rm -f $(RC)
-rm -f $(STAGES)
clean: clean-runit
ifeq ($(HASRC),yes)
clean: clean-rc
endif
clean: clean:
-rm -f halt pause
.PHONY: all install clean .PHONY: all install clean install-runit install-rc install-getty clean-runit clean-rc all-runit all-rc

View File

@@ -1,17 +0,0 @@
# vim: set ts=4 sw=4 et:
msg "Mounting pseudo-filesystems..."
mountpoint -q /proc || mount -o nosuid,noexec,nodev -t proc proc /proc
mountpoint -q /sys || mount -o nosuid,noexec,nodev -t sysfs sys /sys
mountpoint -q /run || mount -o mode=0755,nosuid,nodev -t tmpfs run /run
mountpoint -q /dev || mount -o mode=0755,nosuid -t devtmpfs dev /dev
mkdir -p -m0755 /run/runit /run/lvm /run/user /run/lock /run/log /dev/pts /dev/shm
mountpoint -q /dev/pts || mount -o mode=0620,gid=5,nosuid,noexec -n -t devpts devpts /dev/pts
mountpoint -q /dev/shm || mount -o mode=1777,nosuid,nodev -n -t tmpfs shm /dev/shm
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
if [ -z "$VIRTUALIZATION" ]; then
mountpoint -q /sys/fs/cgroup || mount -o mode=0755 -t tmpfs cgroup /sys/fs/cgroup
mountpoint -q /sys/fs/cgroup/openrc || mkdir -p /sys/fs/cgroup/openrc && mount -t cgroup -o none,name=openrc cgroup /sys/fs/cgroup/openrc
awk '$4 == 1 { system("mountpoint -q /sys/fs/cgroup/" $1 " || { mkdir -p /sys/fs/cgroup/" $1 " && mount -t cgroup -o " $1 " cgroup /sys/fs/cgroup/" $1 " ;}" ) }' /proc/cgroups
fi

View File

@@ -1,6 +0,0 @@
# Some kernel modules must be loaded before starting udev(7).
# Load them by looking at the output of `kmod static-nodes`.
for f in $(kmod static-nodes 2>/dev/null|awk '/Module/ {print $2}'); do
modprobe -bq $f 2>/dev/null
done

View File

@@ -1,9 +0,0 @@
# vim: set ts=4 sw=4 et:
[ -n "$VIRTUALIZATION" ] && return 0
# Do not try to load modules if kernel does not support them.
[ ! -e /proc/modules ] && return 0
msg "Loading kernel modules..."
modules-load -v | tr '\n' ' ' | sed 's:insmod [^ ]*/::g; s:\.ko\(\.gz\)\? ::g'
echo

View File

@@ -1,24 +0,0 @@
# vim: set ts=4 sw=4 et:
[ -n "$VIRTUALIZATION" ] && return 0
if [ -x /usr/lib/systemd/systemd-udevd ]; then
_udevd=/usr/lib/systemd/systemd-udevd
elif [ -x /sbin/udevd -o -x /bin/udevd ]; then
_udevd=udevd
else
msg_warn "cannot find udevd!"
fi
if [ -x /usr/bin/tmpfiles ]; then
msg "Setting up tmpfiles.d entries for /dev..."
tmpfiles --prefix=/dev --create --boot
fi
if [ -n "${_udevd}" ]; then
msg "Starting udev and waiting for devices to settle..."
${_udevd} --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
fi

View File

@@ -1,26 +0,0 @@
# vim: set ts=4 sw=4 et:
[ -n "$VIRTUALIZATION" ] && return 0
TTYS=${TTYS:-12}
if [ -n "$FONT" ]; then
msg "Setting up TTYs font to '${FONT}'..."
_index=0
while [ ${_index} -le $TTYS ]; do
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
$FONT -C "/dev/tty${_index}"
_index=$((_index + 1))
done
fi
if [ -n "$KEYMAP" ]; then
msg "Setting up keymap to '${KEYMAP}'..."
loadkeys -q -u ${KEYMAP}
fi
if [ -n "$HARDWARECLOCK" ]; then
msg "Setting up RTC to '${HARDWARECLOCK}'..."
TZ=$TIMEZONE hwclock --systz \
${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z) --noadjfile} || emergency_shell
fi

View File

@@ -1,70 +0,0 @@
# vim: set ts=4 sw=4 et:
[ -n "$VIRTUALIZATION" ] && return 0
msg "Remounting rootfs read-only..."
mount -o remount,ro / || emergency_shell
if [ -x /sbin/dmraid -o -x /bin/dmraid ]; then
msg "Activating dmraid devices..."
dmraid -i -ay
fi
if [ -x /bin/btrfs ]; then
msg "Activating btrfs devices..."
btrfs device scan || emergency_shell
fi
if [ -x /sbin/vgchange -o -x /bin/vgchange ]; then
msg "Activating LVM devices..."
vgchange --sysinit -a y || emergency_shell
fi
if [ -e /etc/crypttab ]; then
msg "Activating encrypted devices..."
awk -f /etc/runit/crypt.awk /etc/crypttab
if [ -x /sbin/vgchange -o -x /bin/vgchange ]; then
msg "Activating LVM devices for dm-crypt..."
vgchange --sysinit -a y || emergency_shell
fi
fi
if [ -e /etc/zfs/zpool.cache -a -x /usr/bin/zfs ]; then
msg "Activating ZFS devices..."
zpool import -c /etc/zfs/zpool.cache -N -a
msg "Mounting ZFS file systems..."
zfs mount -a
msg "Sharing ZFS file systems..."
zfs share -a
# NOTE(dh): ZFS has ZVOLs, block devices on top of storage pools.
# In theory, it would be possible to use these as devices in
# dmraid, btrfs, LVM and so on. In practice it's unlikely that
# anybody is doing that, so we aren't supporting it for now.
fi
[ -f /fastboot ] && FASTBOOT=1
[ -f /forcefsck ] && FORCEFSCK="-f"
for arg in $(cat /proc/cmdline); do
case $arg in
fastboot) FASTBOOT=1;;
forcefsck) FORCEFSCK="-f";;
esac
done
if [ -z "$FASTBOOT" ]; then
msg "Checking filesystems:"
fsck -A -T -a -t noopts=_netdev $FORCEFSCK
if [ $? -gt 1 ]; then
emergency_shell
fi
fi
msg "Mounting rootfs read-write..."
mount -o remount,rw / || emergency_shell
msg "Mounting all non-network filesystems..."
mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev || emergency_shell

View File

@@ -1,6 +0,0 @@
# vim: set ts=4 sw=4 et:
[ -n "$VIRTUALIZATION" ] && return 0
msg "Initializing swap..."
swapon -a || emergency_shell

View File

@@ -1,31 +0,0 @@
# vim: set ts=4 sw=4 et:
msg "Initializing random seed..."
cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
msg "Setting up loopback interface..."
ip link set up dev lo
[ -r /etc/hostname ] && read -r HOSTNAME < /etc/hostname
if [ -n "$HOSTNAME" ]; then
msg "Setting up hostname to '${HOSTNAME}'..."
printf "%s" "$HOSTNAME" > /proc/sys/kernel/hostname
else
msg_warn "Didn't setup a hostname!"
fi
if [ -n "$TIMEZONE" ]; then
msg "Setting up timezone to '${TIMEZONE}'..."
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
fi
msg "Setting up sysusers.d entries..."
if [ -x /usr/bin/sysusers ]; then
sysusers
fi
msg "Setting up tmpfiles.d entries..."
if [ -x /usr/bin/tmpfiles ]; then
tmpfiles --exclude-prefix=/dev --create --remove --boot
fi

View File

@@ -1,16 +0,0 @@
# vim: set ts=4 sw=4 et:
if [ -x /sbin/sysctl -o -x /bin/sysctl ]; then
msg "Loading sysctl(8) settings..."
for i in /run/sysctl.d/*.conf \
/usr/local/lib/sysctl.d/*.conf \
/usr/lib/sysctl.d/*.conf \
/etc/sysctl.conf \
/etc/sysctl.d/*.conf; do
if [ -e "$i" ]; then
printf '* Applying %s ...\n' "$i"
sysctl -p "$i"
fi
done
fi

View File

@@ -1,12 +0,0 @@
# vim: set ts=4 sw=4 et:
install -m0664 -o root -g utmp /dev/null /run/utmp
if [ ! -e /var/log/wtmp ]; then
install -m0664 -o root -g utmp /dev/null /var/log/wtmp
fi
if [ ! -e /var/log/btmp ]; then
install -m0600 -o root -g utmp /dev/null /var/log/btmp
fi
rm -rf /tmp
install -dm1777 /tmp /tmp/.X11-unix /tmp/.ICE-unix
rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot

View File

@@ -4,7 +4,7 @@ PATH=/usr/bin:/usr/sbin
MSG="System is going down..." MSG="System is going down..."
# We check for this file in stage3 to halt or reboot # We check for this file in stage3 to halt or reboot
touch /run/runit/reboot touch @RUNDIR@/reboot
# Proceed with shutdown process # Proceed with shutdown process
echo "$MSG" | wall echo "$MSG" | wall

View File

@@ -1,57 +0,0 @@
# *-*-shell-*-*
msg() {
# bold
printf "\033[1m=> $@\033[m\n"
}
msg_ok() {
# bold/green
printf "\033[1m\033[32m OK\033[m\n"
}
msg_error() {
# bold/red
printf "\033[1m\033[31mERROR: $@\033[m\n"
}
msg_warn() {
# bold/yellow
printf "\033[1m\033[33mWARNING: $@\033[m"
}
emergency_shell() {
echo
echo "Cannot continue due to errors above, starting emergency shell."
echo "When ready type exit to continue booting."
/bin/sh -l
}
detect_virt() {
# Detect LXC containers
[ ! -e /proc/self/environ ] && return
if grep -q lxc /proc/self/environ >/dev/null; then
export VIRTUALIZATION=1
fi
}
deactivate_vgs() {
_group=${1:-All}
if [ -x /sbin/vgchange -o -x /bin/vgchange ]; then
vgs=$(vgs|wc -l)
if [ $vgs -gt 0 ]; then
msg "Deactivating $_group LVM Volume Groups..."
vgchange -an
fi
fi
}
deactivate_crypt() {
if [ -x /sbin/dmsetup -o -x /bin/dmsetup ]; then
msg "Deactivating Crypt Volumes"
for v in $(dmsetup ls --target crypt --exec "dmsetup info -c --noheadings -o open,name"); do
[ ${v%%:*} -eq 0 ] && cryptsetup close ${v##*:}
done
deactivate_vgs "Crypt"
fi
}

32
rc.conf
View File

@@ -1,32 +0,0 @@
# /etc/runit/rc.conf - system configuration
# Set the service manager (available options: "runit" or "openrc")
#SVMANAGER="runit"
# Set the host name.
#
# NOTE: it's preferred to declare the hostname in /etc/hostname instead:
# - echo myhost > /etc/hostname
#
#HOSTNAME="artix"
# Set RTC to UTC or localtime.
#HARDWARECLOCK="UTC"
# Set timezone, availables timezones at /usr/share/zoneinfo.
#TIMEZONE="Europe/Madrid"
# Keymap to load, see loadkeys(8).
#KEYMAP="us"
# Console font to load, see setfont(8).
#FONT="lat9w-16"
# Console map to load, see setfont(8).
#FONT_MAP=
# Font unimap to load, see setfont(8).
#FONT_UNIMAP=
# Amount of ttys which should be setup.
#TTYS=6

544
rc/functions.in Normal file
View File

@@ -0,0 +1,544 @@
#!/bin/bash
# rc functions
#
# sanitize PATH (will be overridden later when /etc/profile is sourced but is useful for udev)
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# clear the TZ envvar, so daemons always respect /etc/localtime
# unset TZ
. /etc/profile.d/locale.sh
# width:
calc_columns () {
STAT_COL=80
if [[ ! -t 1 ]]; then
USECOLOR=""
elif [[ -t 0 ]]; then
# stty will fail when stdin isn't a terminal
STAT_COL=$(stty size)
# stty gives "rows cols"; strip the rows number, we just want columns
STAT_COL=${STAT_COL##* }
elif tput cols &>/dev/null; then
# is /usr/share/terminfo already mounted, and TERM recognized?
STAT_COL=$(tput cols)
fi
if (( STAT_COL == 0 )); then
# if output was 0 (serial console), set default width to 80
STAT_COL=80
USECOLOR=""
fi
# we use 13 characters for our own stuff
STAT_COL=$(( STAT_COL - 13 ))
if [[ -t 1 ]]; then
SAVE_POSITION="\e[s"
RESTORE_POSITION="\e[u"
DEL_TEXT="\e[$(( STAT_COL + 4 ))G"
else
SAVE_POSITION=""
RESTORE_POSITION=""
DEL_TEXT=""
fi
}
calc_columns
# disable colors on broken terminals
TERM_COLORS=$(tput colors 2>/dev/null)
if (( $? != 3 )); then
case $TERM_COLORS in
*[!0-9]*) USECOLOR="";;
[0-7]) USECOLOR="";;
'') USECOLOR="";;
esac
fi
unset TERM_COLORS
# functions:
deltext() {
printf "${DEL_TEXT}"
}
printhl() {
printf "${C_OTHER}${PREFIX_HL} ${C_H1}${1}${C_CLEAR} \n"
}
printsep() {
printf "\n${C_SEPARATOR} ------------------------------\n"
}
stat_busy() {
printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} "
printf "${SAVE_POSITION}"
deltext
printf " ${C_OTHER}[${C_BUSY}BUSY${C_OTHER}]${C_CLEAR} "
}
stat_done() {
deltext
printf " ${C_OTHER}[${C_DONE}DONE${C_OTHER}]${C_CLEAR} \n"
}
stat_fail() {
deltext
printf " ${C_OTHER}[${C_FAIL}FAIL${C_OTHER}]${C_CLEAR} \n"
}
status() {
local quiet
case $1 in
-q)
quiet=1
;;&
-v)
# NOOP: supported for backwards compat
shift
;;
esac
stat_busy "$1"
shift
if (( quiet )); then
"$@" &>/dev/null
else
"$@"
fi
local ret=$?
(( ret == 0 )) && stat_done || stat_fail
return $ret
}
# usage : in_array( $needle, $haystack )
# return : 0 - found
# 1 - not found
in_array() {
local needle=$1; shift
local item
for item; do
[[ $item = "${needle}" ]] && return 0
done
return 1 # Not Found
}
kill_all() {
stat_busy "Sending TERM signal to processes"
pkill --inverse -s0,1 -TERM
if (( $? == 0 )); then
stat_done
else
stat_fail
sleep 1
status "Sending KILL signal to processes" pkill --inverse -s0,1 -KILL
fi
}
print_welcome() {
# see os-release(5)
. /etc/os-release
echo " "
printhl "${PRETTY_NAME}\n"
printhl "${C_H2}${HOME_URL}"
printsep
}
load_modules() {
local rc=0
/usr/bin/modules-load
(( rc+=$? ))
return $rc
}
# Start/trigger udev, load MODULES, and settle udev
udevd_modprobe() {
# $1 = where we are being called from.
# This is used to determine which hooks to run.
status "Starting udev daemon" udevd --daemon
run_hook "$1_udevlaunched"
stat_busy "Triggering udev uevents"
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
stat_done
# Load modules from the MODULES array and modules-load.d
status "Loading user-specified modules" load_modules
status "Waiting for udev uevents to be processed" \
udevadm settle
run_hook "$1_udevsettled"
# in case loading a module changed the display mode
calc_columns
}
activate_vgs() {
[[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0
stat_busy "Activating LVM2 groups"
vgchange --sysinit -a y >/dev/null
(( $? == 0 )) && stat_done || stat_fail
}
load_sysctl() {
if [ -x /usr/bin/sysctl ]; then
for i in /run/sysctl.d/*.conf \
/etc/sysctl.d/*.conf \
/usr/local/lib/sysctl.d/*.conf \
/usr/lib/sysctl.d/*.conf \
/etc/sysctl.conf; do
if [ -e "$i" ]; then
printf '* Applying %s \n' "$i"
sysctl -p "$i"
fi
done
fi
}
do_unlock_legacy() {
# $1 = requested name
# $2 = source device
# $3 = password
# $4 = options
local open=create a=$1 b=$2 failed=0
# Ordering of options is different if you are using LUKS vs. not.
# Use ugly swizzling to deal with it.
# isLuks only gives an exit code but no output to stdout or stderr.
if cryptsetup isLuks "$2" 2>/dev/null; then
open=luksOpen
a=$2
b=$1
fi
case $3 in
SWAP)
local _overwriteokay=0
if [[ -b $2 && -r $2 ]]; then
# This is DANGEROUS! If there is any known file system,
# partition table, RAID, or LVM volume on the device,
# we don't overwrite it.
#
# 'blkid' returns 2 if no valid signature has been found.
# Only in this case should we allow overwriting the device.
#
# This sanity check _should_ be sufficient, but it might not.
# This may cause data loss if it is not used carefully.
blkid -p "$2" &>/dev/null
(( $? == 2 )) && _overwriteokay=1
fi
if (( _overwriteokay == 0 )); then
false
elif cryptsetup -d /dev/urandom $4 $open "$a" "$b" >/dev/null; then
printf "creating swapspace..\n"
mkswap -f -L $1 /dev/mapper/$1 >/dev/null
fi;;
ASK)
printf "\nOpening '$1' volume:\n"
cryptsetup $4 $open "$a" "$b" < /dev/console;;
/dev*)
local ckdev=${3%%:*}
local cka=${3#*:}
local ckb=${cka#*:}
local cka=${cka%:*}
local ckfile=/dev/ckfile
local ckdir=/dev/ckdir
case ${cka} in
*[!0-9]*)
# Use a file on the device
# cka is not numeric: cka=filesystem, ckb=path
mkdir ${ckdir}
mount -r -t ${cka} ${ckdev} ${ckdir}
dd if=${ckdir}/${ckb} of=${ckfile} >/dev/null 2>&1
umount ${ckdir}
rmdir ${ckdir};;
*)
# Read raw data from the block device
# cka is numeric: cka=offset, ckb=length
dd if=${ckdev} of=${ckfile} bs=1 skip=${cka} count=${ckb} >/dev/null 2>&1;;
esac
cryptsetup -d ${ckfile} $4 $open "$a" "$b" >/dev/null
dd if=/dev/urandom of=${ckfile} bs=1 count=$(stat -c %s ${ckfile}) conv=notrunc >/dev/null 2>&1
rm ${ckfile};;
/*)
cryptsetup -d "$3" $4 $open "$a" "$b" >/dev/null;;
*)
echo "$3" | cryptsetup $4 $open "$a" "$b" >/dev/null;;
esac
return $?
}
do_unlock() {
local name=$1 device=$2 password=$3 options=$4
printf "${C_MAIN}Unlocking $1${C_CLEAR}\n"
if [[ ${options:0:2} =~ -. ]]; then
do_unlock_legacy "$name" "$device" "$password" "$options"
return $?
fi
case $password in
ASK|SWAP)
do_unlock_legacy "$name" "$device" "$password" "$options"
;;
*)
do_unlock_legacy "$name" "$device" "$password" "$options"
;;
esac
failed=$?
if (( $failed )); then
printf "${C_FAIL}Unlocking of $1 failed.${C_CLEAR}\n"
fi
return $?
}
deactivate_crypt() {
if [[ -x /usr/bin/dmsetup ]]; then
for v in $(dmsetup ls --target crypt --exec "dmsetup info -c --noheadings -o open,name"); do
[[ ${v%%:*} == "0" ]] && cryptsetup close ${v##*:}
done
fi
}
set_timezone() {
local tz=$1 zonefile=/usr/share/zoneinfo/$1
[[ $tz ]] || return 1
if [[ ! -e $zonefile ]]; then
printf "error: \`%s' is not a valid time zone\n" "$tz"
return 1
fi
if [[ -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then
return 0
else
ln -sf "/usr/share/zoneinfo/$tz" /etc/localtime
fi
}
# Filesystem functions
# These can be overridden/reused for customizations like shutdown/loop-fsck.
NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.glusterfs"
# Check local filesystems
fsck_all() {
if [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline); then
FORCEFSCK="-f"
elif [[ -f /fastboot ]] || in_array fastboot $(< /proc/cmdline); then
return 0
elif [[ -e /run/initramfs/root-fsck ]]; then
IGNORE_MOUNTED="-M"
fi
fsck -A -T -C${FSCK_FD} -a -t no${NETFS//,/,no},noopts=_netdev ${IGNORE_MOUNTED} -- ${FORCEFSCK}
}
# Single-user login and/or automatic reboot after fsck (if needed)
fsck_reboot() {
# $1 = exit code returned by fsck
# Ignore conditions 'FS errors corrected' and 'Cancelled by the user'
(( ($1 | 33) == 33 )) && return 0
if (( $1 & 2 )); then
echo
echo "********************** REBOOT REQUIRED *********************"
echo "* *"
echo "* The system will be rebooted automatically in 15 seconds. *"
echo "* *"
echo "************************************************************"
echo
sleep 15
else
echo
echo "***************** FILESYSTEM CHECK FAILED ****************"
echo "* *"
echo "* Please repair manually and reboot. Note that the root *"
echo "* file system is currently mounted read-only. To remount *"
echo "* it read-write, type: mount -o remount,rw / *"
echo "* When you exit the maintenance shell, the system will *"
echo "* reboot automatically. *"
echo "* *"
echo "************************************************************"
echo
sulogin -p
fi
echo "Automatic reboot in progress..."
umount -a
mount -o remount,ro /
reboot -f
exit 0
}
mount_all() {
mount -a -t "no${NETFS//,/,no}" -O no_netdev
}
remove_leftover() {
status 'Removing leftover files' tmpfiles --create --remove --clean
}
bootlogd_stop() {
[[ -f /run/bootlogd.pid ]] || return 0
touch /var/log/boot
kill $(< /run/bootlogd.pid)
rm -f /run/bootlogd.pid
}
bootlogd_start(){
# [[ ! -f /var/log/boot ]] && touch /var/log/boot
bootlogd -p /run/bootlogd.pid
}
console_setup(){
TTYS=${TTYS:-6}
if [ -n "$FONT" ]; then
_index=0
while [ ${_index} -le $TTYS ]; do
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
$FONT -C "/dev/tty${_index}"
_index=$((_index + 1))
done
fi
if [ -n "$KEYMAP" ]; then
loadkeys -q -u ${KEYMAP}
fi
}
init_random_seed(){
cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
}
save_random_seed(){
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
}
mk_kmod_static_nodes(){
[[ -d /run/tmpfiles.d ]] || mkdir /run/tmpfiles.d
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
}
mk_tmpfiles_dev(){
if [ -x /usr/bin/tmpfiles ]; then
tmpfiles --prefix=/dev --create --boot
fi
}
mk_tmpfiles_setup(){
if [ -x /usr/bin/tmpfiles ]; then
tmpfiles --exclude-prefix=/dev --create --remove --boot
fi
}
mk_sysusers(){
if [ -x /usr/bin/sysusers ]; then
sysusers
fi
}
cleanup_sysinit(){
install -m0664 -o root -g utmp /dev/null /run/utmp
if [ ! -e /var/log/wtmp ]; then
install -m0664 -o root -g utmp /dev/null /var/log/wtmp
fi
if [ ! -e /var/log/btmp ]; then
install -m0600 -o root -g utmp /dev/null /var/log/btmp
fi
rm -rf /tmp
install -dm1777 /tmp /tmp/.X11-unix /tmp/.ICE-unix
rm -f /etc/nologin #/forcefsck /forcequotacheck /fastboot
}
###############################
# Custom hooks in initscripts #
###############################
# Hooks can be used to include custom code in various places in the rc.* scripts
#
# Define a hook function in a functions.d file using:
# function_name() {
# ...
# }
# add_hook hook_name function_name
# It is allowed to register several hook functions for the same hook
# Is is also allowed to register the same hook function for several hooks
#
# Currently, the following hooks exist:
# sysinit_start: at the beginning of rc.sysinit
# shutdown_start: at the beginning of rc.shutdown
# sysinit_end: at the end of rc.sysinit
# sysinit_udevlaunched: after udev has been launched in rc.sysinit
# sysinit_udevsettled: after uevents have settled in rc.sysinit
# sysinit_premount: before local filesystems are mounted, but after root is mounted read-write in rc.sysinit
# sysinit_postmount: after local filesystems are mounted
# shutdown_prekillall: before all processes are being killed in rc.shutdown
# shutdown_postkillall: after all processes have been killed in rc.shutdown
# shutdown_preumount: after last filesystem write, but before filesystems are unmounted
# shutdown_postumount: after filesystems are unmounted
# shutdown_poweroff: directly before powering off in rc.shutdown
#
# Declare add_hook and run_hook as read-only to prevent overwriting them.
# Too bad we cannot do the same thing with hook_funcs
if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then
declare -A hook_funcs
add_hook() {
[[ $1 && $2 ]] || return 1
hook_funcs[$1]+=" $2"
}
run_hook() {
[[ $1 ]] || return 1
local func
for func in ${hook_funcs["$1"]}; do
"${func}"
done
}
declare -fr add_hook run_hook
declare -r RC_FUNCTIONS_HOOK_FUNCS_DEFINED=1
fi
# set colors
if [[ $USECOLOR != [nN][oO] ]]; then
if tput setaf 0 &>/dev/null; then
C_CLEAR=$(tput sgr0) # clear text
C_MAIN=${C_CLEAR}$(tput bold) # main text
C_OTHER=${C_MAIN}$(tput setaf 4) # prefix & brackets
C_SEPARATOR=${C_MAIN}$(tput setaf 0) # separator
C_BUSY=${C_CLEAR}$(tput setaf 6) # busy
C_FAIL=${C_MAIN}$(tput setaf 1) # failed
C_DONE=${C_MAIN} # completed
C_BKGD=${C_MAIN}$(tput setaf 5) # backgrounded
C_H1=${C_MAIN} # highlight text 1
C_H2=${C_MAIN}$(tput setaf 6) # highlight text 2
else
C_CLEAR="\e[m" # clear text
C_MAIN="\e[;1m" # main text
C_OTHER="\e[1;34m" # prefix & brackets
C_SEPARATOR="\e[1;30m" # separator
C_BUSY="\e[;36m" # busy
C_FAIL="\e[1;31m" # failed
C_DONE=${C_MAIN} # completed
C_BKGD="\e[1;35m" # backgrounded
C_H1=${C_MAIN} # highlight text 1
C_H2="\e[1;36m" # highlight text 2
fi
fi
# prefixes:
PREFIX_REG="::"
PREFIX_HL=" >"
# Source additional functions at the end to allow overrides
# for f in @RCDIR@/functions.d/*; do
# [[ -e $f ]] && . "$f"
# done

13
rc/rc.conf.in Normal file
View File

@@ -0,0 +1,13 @@
# @RCDIR@/rc.conf - system configuration
# Storage
#
# USEDMRAID="no"
# USELVM="no"
# Network
#
# interface=
# address=
# netmask=
# gateway=

4
rc/rc.local.in Normal file
View File

@@ -0,0 +1,4 @@
# Default rc.local; add your custom commands here.
#
# This is run by runit in stage 2 before the services are executed
# (see /etc/runit/2).

View File

@@ -0,0 +1 @@
status 'Saving random seed' save_random_seed

View File

@@ -0,0 +1 @@
[[ $TIMEZONE ]] && status "Configuring time zone" set_timezone "$TIMEZONE"

2
rc/shutdown.d/03-wtmp.sh Normal file
View File

@@ -0,0 +1,2 @@
# Write to wtmp file before unmounting
halt -w

View File

@@ -0,0 +1,3 @@
# stop monitoring of LVM2 groups before unmounting filesystems
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
status "Deactivating monitoring of LVM2 groups" vgchange --monitor n

2
rc/shutdown.d/05-udev.sh Normal file
View File

@@ -0,0 +1,2 @@
# any future uevents can and should be ignored
status "Shutting down udev" udevadm control --exit

View File

@@ -0,0 +1,3 @@
run_hook shutdown_prekillall
kill_all
run_hook shutdown_postkillall

3
rc/shutdown.d/08-swap.sh Normal file
View File

@@ -0,0 +1,3 @@
# almost everything is dead now, so the swap should hopefully be relatively
# empty, and quick to switch off
status "Deactivating swap" swapoff -a

View File

@@ -0,0 +1,3 @@
run_hook shutdown_preumount
status "Unmounting non-API filesystems" umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
run_hook shutdown_postumount

View File

@@ -0,0 +1,3 @@
status "Remounting root filesystem read-only" \
mount -o remount,ro /
sync

View File

@@ -0,0 +1,7 @@
# Kill non-root encrypted partition mappings
if [[ -f /etc/crypttab ]] && type -p cryptsetup >/dev/null; then
# Maybe someone has LVM on an encrypted block device
# executing an extra vgchange is errorless
[[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null
deactivate_crypt
fi

2
rc/shutdown.d/13-lvm2.sh Normal file
View File

@@ -0,0 +1,2 @@
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
status "Deactivating LVM2 groups" vgchange --sysinit -an &>/dev/null

View File

@@ -0,0 +1,18 @@
# mount the API filesystems
# /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm
mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
mkdir -p /dev/{pts,shm}
mountpoint -q /dev/pts || mount -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
mountpoint -q /dev/shm || mount -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
mountpoint -q /sys/firmware/efi/efivars || mount -n -t efivarfs -o ro efivarfs /sys/firmware/efi/efivars
mountpoint -q /sys/fs/cgroup || mount -o mode=0755 -t tmpfs cgroup /sys/fs/cgroup
mountpoint -q /sys/fs/cgroup/openrc || mkdir -p /sys/fs/cgroup/openrc && mount -t cgroup -o none,name=openrc cgroup /sys/fs/cgroup/openrc
awk '$4 == 1 { system("mountpoint -q /sys/fs/cgroup/" $1 " || { mkdir -p /sys/fs/cgroup/" $1 " && mount -t cgroup -o " $1 " cgroup /sys/fs/cgroup/" $1 " ;}" ) }' /proc/cgroups
findmnt / --options ro &>/dev/null || status "Mounting root read-only" mount -o remount,ro /
bootlogd_start

View File

@@ -0,0 +1,10 @@
unset HOSTNAME
if [[ -s /etc/hostname ]]; then
HOSTNAME=$(< /etc/hostname)
fi
if [[ $HOSTNAME ]]; then
stat_busy "Setting hostname: $HOSTNAME"
echo "$HOSTNAME" >| /proc/sys/kernel/hostname && stat_done || stat_fail
fi

View File

@@ -0,0 +1,34 @@
HWCLOCK_PARAMS="--systz"
if [[ $HARDWARECLOCK ]]; then
[[ -f /etc/adjtime ]] && { read ; read ; read ADJTIME; } < /etc/adjtime
if [[ $ADJTIME == 'LOCAL' ]]; then
if [[ $HARDWARECLOCK == 'UTC' ]]; then
printf "${C_FAIL}@RCDIR@/rc.conf says the RTC is in UTC, but /etc/adjtime says it is in localtime.\n${C_OTHER}."
fi
else
if [[ $HARDWARECLOCK == 'LOCALTIME' ]]; then
printf "${C_FAIL}@RCDIR@/rc.conf says the RTC is in localtime, but hwclock (/etc/adjtime) thinks it is in UTC.\n${C_OTHER}."
fi
fi
case $HARDWARECLOCK in
UTC) HWCLOCK_PARAMS+=" --utc --noadjfile";;
localtime) HWCLOCK_PARAMS+=" --localtime --noadjfile";;
*) HWCLOCK_PARAMS="";;
esac
fi
if [[ $HWCLOCK_PARAMS ]]; then
stat_busy "Adjusting system time and setting kernel time zone"
# Adjust the system time for time zone offset if rtc is not in UTC, as
# filesystem checks can depend on system time. This also sets the kernel
# time zone, used by e.g. vfat.
hwclock $HWCLOCK_PARAMS && stat_done || stat_fail
unset TZ
fi

View File

@@ -0,0 +1 @@
status "Creating list of required static device nodes" mk_kmod_static_nodes

View File

@@ -0,0 +1 @@
status "Setting up tmpfiles.d entries for /dev" mk_tmpfiles_dev

View File

@@ -0,0 +1,2 @@
# Start/trigger udev, load MODULES, and settle udev
udevd_modprobe sysinit

View File

@@ -0,0 +1,2 @@
# this must be done after udev has loaded the KMS modules
status 'Configuring virtual consoles' console_setup

View File

@@ -0,0 +1,2 @@
# bring up the loopback interface
[[ -d /sys/class/net/lo ]] && status "Bringing up loopback interface" ip link set up dev lo

View File

@@ -0,0 +1,3 @@
# FakeRAID devices detection
[[ $USEDMRAID = [Yy][Ee][Ss] && -x $(type -P dmraid) ]] &&
status "Activating FakeRAID arrays" dmraid -i -ay

2
rc/sysinit.d/10-lvm2.sh Normal file
View File

@@ -0,0 +1,2 @@
# Activate LVM2 groups, if any
activate_vgs

View File

@@ -0,0 +1,6 @@
# Set up non-root encrypted partition mappings
if [[ -f /etc/crypttab ]] && type -p cryptsetup >/dev/null; then
status "Activating encrypted devices" awk -f /etc/rc/crypt.awk /etc/crypttab
# Maybe someone has LVM on an encrypted block device
activate_vgs
fi

13
rc/sysinit.d/12-fsck.sh Normal file
View File

@@ -0,0 +1,13 @@
run_hook sysinit_prefsck
if [[ -x $(type -P fsck) ]]; then
stat_busy "Checking filesystems"
fsck_all >|"${FSCK_OUT:-/dev/stdout}" 2>|"${FSCK_ERR:-/dev/stdout}"
declare -r fsckret=$?
(( fsckret <= 1 )) && stat_done || stat_fail
else
declare -r fsckret=0
fi
# Single-user login and/or automatic reboot if needed
run_hook sysinit_postfsck
fsck_reboot $fsckret

View File

@@ -0,0 +1,2 @@
status "Remounting root and API filesystems" \
mount -o remount,rw /

View File

@@ -0,0 +1,4 @@
run_hook sysinit_premount
status "Mounting local filesystems" \
mount_all
run_hook sysinit_postmount

View File

@@ -0,0 +1,4 @@
# Enable monitoring of LVM2 groups, now that the filesystems are mounted rw
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
status "Activating monitoring of LVM2 groups" \
vgchange --monitor y >/dev/null

1
rc/sysinit.d/16-swap.sh Normal file
View File

@@ -0,0 +1 @@
status "Activating swap" swapon -a

View File

@@ -0,0 +1 @@
[[ $TIMEZONE ]] && status "Configuring time zone" set_timezone "$TIMEZONE"

View File

@@ -0,0 +1 @@
status 'Initializing random seed' init_random_seed

View File

@@ -0,0 +1 @@
status "Setting up tmpfiles.d entries" mk_tmpfiles_setup

View File

@@ -0,0 +1 @@
status "Setting up sysusers.d entries" mk_sysusers

View File

@@ -0,0 +1,8 @@
stat_busy "Saving dmesg log"
if [[ -e /proc/sys/kernel/dmesg_restrict ]] &&
(( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then
install -Tm 0600 <( dmesg ) /var/log/dmesg.log
else
install -Tm 0644 <( dmesg ) /var/log/dmesg.log
fi
(( $? == 0 )) && stat_done || stat_fail

View File

@@ -0,0 +1 @@
status "Loading sysctl(8) settings" load_sysctl

View File

@@ -1,73 +0,0 @@
#!/bin/sh
# shutdown - shutdown(8) lookalike for runit
single() {
runsvchdir single
}
abort() {
printf '%s\n' "$1" >&2
exit 1
}
usage() {
abort "Usage: ${0##*/} [-fF] [-kchPr] time [warning message]"
}
action=single
while getopts akrhPHfFnct: opt; do
case "$opt" in
a|n|H) abort "'-$opt' is not implemented";;
t) ;;
f) touch /fastboot;;
F) touch /forcefsck;;
k) action=true;;
c) action=cancel;;
h|P) action=halt;;
r) action=reboot;;
[?]) usage;;
esac
done
shift $((OPTIND - 1))
[ $# -eq 0 ] && usage
time=$1; shift
message="${*:-system is going down}"
if [ "$action" = "cancel" ]; then
kill "$(cat /run/runit/shutdown.pid)"
if [ -e /etc/nologin ] && ! [ -s /etc/nologin ]; then
rm /etc/nologin
fi
echo "${*:-shutdown cancelled}" | wall
exit
fi
touch /run/runit/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}"
echo $$ >/run/runit/shutdown.pid
case "$time" in
now) time=0;;
+*) time=${time#+};;
*:*) abort "absolute time is not implemented";;
*) abort "invalid time";;
esac
for break in 5 0; do
[ "$time" -gt "$break" ] || continue
[ "$break" = 0 ] && touch /etc/nologin
printf '%s in %s minutes\n' "$message" "$time" | wall
printf 'shutdown: sleeping for %s minutes... ' "$(( time - break ))"
sleep $(( (time - break) * 60 ))
time="$break"
printf '\n'
[ "$break" = 0 ] && rm /etc/nologin
done
printf '%s NOW\n' "$message" | wall
$action

Some files were not shown because too many files have changed in this diff Show More