stali-init

Stali init files. To be shared.
git clone git://r-36.net/stali-init
Log | Files | Refs

commit 376703b08351274682217cce3637326aba97c811
parent ee166e16177a417eedeaedae2ef20e1d4861b6ae
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat,  1 Mar 2014 17:35:43 +0100

Moving everything over to etc and random file.

/etc is too hardcoded for being changed so it will be kept.

Additionally the random seed code was updated.

Diffstat:
rc.init | 85++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
rc.shutdown | 61+++++--------------------------------------------------------
2 files changed, 70 insertions(+), 76 deletions(-)

diff --git a/rc.init b/rc.init @@ -1,6 +1,6 @@ #!/bin/busybox ash -. /cfg/rc.conf +. /etc/rc.conf mkdir -p /dev mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid @@ -33,10 +33,10 @@ then mount -o remount,ro / fi -if [ -s /cfg/locale.conf ]; +if [ -s /etc/locale.conf ]; then - printf "Reading /cfg/locale.conf.\n" - eval $(cat /cfg/locale.conf) + printf "Reading /etc/locale.conf.\n" + eval $(cat /etc/locale.conf) fi if [ -n $(printf "%s" "$LANG" | grep -i utf) ]; @@ -56,10 +56,10 @@ else echo 0 >| /sys/module/vt/parameters/default_utf8 fi -if [ -s /cfg/vconsole.conf ]; +if [ -s /etc/vconsole.conf ]; then printf "Reading vconsole.conf.\n" - eval $(cat /cfg/vconsole.conf) + eval $(cat /etc/vconsole.conf) [ -n "$FONT" ] && CONSOLEFONT="$FONT" [ -n "$FONT_MAP" ] && CONSOLEMAP="$FONT_MAP" fi @@ -90,25 +90,20 @@ then fi printf "Running nldev.\n" -if [ -e /proc/self/fd ]; -then - rm -f /dev/fd 2>/dev/null - ln -sf /proc/self/fd /dev/fd -fi - -nldev -b +nldev -kbd & printf "Loading MODULES from rc.conf.\n" for i in $MODULES; do - /sbin/modprobe "${i}" + busybox modprobe "${i}" done printf "Triggering all device events.\n" nltrigger add all printf "Setting up lo device.\n" -[ -d /sys/class/net/lo ] && ip link set up dev lo +[ -d /sys/class/net/lo ] && ifconfig lo up +#ip link set up dev lo [ "$USEDMRAID" = "yes" ] && printf "Setting up dmraid.\n" && env dmraid -i -ay [ "$USEBTRFS" = "yes" ] && printf "Setting up btrfs.\n" && env btrfs device scan @@ -130,7 +125,7 @@ fi printf "Remounting /.\n" mount -o remount,rw / -printf "Mounting all filesystems in /cfg/fstab.\n" +printf "Mounting all filesystems in /etc/fstab.\n" mount -a [ "$USELVM" = "yes" ] && printf "Activating lvm monitor.\n" && env vgchange --monitor y >/dev/null @@ -146,9 +141,9 @@ then then printf "'%s' is not a valid timezone.\n" "${TIMEZONE}" else - if [ ! -L /cfg/localtime ] || [ ! /cfg/localtime -ef "${zonefile}" ]; + if [ ! -L /etc/localtime ] || [ ! /etc/localtime -ef "${zonefile}" ]; then - ln -sf "${zoneinfo}" /cfg/localtime + ln -sf "${zoneinfo}" /etc/localtime fi fi fi @@ -160,7 +155,11 @@ then cat $RANDOM_SEED > /dev/urandom else dd if=/dev/random of=/dev/urandom count=1 &>/dev/null + touch $RANDOM_SEED fi +chmod 600 $RANDOM_SEED +POOL_FILE=/proc/sys/kernel/random/poolsize +[ -r $POOL_FILE ] && POOL_SIZE=$(cat $POOL_FILE) || POOL_SIZE=512 printf "Cleaning up /var.\n" if [ ! -L /var/lock ] && [ ! /var/lock -ef /run/lock ]; @@ -175,11 +174,12 @@ then ln -sf /run /var/run fi -[ -s /cfg/hostname ] && HOSTNAME=$(cat /cfg/hostname) +[ -s /etc/hostname ] && HOSTNAME=$(cat /etc/hostname) if [ -n "$HOSTNAME" ]; then printf "Setting hostname to '%s'.\n" "${HOSTNAME}" printf "%s\n" "$HOSTNAME" > /proc/sys/kernel/hostname + hostname -F /etc/hostname fi printf "Storing dmesg output into /var/log/dmesg.log.\n" @@ -191,5 +191,50 @@ else chmod 0644 /var/log/dmesg.log fi -# next file is stali.multi +printf "Running sysctl.\n" +sysctl -p /etc/sysctl.conf &>/dev/null +for path in /usr/lib/sysctl.d /etc/sysctl.d /run/sysctl.d; +do + if [ -d $path ]; + then + for file in $(ls -1 $path); + do + sysctl -p $file &>/dev/null + done + fi +done + +printf "Running binfmt.\n" +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; + for file in $(ls -1 $path); + do + grep "^:" $file | \ + while read -r line; + do + printf "%s" "$line" \ + > /proc/sys/fs/binfmt_misc/register + done + done +done + +printf "Killing bootlogd.\n" +if [ -f /run/bootlogd.pid ]; +then + kill $(cat /run/bootlogd.pid) + rm -f /run/bootlogd.pid +fi +[ -e /run/boot.log ] && mv /run/boot.log /var/log/boot + +printf "Loading DELAYMODULES from rc.conf.\n" +for i in $DELAYMODULES; +do + busybox modprobe "${i}" +done + +# next is rc.svc +# then is tty1 from stali.inittab diff --git a/rc.shutdown b/rc.shutdown @@ -1,6 +1,6 @@ #!/bin/busybox ash -. /cfg/rc.conf +. /etc/rc.conf # avoid staircase effect stty onlcr @@ -13,15 +13,10 @@ svc -k 2>&1 >/dev/null printf "Saving random seed for next boot.\n" RANDOM_SEED=/var/lib/misc/random-seed -rm -f $RANDOM_SEED +touch $RANDOM_SEED +chmod 600 $RANDOM_SEED POOL_FILE=/proc/sys/kernel/random/poolsize -if [ -r $POOL_FILE ]; -then - read POOL_SIZE < $POOL_FILE - POOL_SIZE=$(($POOL_SIZE / 8)) -else - POOL_SIZE=512 -fi +[ -r $POOL_FILE ] && POOL_SIZE=$(cat $POOL_FILE) || POOL_SIZE=512 dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &>/dev/null printf "Halting.\n" @@ -32,55 +27,9 @@ halt -w printf "Swapoff.\n" swapoff -a &>/dev/null printf "Unmounting all filesystems.\n" -umount -a &>/dev/null +umount -a -r &>/dev/null # TODO: crypttab support [ "$USELVM" = "yes" ] && printf "Stopping lvm completely.\n" && env vgchange --sysinit -a n -if [ -x /run/initramfs/shutdown ]; -then - printf "Going back to initramfs.\n" - if [ $RUNLEVEL -eq 0 ]; - then - action="poweroff" - else - action="reboot" - fi - - mount -o bind /run/initramfs /run/initramfs - - mount -o private /run/initramfs - mount -o private / - - # bind all api mounts - for i in sys proc dev run oldroot; - do - mkdir -p /run/initramfs/${i} - done - mount -o bind /sys /run/initramfs/sys - mount -o bind /proc /run/initramfs/proc - mount -o bind /dev /run/initramfs/dev - mount -o bind /run /run/initramfs/run - - cd /run/initramfs - pivot_root . oldroot - - /oldroot/sbin/init u - - exec chroot . /shutdown $action </dev/console >/dev/console 2>&1 -else - mount -o remount,ro / - - if [ $RUNLEVEL -eq 0 ]; - then - printf "POWERR OFF\n" - poweroff -f - else - printf "REBOOTING\n" - env kexec -e &>/dev/null - reboot -f - fi - -fi -