#!/bin/sh # # /etc/runit/1: System one time tasks (Stage 1). # # Version: (#) 1.00 2009-12-07 (MAF) # (#) 1.01 2010-03-12 (MAF) # (#) 1.02 2010-06-16 (MAF) # (#) 1.03 2010-06-17 (MAF) # (#) 1.04 2010-06-22 (MAF) # (#) 1.05 2010-06-30 (MAF) # (#) 1.06 2010-07-02 (MAF) # (#) 2.00 2010-07-09 (MAF) # (#) 2.01 2010-07-21 (MAF) # (#) 2.02 2010-07-29 (MAF) # (#) 2.03 2010-07-30 (MAF) # (#) 2.04 2010-12-21 (MAF) # # Author: Matías A. Fonzo, . # # Under the terms of the GNU General Public License. PATH=/sbin:/bin:/usr/sbin:/usr/bin # Functions. # A function for display a message: msg() { printf '%s\n' "$@"; } msg "Mounting kernel-based filesystems ..." mount -vn -t proc proc /proc mount -vn -t sysfs sysfs /sys # Initialize the dynamic device directory system (udev): sh /etc/rc.d/rc.udevd start # Initialize LVM2 (Logical Volume Manager version 2): # # See the backup directory: if [ -r /etc/lvm/lvm.conf ]; then BACKUP_DIR="$(awk '/backup_dir/ && !/^#/' /etc/lvm/lvm.conf | awk -F '["]' '{ print $2 }')" else # This is the default directory: BACKUP_DIR=/etc/lvm/backup fi # Check the backup directory: if [ -d "$BACKUP_DIR" ]; then # Load the device-mapper module: modprobe -q dm-mod # Scan all volume groups and make the attributes: vgscan --mknodes --ignorelockingfailure > /dev/null 2>&1 && \ vgchange -ay --ignorelockingfailure > /dev/null 2>&1 fi # Enable devices for paging and swapping are to take place: if [ -f /etc/rc.d/rc.swap ]; then sh /etc/rc.d/rc.swap start fi # Save the hardware time -> the system clock: if [ -f /etc/rc.d/rc.clock ]; then sh /etc/rc.d/rc.clock start fi # Override terminal settings before to check the filesystems: setterm -blank 0 # Test if the filesystem is still in read-only mode: if touch /if-not-read-only$$ 2> /dev/null ; then rm -f /if-not-read-only$$ mount -vn -o remount,ro / fi msg "*** Checking the root filesystem ..." if [ ! -e /etc/fastboot ]; then if [ -r /etc/forcefsck ]; then FORCE_CHK=-f fi fsck -a $FORCE_CHK -C / ERR_CODE=$? if [ $ERR_CODE -eq 0 ]; then msg "*** Checking the rest of the filesystems ..." fsck -a $FORCE_CHK -R -A -T -C fi if [ $ERR_CODE -eq 2 ] || [ $ERR_CODE -eq 3 ]; then msg \ "o=====================CHECK FAILED======================o" \ "An error ocurred while the root filesystem was checked." \ "" \ "The system should be rebooted or halted." \ "" \ "ERROR CODE: $ERR_CODE" \ "o=======================================================o" \ "" read -p "Press ENTER to reboot (or halt the system)..." exit 100; fi if [ $ERR_CODE -gt 3 ] && [ $ERR_CODE -lt 16 ]; then msg \ "o=====================CHECK FAILED======================o" \ "An error ocurred while the root filesystem was checked." \ "" \ "This is your chance to repair the system manually." \ "For help, check the *fsck utilities according to" \ "your filesystem." \ "" \ "Note:" \ "" \ "The system is currently mounted in read-only mode." \ "To remount the system in read-write mode, type:" \ "" \ "mount -vn -o remount,rw /" \ "" \ "ERROR CODE: $ERR_CODE" \ "o=======================================================o" \ "" read -p "Press ENTER to continue..." exec env - PS1='Repairme:\w# ' su -l -p fi if [ $ERR_CODE -ge 16 ]; then msg "" "Unexpected fsck error: $ERR_CODE" "" fi else msg "/etc/fastboot is present: Dodging checking." fi msg "Remounting root filesystem in read-write mode ..." mount -vn -o remount,rw / # In a modern GNU/Linux distributions like Dragora, # /etc/mtab is a symlink to /proc/mounts: rm -f /etc/mtab* ln -s /proc/mounts /etc/mtab # Enable swap partition(s) -- again: swapon -a -e # Load the kernel parameters: if [ -r /etc/sysctl.conf ]; then msg "[-] Loading kernel parameters via /etc/sysctl.conf ..." sysctl -q -p /etc/sysctl.conf fi # Refresh the kernel modules: msg "Refreshing kernel modules: depmod -A" depmod -A # Load modules from rc: if [ -L /etc/rc.d/rc.modules ] && [ -e /etc/rc.d/rc.modules ]; then RC_MODULES="$(readlink /etc/rc.d/rc.modules)" msg "[-] Loading modules from /etc/rc.d/${RC_MODULES} ..." . /etc/rc.d/${RC_MODULES} fi # Set the ISA Plug-And-Play devices (if any): if [ -x /sbin/isapnp ]; then if [ -r /etc/isapnp.conf ]; then /sbin/isapnp /etc/isapnp.conf else if [ -x /sbin/pnpdump ]; then msg "Detecting ISA Plug-And-Play devices (wait) ..." /sbin/pnpdump > /etc/isapnp.conf msg "Establishing ISA Plug-And-Play devices ..." /sbin/isapnp /etc/isapnp.conf fi fi fi # Mount the USB filesystem (if supported): msg "Mounting usbfs (if supported) ..." if grep -qw usbfs /proc/filesystems ; then if ! grep -wq usbfs /proc/mounts ; then if ! mount -f /proc/bus/usb 2> /dev/null ; then mount -v -t usbfs usbfs /proc/bus/usb else # Mount from fstab: mount -v /proc/bus/usb fi fi fi msg "Mounting local filesystems:" mount -v -a -t no,fs,rootfs,usbfs,devtmpfs,proc,sysfs,devpts # Seek & destroy temporary files: for dir in /var/run /var/lock ; do find $dir ! -type d -delete done rm -rf \ /etc/fastboot \ /etc/forcefsck \ /etc/nologin \ /tmp/.ICE-unix/* \ /tmp/.X11-unix/* \ /tmp/.*-ICE-* \ /tmp/.Xauth* \ /tmp/.X?-lock # Initialize the random number generator: RANDOM_SEED=/etc/random-seed POOLFILE=/proc/sys/kernel/random/poolsize msg "${RANDOM_SEED}: Initializing random number generator." [ -r $RANDOM_SEED ] && cat $RANDOM_SEED > /dev/urandom || touch $RANDOM_SEED; chmod 600 $RANDOM_SEED [ -r $POOLFILE ] && bytes="$(cat $POOLFILE)" || bytes=512; dd if=/dev/urandom of="$RANDOM_SEED" count=1 bs="$bytes" 2> /dev/null # Save the dmesg output: dmesg > /var/log/dmesg # Update the shared libraries: msg "Updating recent shared libraries: ldconfig &" ldconfig & # Set the terminal settings (using APM, if available): setterm -blank 15 -powersave on -powerdown 30 # Load the keyboard map: if [ -x /etc/rc.d/rc.keymap ]; then /etc/rc.d/rc.keymap fi