16 Commits

Author SHA1 Message Date
5d16b77bdb Decouple LVM2 stage1 scripts to its own package 2018-05-09 07:22:56 +07:00
cea6a58cba Decouple cryptsetup initscripts to its own package 2018-05-09 07:16:43 +07:00
d2ebd92f24 Further fix for binfmt
Skip if directory doesn't exist or directory is empty.
Previous implementation was actually successful, but it always returns
1, probably because the loop expects all directories to exist.
2018-05-07 20:58:31 +07:00
4908b26a2d Enable btrfs only if USEBTRFS=yes 2018-05-07 14:24:37 +07:00
fdb0488f1e Fix issues with listing binfmt files 2018-05-07 11:08:52 +07:00
1aeedd0019 Remove /forcefsck and others during cleanup 2018-05-07 10:36:52 +07:00
0db3224e90 Add binfmt support 2018-05-06 20:25:53 +07:00
9527ccc8d0 Only read /etc/vconsole.conf if file exists 2018-05-06 19:46:18 +07:00
fb122c1beb Read from /etc/vconsole.conf for console_setup 2018-05-06 18:31:26 +07:00
8b47e238b9 Enable btrfs support 2018-05-06 18:27:45 +07:00
c9126a652a Make cleanup.sh the very last script to run by stage1 2018-05-06 11:13:45 +07:00
udeved
89b99e475d tmpfiles --clean is not implemented in opentmpfiles; remove the call 2018-05-06 01:14:01 +00:00
udeved
9befe99ed5 merge master 2018-05-05 23:27:57 +00:00
udeved
d36f9e6952 make clean up a sysinit module
rm unused
2018-05-05 23:24:56 +00:00
7852ea0ee3 sysctl: use sysctl --system 2018-05-06 06:12:39 +07:00
cf1c3912e7 Remove /forcefsck and others after boot
After testing, this file wasn't removed after boot, so I had to remove
it manually.
2018-05-06 06:03:29 +07:00
20 changed files with 36 additions and 427 deletions

2
1.in
View File

@@ -14,8 +14,6 @@ for sysinit in @RCDIR@/sysinit.d/*; do
. $sysinit . $sysinit
done done
cleanup_sysinit
run_hook sysinit_end run_hook sysinit_end
install -m100 /dev/null @RUNDIR@/stopit install -m100 /dev/null @RUNDIR@/stopit

View File

@@ -58,8 +58,8 @@ all-rc: $(RC) $(STAGES)
install-runit: install-runit:
install -d $(DESTDIR)$(RUNITDIR) install -d $(DESTDIR)$(RUNITDIR)
install -d $(DESTDIR)$(RUNSVDIR) install -d $(DESTDIR)$(RUNSVDIR)
mkdir -p $(DESTDIR)$(RUNSVDIR)/default install -d $(DESTDIR)$(RUNSVDIR)/default
mkdir -p $(DESTDIR)$(SVDIR)/sulogin install -d $(DESTDIR)$(SVDIR)/sulogin
$(LN) $(RUNSVDIR)/default $(DESTDIR)$(RUNSVDIR)/current $(LN) $(RUNSVDIR)/default $(DESTDIR)$(RUNSVDIR)/current
$(CP) sv/sulogin $(DESTDIR)$(SVDIR)/ $(CP) sv/sulogin $(DESTDIR)$(SVDIR)/
$(CP) runsvdir/single $(DESTDIR)$(RUNSVDIR)/ $(CP) runsvdir/single $(DESTDIR)$(RUNSVDIR)/
@@ -89,7 +89,6 @@ install-rc:
install -m755 $(RC) $(DESTDIR)$(RCDIR) install -m755 $(RC) $(DESTDIR)$(RCDIR)
install -m644 rc/sysinit.d/* $(DESTDIR)$(RCDIR)/sysinit.d install -m644 rc/sysinit.d/* $(DESTDIR)$(RCDIR)/sysinit.d
install -m644 rc/shutdown.d/* $(DESTDIR)$(RCDIR)/shutdown.d install -m644 rc/shutdown.d/* $(DESTDIR)$(RCDIR)/shutdown.d
install -m644 rc/crypt.awk $(DESTDIR)$(RCDIR)
install -d $(DESTDIR)$(RUNITDIR) install -d $(DESTDIR)$(RUNITDIR)
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR) install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)

View File

@@ -8,7 +8,7 @@ distribution.
- GNU coreutils - GNU coreutils
- GNU bash - GNU bash
- A POSIX awk - A POSIX awk
- procps-ng (needs pkill -s0,1) - procps-ng
- runit - runit
- opentmpfiles - opentmpfiles
- opensysusers - opensysusers

67
halt.8
View File

@@ -1,67 +0,0 @@
.Dd July 29, 2014
.Dt HALT 8
.Os Linux
.Sh NAME
.Nm halt ,
.Nm reboot ,
.Nm poweroff
.Nd stop the system
.Sh SYNOPSIS
.Nm halt
.Op Fl n
.Op Fl f
.Nm reboot
.Op Fl n
.Op Fl f
.Nm poweroff
.Op Fl n
.Op Fl f
.Sh DESCRIPTION
.Nm halt
/
.Nm reboot
/
.Nm poweroff
tells
.Xr init 8
to bring down, reboot, or power off the system.
Without
.Fl f ,
it is a shortcut for
.Nm init 0
/
.Nm init 6 .
.Bl -tag -width indent
.It Fl n
Don't sync before reboot or halt.
Note that the kernel and storage drivers may still sync.
.It Fl f
Force halt or reboot, don't call
.Xr init 8 .
This is
.Sy dangerous !
.El
.Sh UNSUPPORTED OPTIONS
This version of
.Nm
is based on
.Xr runit 8 ,
the following features are
.Sy not
supported and silently ignored:
.Bl -tag -width indent
.It Fl w
to just write the wtmp record.
.It Fl d
to not write the wtmp record.
.It Fl h
to put hard drives in standby mode.
.It Fl i
to shut down network interfaces.
.El
.Sh SEE ALSO
.Xr init 8 ,
.Xr shutdown 8
.Sh AUTHOR
.An Leah Neukirchen ,
.Mt leah@vuxu.org .

77
halt.c
View File

@@ -1,77 +0,0 @@
#include <errno.h>
#include <unistd.h>
#include <err.h>
#include <string.h>
#include <sys/reboot.h>
extern char *__progname;
typedef enum {NOOP, HALT, REBOOT, POWEROFF} action_type;
int main(int argc, char *argv[]) {
int do_sync = 1;
int do_force = 0;
int opt;
action_type action = NOOP;
if (strcmp(__progname, "halt") == 0)
action = HALT;
else if (strcmp(__progname, "reboot") == 0)
action = REBOOT;
else if (strcmp(__progname, "poweroff") == 0)
action = POWEROFF;
else
warnx("no default behavior, needs to be called as halt/reboot/poweroff.");
while ((opt = getopt(argc, argv, "dfhinw")) != -1)
switch (opt) {
case 'n':
do_sync = 0;
break;
case 'w':
action = NOOP;
do_sync = 0;
break;
case 'd':
case 'h':
case 'i':
/* silently ignored. */
break;
case 'f':
do_force = 1;
break;
default:
errx(1, "Usage: %s [-n] [-f]", __progname);
}
if (do_sync)
sync();
switch (action) {
case HALT:
if (do_force)
reboot(RB_HALT_SYSTEM);
else
execl("/bin/runit-init", "init", "0", (char*)0);
err(1, "halt failed");
break;
case POWEROFF:
if (do_force)
reboot(RB_POWER_OFF);
else
execl("/bin/runit-init", "init", "0", (char*)0);
err(1, "poweroff failed");
break;
case REBOOT:
if (do_force)
reboot(RB_AUTOBOOT);
else
execl("/bin/runit-init", "init", "6", (char*)0);
err(1, "reboot failed");
break;
case NOOP:
break;
}
return 0;
}

View File

@@ -1,4 +0,0 @@
# 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

@@ -1,103 +0,0 @@
/^#/ || /^$/ { next }
NF>4 { print "a valid crypttab has max 4 cols not " NF >"/dev/stderr"; next }
{
# decode the src variants
split($2, o_src, "=")
if (o_src[1] == "UUID") ("blkid -l -o device -t " $2) | getline src;
else src=o_src[1];
# no password or none is given, ask fo it
if ( NF == 2 ) {
ccmd="cryptsetup luksOpen " src " " $1;
system(ccmd);
ccmd="";
}
else if (NF == 3 ) {
dest=$1
key=$3
split($3, po, "=");
if ( po[1] == "none") ccmd="cryptsetup luksOpen " src " " dest;
else ccmd="cryptsetup luksOpen -d " key " " src" " dest;
system(ccmd);
ccmd="";
}
else {
# the option field is not empty parse the options
dest=$1
key=$3
split($4, opts, ",");
commonopts="";
swapopts="";
luksopts="";
for(i in opts) {
split(opts[i], para, "=");
par=para[1];
val=para[2];
if ( par == "readonly" || par == "read-only") commonopts=commonopts "-r ";
else if ( par == "discard" ) commonopts=commonopts "--allow-discards ";
else if ( par == "tries" ) commonopts=commonopts "-T " val " ";
else if ( par == "swap" ) makeswap="y";
else if ( par == "cipher" ) swapopts=swapopts "-c " val " ";
else if ( par == "size" ) swapopts=swapopts "-s " val " ";
else if ( par == "hash" ) swapopts=swapopts "-h " val " ";
else if ( par == "offset" ) swapopts=swapopts "-o " val " ";
else if ( par == "skip" ) swapopts=swapopts "-p " val " ";
else if ( par == "verify" ) swapopts=swapopts "-y ";
#else if ( par == "noauto" )
#else if ( par == "nofail" )
#else if ( par == "plain" )
#else if ( par == "timeout" )
#else if ( par == "tmp" )
else if ( par == "luks" ) use_luks="y";
else if ( par == "keyscript" ) {use_keyscript="y"; keyscript=val;}
else if ( par == "keyslot" || par == "key-slot" ) luksopts=luksopts "-S " val " ";
else if ( par == "keyfile-size" ) luksopts=luksopts "-l " val " ";
else if ( par == "keyfile-offset" ) luksopts=luksopts "-keyfile-offset=" val " ";
else if ( par == "header" ) luksopts=luksopts "--header=" val " ";
else {
print "option: " par " not supported " >"/dev/stderr";
makeswap="";
use_luks="";
use_keyscript="";
next;
}
}
if ( makeswap == "y" && use_luks != "y" ) {
ccmd="cryptsetup " swapopts commonopts "-d " key " create " dest " " src;
ccmd_2="mkswap /dev/mapper/" dest;
makeswap="";
use_luks="";
use_keyscript="";
system(ccmd);
system(ccmd_2);
ccmd="";
ccmd_2="";
next;
}
if ( use_luks == "y" && makeswap != "y" ){
if ( use_keyscript == "y") {
ccmd=keyscript " | cryptsetup " luksopts commonopts "luksOpen -d - " src " " dest;
use_keyscript="";
}
else {
if ( key == "none" ){
ccmd="cryptsetup " luksopts commonopts "luksOpen " src " " dest;
}
else {
ccmd="cryptsetup " luksopts commonopts "luksOpen -d " key " " src " " dest;
}
}
}
else {
print "use swap OR luks as option" >"/dev/stderr";
ccmd="";
}
makeswap="";
use_luks="";
use_keyscript="";
if ( ccmd != ""){
system(ccmd);
ccmd=""
}
}
}

View File

@@ -173,29 +173,6 @@ udevd_modprobe() {
calc_columns 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() { do_unlock_legacy() {
# $1 = requested name # $1 = requested name
# $2 = source device # $2 = source device
@@ -292,14 +269,6 @@ do_unlock() {
return $? 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() { set_timezone() {
local tz=$1 zonefile=/usr/share/zoneinfo/$1 local tz=$1 zonefile=/usr/share/zoneinfo/$1
@@ -317,6 +286,20 @@ set_timezone() {
fi fi
} }
run_binfmt() {
mountpoint -q /proc/sys/fs/binfmt_misc || \
mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc
for path in /usr/lib/binfmt.d /etc/binfmt.d /run/binfmt.d; do
[[ ! -d $path ]] && continue
[[ -z "$(ls $path)" ]] && continue
grep "^:" $path/* | \
while read -r line; do
printf "%s" "$line" > /proc/sys/fs/binfmt_misc/register
done
done
}
# Filesystem functions # Filesystem functions
# These can be overridden/reused for customizations like shutdown/loop-fsck. # 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" NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.glusterfs"
@@ -385,6 +368,7 @@ bootlogd_start(){
} }
console_setup(){ console_setup(){
[ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
TTYS=${TTYS:-6} TTYS=${TTYS:-6}
if [ -n "$FONT" ]; then if [ -n "$FONT" ]; then
_index=0 _index=0
@@ -435,24 +419,6 @@ mk_sysusers(){
fi 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
# Remove leftover files
remove_leftover
# this is not good, why remove tmp? consider /tmp is mounted tmpfs.
# rm -rf /tmp
# install -dm1777 /tmp /tmp/.X11-unix /tmp/.ICE-unix
rm -f /etc/nologin #/forcefsck /forcequotacheck /fastboot
}
############################### ###############################
# Custom hooks in initscripts # # Custom hooks in initscripts #
############################### ###############################

View File

@@ -2,12 +2,11 @@
# Storage # Storage
# #
# Enable dmraid support (yes/no)
# USEDMRAID="no" # USEDMRAID="no"
# Enable LVM2 support (yes/no)
# USELVM="no" # USELVM="no"
# Network # Enable btrfs support (yes/no)
# # USEBTRFS="no"
# interface=
# address=
# netmask=
# gateway=

View File

@@ -1,3 +0,0 @@
# 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

View File

@@ -1,7 +0,0 @@
# 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

View File

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

View File

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

1
rc/sysinit.d/11-btrfs.sh Normal file
View File

@@ -0,0 +1 @@
[[ $USEBTRFS == [Yy][Ee][Ss] ]] && status "Activating btrfs devices" btrfs device scan

View File

@@ -1,6 +0,0 @@
# 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

View File

@@ -1,4 +0,0 @@
# 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

View File

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

View File

@@ -0,0 +1 @@
status "Running binfmt" run_binfmt

View File

@@ -0,0 +1,10 @@
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 -f /etc/nologin /forcefsck /forcequotacheck /fastboot

View File

@@ -1,90 +0,0 @@
.Dd July 29, 2014
.Dt SHUTDOWN 8
.Os Linux
.Sh NAME
.Nm shutdown
.Nd bring down the system
.Sh SYNOPSIS
.Nm shutdown
.Op Fl rhP
.Op Fl fF
.Op Cm now | Cm + Ns Ar mins
.Op Ar message ...
.Sh DESCRIPTION
.Nm
brings the system down in a secure way.
All logged-in users
are notified that the system is going down, and
.Xr login 1
is blocked.
.Pp
By default,
.Nm
puts the system into single user mode.
Rebooting and halting the system can be done using the following options:
.Bl -tag -width indent
.It Fl c
Cancel an ongoing shutdown.
.It Fl f
Enable fast booting; skip
.Xr fsck 8
on next boot.
.It Fl F
Force run of
.Xr fsck 8
on next boot.
.It Fl h
Halt the system.
.It Fl k
Don't really shutdown; only send the warning messages to everybody.
.It Fl P
Poweroff the system.
.It Fl r
Reboot the system.
.It Cm now
Shutdown without further waiting.
.It Cm + Ns Ar mins
Wait
.Ar mins
minutes before shutting down.
.It Ar message
Message displayed to all users, defaults to "system is going down".
.El
.Sh UNSUPPORTED OPTIONS
This version of
.Nm
is based on
.Xr runit 8 ,
the following features are
.Sy not
supported:
.Bl -tag -width indent
.It Fl t Ar secs
to wait
.Ar secs
seconds between SIGKILL and SIGTERM on shutdown is silently ignored.
.It Fl a
Use
.Pa /etc/shutdown.allow .
.It Fl H
Drop into boot monitor.
.It Fl n
Don't call
.Xr init 8 .
.It Ar hh Ns : Ns Ar mm
Absolute time specification is not implemented.
.El
.Sh EXAMPLES
Turn off the system:
.Dl # shutdown -h now
.Sh SEE ALSO
.Xr fsck 8 ,
.Xr halt 8 ,
.Xr init 8 ,
.Xr poweroff 8 ,
.Xr reboot 8 ,
.Xr runit 8 ,
.Xr runsvchdir 8
.Sh AUTHOR
.An Leah Neukirchen ,
.Mt leah@vuxu.org .