5 kx #!/bin/sh
5 kx #
5 kx # /etc/rc.d/rc.S: System initialization script.
5 kx #
5 kx # Written by: Patrick J. Volkerding, <volkerdi@slackware.com>
406 kx # Modified by: Andrey V. Kosteltsev, <kx@radix-linux.su>
5 kx #
5 kx
5 kx PATH=/sbin:/usr/local/sbin:/bin:/usr/local/bin:/usr/sbin:/usr/bin
5 kx
5 kx # Mount /proc if it is not already mounted:
5 kx if [ ! -d /proc/sys ]; then
5 kx /sbin/mount -v proc /proc -n -t proc 2> /dev/null
5 kx fi
5 kx
5 kx # Mount /sys if it is not already mounted:
5 kx if [ ! -d /sys/kernel ]; then
5 kx /sbin/mount -v sysfs /sys -n -t sysfs 2> /dev/null
5 kx fi
5 kx
5 kx # If /run exists, mount a tmpfs on it (unless the initrd has already done so):
5 kx if [ -d /run ]; then
5 kx if ! grep -wq "tmpfs /run tmpfs" /proc/mounts ; then
5 kx /sbin/mount -v -n -t tmpfs tmpfs /run -o mode=0755,size=32M,nodev,nosuid,noexec
5 kx fi
5 kx fi
5 kx
5 kx # Load the loop device kernel module (not applicable on OMAP5):
5 kx if [ -x /etc/rc.d/rc.loop ]; then
5 kx /etc/rc.d/rc.loop start
5 kx fi
5 kx
5 kx
5 kx # Initialize udev to manage /dev entries and hotplugging for 3.x kernels.
5 kx # You may turn off udev by making the /etc/rc.d/rc.udev file non-executable
5 kx # or giving the "nohotplug" option at boot, but realize that if you turn off
5 kx # udev that you will have to load all the kernel modules that you need
5 kx # yourself (possibly in /etc/rc.d/rc.modules, which does not promise to list
5 kx # all of them), and make any additional device nodes that you need in the
5 kx # /dev directory. Even USB and IEEE1394 devices will need to have the
5 kx # modules loaded by hand if udev is not used. So use it. :-)
5 kx if grep -wq sysfs /proc/mounts && grep -q devtmpfs /proc/filesystems ; then
5 kx if ! grep -wq nohotplug /proc/cmdline ; then
5 kx if [ -x /etc/rc.d/rc.udev ]; then
5 kx /etc/rc.d/rc.udev start
5 kx fi
5 kx fi
5 kx fi
5 kx
5 kx # Mount Control Groups filesystem interface:
5 kx if grep -wq cgroup /proc/filesystems ; then
5 kx if [ -d /sys/fs/cgroup ]; then
5 kx # See linux-*/Documentation/cgroups/cgroups.txt (section 1.6)
5 kx # Check if we have some tools to autodetect the available cgroup controllers
5 kx if [ -x /bin/cut -a -x /bin/tail ]; then
5 kx # Mount a tmpfs as the cgroup filesystem root
5 kx mount -t tmpfs -o mode=0755,size=8M cgroup_root /sys/fs/cgroup
5 kx # Autodetect available controllers and mount them in subfolders
5 kx controllers="$(/bin/cut -f 1 /proc/cgroups | /bin/tail -n +2)"
5 kx for i in $controllers; do
5 kx mkdir /sys/fs/cgroup/$i
5 kx mount -t cgroup -o $i $i /sys/fs/cgroup/$i
5 kx done
5 kx unset i controllers
5 kx else
5 kx # We can't use autodetection so fall back mounting them all together
5 kx mount -t cgroup cgroup /sys/fs/cgroup
5 kx fi
5 kx else
5 kx mkdir -p /dev/cgroup
5 kx mount -t cgroup cgroup /dev/cgroup
5 kx fi
5 kx fi
5 kx
5 kx # Initialize the Logical Volume Manager.
5 kx # This won't start unless we find /etc/lvmtab (LVM1) or
5 kx # /etc/lvm/backup/ (LVM2). This is created by /sbin/vgscan, so to
5 kx # use LVM you must run /sbin/vgscan yourself the first time (and
5 kx # create some VGs and LVs).
5 kx # Create LVM lock/run directories:
5 kx mkdir -p -m 0700 /run/lvm /run/lock /run/lock/lvm
5 kx if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
5 kx echo "Initializing LVM (Logical Volume Manager):"
5 kx # Check for device-mapper support.
5 kx if ! grep -wq device-mapper /proc/devices ; then
5 kx # Try to load a device-mapper kernel module:
5 kx /sbin/modprobe -q dm-mod
5 kx fi
5 kx # Scan for new volume groups:
5 kx /sbin/vgscan --mknodes --ignorelockingfailure 2> /dev/null
5 kx if [ $? = 0 ]; then
5 kx # Make volume groups available to the kernel.
5 kx # This should also make logical volumes available.
5 kx /sbin/vgchange -ay --ignorelockingfailure
5 kx fi
5 kx fi
5 kx
5 kx # Open any volumes created by cryptsetup:
5 kx #
5 kx # Some notes on /etc/crypttab in Slackware:
5 kx # Only LUKS formatted volumes are supported (except for swap)
5 kx # crypttab follows the following format:
5 kx # <luks_name> <device> <password> <options>
5 kx #
5 kx # <luks_name>: This is the name of your LUKS volume.
5 kx # For example: crypt-home
5 kx #
5 kx # <device>: This is the device containing your LUKS volume.
5 kx # For example: /dev/sda2
5 kx #
5 kx # <password>: This is either the volume password in plain text, or the name of
5 kx # a key file. Use 'none' to interactively enter password on boot.
5 kx #
5 kx # <options>: Comma-separated list of options. Note that there must be a
5 kx # password field for any options to be picked up (use a password of 'none' to
5 kx # get a password prompt at boot). The following options are supported:
5 kx #
5 kx # discard -- this will cause --allow-discards to be passed to the cryptsetup
5 kx # program while opening the LUKS volume.
5 kx #
5 kx # ro -- this will cause --readonly to be passed to the cryptsetup program while
5 kx # opening the LUKS volume.
5 kx #
5 kx # swap -- this option cannot be used with other options. The device given will
5 kx # be formatted as a new encrypted volume with a random key on boot, and used as
5 kx # swap.
5 kx #
5 kx if [ -f /etc/crypttab -a -x /sbin/cryptsetup ]; then
5 kx # First, check for device-mapper support.
5 kx if ! grep -wq device-mapper /proc/devices ; then
5 kx # If device-mapper exists as a module, try to load it.
5 kx # Try to load a device-mapper kernel module:
5 kx /sbin/modprobe -q dm-mod
5 kx fi
5 kx # NOTE: we only support LUKS formatted volumes (except for swap)!
5 kx cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do
5 kx eval LUKSARRAY=( $line )
5 kx LUKS="${LUKSARRAY[0]}"
5 kx DEV="${LUKSARRAY[1]}"
5 kx PASS="${LUKSARRAY[2]}"
5 kx OPTS="${LUKSARRAY[3]}"
5 kx LUKSOPTS=""
5 kx if echo $OPTS | grep -wq ro ; then LUKSOPTS="${LUKSOPTS} --readonly" ; fi
5 kx if echo $OPTS | grep -wq discard ; then LUKSOPTS="${LUKSOPTS} --allow-discards" ; fi
5 kx # Skip LUKS volumes that were already unlocked (in the initrd):
5 kx /sbin/cryptsetup status $LUKS 2>/dev/null | head -n 1 | grep -q "is active" && continue
5 kx if /sbin/cryptsetup isLuks $DEV 2>/dev/null ; then
5 kx if [ -z "${LUKSOPTS}" ]; then
5 kx echo "Unlocking LUKS encrypted volume '${LUKS}' on device '$DEV':"
5 kx else
5 kx echo "Unlocking LUKS encrypted volume '${LUKS}' on device '$DEV' with options '${LUKSOPTS}':"
5 kx fi
5 kx if [ -n "${PASS}" -a "${PASS}" != "none" ]; then
5 kx if [ -f "${PASS}" ]; then
5 kx # A password was given a key-file filename
5 kx /sbin/cryptsetup ${LUKSOPTS} --key-file=${PASS} luksOpen $DEV $LUKS
5 kx else
5 kx # A password was provided in plain text
5 kx echo "${PASS}" | /sbin/cryptsetup ${LUKSOPTS} luksOpen $DEV $LUKS
5 kx fi
5 kx else
5 kx # No password was given, or a password of 'none' was given
5 kx /sbin/cryptsetup ${LUKSOPTS} luksOpen $DEV $LUKS </dev/tty0 >/dev/tty0 2>&1
5 kx fi
5 kx elif echo $OPTS | grep -wq swap ; then
5 kx # If any of the volumes is to be used as encrypted swap,
5 kx # then encrypt it using a random key and run mkswap:
5 kx echo "Creating encrypted swap volume '${LUKS}' on device '$DEV':"
5 kx /sbin/cryptsetup --cipher=aes --key-file=/dev/urandom --key-size=256 create $LUKS $DEV
5 kx mkswap /dev/mapper/$LUKS
5 kx fi
5 kx done
5 kx fi
5 kx
5 kx # Enable swapping:
5 kx /sbin/swapon -a 2> /dev/null
5 kx
5 kx ## Start FUSE, if requested:
5 kx #if [ -x /etc/rc.d/rc.fuse ]; then
5 kx # /etc/rc.d/rc.fuse start
5 kx #fi
5 kx
5 kx # Set the tick and frequency for the system clock.
5 kx # Default values are: TICK=10000 and FREQ=0
5 kx TICK=10000
5 kx FREQ=0
5 kx # If there's a /etc/default/adjtimex config file, source it to override
5 kx # the default TICK and FREQ:
5 kx if [ -r /etc/default/adjtimex ]; then
5 kx . /etc/default/adjtimex
5 kx fi
5 kx if /sbin/adjtimex --tick $TICK --frequency $FREQ; then
5 kx echo "Setting the system clock rate: /sbin/adjtimex --tick $TICK --frequency $FREQ"
5 kx else
5 kx echo "Failed to set system clock with adjtimex, possibly invalid parameters? (TICK=$TICK FREQ=$FREQ)"
5 kx fi
5 kx
5 kx # Set the system time from the hardware clock using hwclock --hctosys.
5 kx if [ -x /sbin/hwclock ]; then
5 kx # Check for a broken motherboard RTC clock (where ioports for rtc are
5 kx # unknown) to prevent hwclock causing a hang:
5 kx if ! grep -q " : rtc" /proc/ioports ; then
5 kx CLOCK_OPT="--directisa"
5 kx fi
5 kx if [ /etc/adjtime -nt /etc/hardwareclock ]; then
5 kx if grep -q "^LOCAL" /etc/adjtime ; then
5 kx echo -n "Setting system time from the hardware clock (localtime): "
5 kx else
5 kx echo -n "Setting system time from the hardware clock (UTC): "
5 kx fi
5 kx /sbin/hwclock $CLOCK_OPT --hctosys
5 kx elif grep -wq "^localtime" /etc/hardwareclock 2> /dev/null ; then
5 kx echo -n "Setting system time from the hardware clock (localtime): "
5 kx /sbin/hwclock $CLOCK_OPT --localtime --hctosys
5 kx else
5 kx echo -n "Setting system time from the hardware clock (UTC): "
5 kx /sbin/hwclock $CLOCK_OPT --utc --hctosys
5 kx fi
5 kx date
5 kx fi
5 kx
5 kx #######
5 kx ####### TODO: Test to see if the root partition is read-only, like it ought to be.
5 kx #######
5 kx
5 kx ## Test to see if the root partition is read-only, like it ought to be.
5 kx #READWRITE=no
5 kx #if touch /fsrwtestfile 2>/dev/null; then
5 kx # rm -f /fsrwtestfile
5 kx # READWRITE=yes
5 kx #else
5 kx # echo "Testing root filesystem status: read-only filesystem"
5 kx #fi
5 kx #
5 kx ## See if a forced filesystem check was requested at shutdown:
5 kx #if [ -r /etc/forcefsck ]; then
5 kx # FORCEFSCK="-f"
5 kx #fi
5 kx #
5 kx ## If we're using F2FS for the root filesystem, don't check it as it doesn't
5 kx ## allow checking a read-only filesystem:
5 kx #if grep -q ' / f2fs ' /proc/mounts ; then
5 kx # echo "Remounting root device with read-write enabled."
5 kx # /sbin/mount -w -v -n -o remount /
5 kx #elif [ ! $READWRITE = yes ]; then
5 kx # # Check the root filesystem:
5 kx # RETVAL=0
5 kx # if [ ! -r /etc/fastboot ]; then
5 kx # echo "Checking root filesystem:"
5 kx # /sbin/fsck $FORCEFSCK -C -a /
5 kx # RETVAL=$?
5 kx # fi
5 kx # # An error code of 2 or higher will require a reboot.
5 kx # if [ $RETVAL -ge 2 ]; then
5 kx # # An error code equal to or greater than 4 means that some errors
5 kx # # could not be corrected. This requires manual attention, so we
5 kx # # offer a chance to try to fix the problem in single-user mode:
5 kx # if [ $RETVAL -ge 4 ]; then
5 kx # echo
5 kx # echo "***********************************************************"
5 kx # echo "*** An error occurred during the root filesystem check. ***"
5 kx # echo "*** You will now be given a chance to log into the ***"
5 kx # echo "*** system in single-user mode to fix the problem. ***"
5 kx # echo "*** ***"
5 kx # echo "*** If you are using the ext2 filesystem, running ***"
5 kx # echo "*** 'e2fsck -v -y <partition>' might help. ***"
5 kx # echo "***********************************************************"
5 kx # echo
5 kx # echo "Once you exit the single-user shell, the system will reboot."
5 kx # echo
5 kx # PS1="(Repair filesystem) \#"; export PS1
5 kx # sulogin
5 kx # else # With an error code of 2 or 3, reboot the machine automatically:
5 kx # echo
5 kx # echo "***********************************"
5 kx # echo "*** The filesystem was changed. ***"
5 kx # echo "*** The system will now reboot. ***"
5 kx # echo "***********************************"
5 kx # echo
5 kx # fi
5 kx # echo "Unmounting file systems."
5 kx # /sbin/umount -a -r
5 kx # /sbin/mount -n -o remount,ro /
5 kx # echo "Rebooting system."
5 kx # reboot -f
5 kx # fi
5 kx # # Remount the root filesystem in read-write mode
5 kx # echo "Remounting root device with read-write enabled:"
5 kx # /sbin/mount -w -v -n -o remount /
5 kx # if [ $? -gt 0 ] ; then
5 kx # echo "FATAL: Attempt to remount root device as read-write failed! This is going to"
5 kx # echo "cause serious problems."
5 kx # fi
5 kx #else
5 kx # echo "Testing root filesystem status: read-write filesystem"
5 kx # echo
5 kx # echo "ERROR: Root partition has already been mounted read-write. Cannot check!"
5 kx # echo
5 kx # echo "For filesystem checking to work properly, your system must initially mount"
5 kx # echo "the root partition as read only. If you're booting with LILO, add a line:"
5 kx # echo
5 kx # echo " read-only"
5 kx # echo
5 kx # echo "to the Linux section in your /etc/lilo.conf and type 'lilo' to reinstall it."
5 kx #fi # Done checking root filesystem
5 kx
5 kx
5 kx echo "Remounting root device with read-write enabled:"
5 kx /sbin/mount -w -v -n -o remount /
5 kx #######
5 kx #######
5 kx #######
5 kx
5 kx
5 kx # If /etc/mtab is a symlink (probably to /proc/mounts) then we don't want to mess with it.
5 kx if [ ! -L /etc/mtab -o ! -r /etc/mtab ]; then
5 kx # /etc/mtab is a file (or doesn't exist), so we'll handle it the old way:
5 kx # Any /etc/mtab that exists here is old, so we start with a new one:
5 kx /bin/rm -f /etc/mtab{,~,.tmp} && /bin/touch /etc/mtab
5 kx # Add /, /proc, /sys, and /dev/shm mounts to /etc/mtab:
5 kx /sbin/mount -f -w /
5 kx if [ -d /proc/sys ]; then
5 kx /sbin/mount -f -t proc proc /proc
5 kx fi
5 kx if [ -d /sys/bus ]; then
5 kx /sbin/mount -f -t sysfs sysfs /sys
5 kx fi
5 kx if grep -q '^[^ ]\+ /dev/shm ' /proc/mounts 2> /dev/null ; then
5 kx /sbin/mount -f -t tmpfs tmpfs /dev/shm
5 kx fi
5 kx fi
5 kx
5 kx # Configure ISA Plug-and-Play devices:
5 kx if [ -r /etc/isapnp.conf ]; then
5 kx if [ -x /sbin/isapnp ]; then
5 kx /sbin/isapnp /etc/isapnp.conf
5 kx fi
5 kx fi
5 kx
5 kx
5 kx # Run the kernel module script. This updates the module dependencies and
5 kx # also supports manually loading kernel modules through rc.modules.local.
5 kx if [ -x /etc/rc.d/rc.modules ]; then
5 kx /etc/rc.d/rc.modules
5 kx fi
5 kx
5 kx # Configure kernel parameters:
5 kx if [ -x /sbin/sysctl -a -r /etc/sysctl.conf ]; then
5 kx echo "Configuring kernel parameters: /sbin/sysctl -e --system"
5 kx /sbin/sysctl -e --system
5 kx elif [ -x /sbin/sysctl ]; then
5 kx echo "Configuring kernel parameters: /sbin/sysctl -e --system"
5 kx # Don't say "Applying /etc/sysctl.conf" or complain if the file doesn't exist
5 kx /sbin/sysctl -e --system 2> /dev/null | grep -v "Applying /etc/sysctl.conf"
5 kx fi
5 kx
5 kx # Check all the non-root filesystems:
5 kx if [ ! -r /etc/fastboot ]; then
5 kx echo "Checking non-root filesystems:"
5 kx /sbin/fsck $FORCEFSCK -C -R -A -a
5 kx fi
5 kx
5 kx # Mount usbfs only if it is found in /etc/fstab:
5 kx if grep -wq usbfs /proc/filesystems; then
5 kx if ! grep -wq usbfs /proc/mounts ; then
5 kx if grep -wq usbfs /etc/fstab; then
5 kx /sbin/mount -v /proc/bus/usb
5 kx fi
5 kx fi
5 kx fi
5 kx
5 kx # Mount non-root file systems in fstab, but not NFS or SMB
5 kx # because TCP/IP is not yet configured, and not proc or sysfs
5 kx # because those have already been mounted. Also check that
5 kx # devpts is not already mounted before attempting to mount
5 kx # it. With a 2.6.x or newer kernel udev mounts devpts.
5 kx echo "Mounting non-root local filesystems:"
5 kx if /bin/grep -wq devpts /proc/mounts ; then
5 kx # This pipe after the mount command is just to convert the new
5 kx # mount verbose output back to the old format that contained
5 kx # more useful information:
5 kx /sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs,nodevpts | grep successfully | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep " ${dev} " ; done
5 kx else
5 kx /sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs | grep successfully | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep " ${dev} " ; done
5 kx fi
5 kx
5 kx # Make sure that /var/run is a symbolic link pointing to /run:
5 kx if [ -d /run -a ! -L /var/run ]; then
5 kx (cd /var ; rm -rf run ; ln -sf /run run)
5 kx fi
5 kx
5 kx # Enable swapping again. This is needed in case a swapfile is used,
5 kx # as it can't be enabled until the filesystem it resides on has been
5 kx # mounted read-write.
5 kx /sbin/swapon -a 2> /dev/null
5 kx
5 kx # Start libcgroup services:
5 kx if [ -x /etc/rc.d/rc.cgconfig -a -x /etc/rc.d/rc.cgred -a -d /sys/fs/cgroup ]; then
5 kx /etc/rc.d/rc.cgconfig start ; echo " /usr/sbin/cgconfigparser -l /etc/cgconfig.conf"
5 kx /etc/rc.d/rc.cgred start
5 kx fi
5 kx
5 kx # Clean up some temporary files:
5 kx rm -f /etc/nologin /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
5 kx /var/state/saslauthd/saslauthd.pid /tmp/.Xauth* 1> /dev/null 2> /dev/null
5 kx rm -rf /tmp/{kde-[a-zA-Z]*,ksocket-[a-zA-Z]*,hsperfdata_[a-zA-Z]*,plugtmp*}
5 kx if [ -d /var/lib/@DISTRO@/setup/tmp ]; then
5 kx ( cd /var/lib/@DISTRO@/setup/tmp && rm -rf * )
5 kx fi
5 kx
5 kx # Clear /var/lock/subsys:
5 kx if [ -d /var/lock/subsys ]; then
5 kx rm -f /var/lock/subsys/*
5 kx fi
5 kx
5 kx # Create /tmp/{.ICE-unix,.X11-unix} if they are not present:
5 kx if [ ! -e /tmp/.ICE-unix ]; then
5 kx mkdir -p /tmp/.ICE-unix
5 kx chmod 1777 /tmp/.ICE-unix
5 kx fi
5 kx if [ ! -e /tmp/.X11-unix ]; then
5 kx mkdir -p /tmp/.X11-unix
5 kx chmod 1777 /tmp/.X11-unix
5 kx fi
5 kx
5 kx # Create a fresh utmp file:
5 kx touch /var/run/utmp
5 kx chown root:utmp /var/run/utmp
5 kx chmod 664 /var/run/utmp
5 kx
5 kx # In case pam_faillock(8) is being used, create the tally directory:
5 kx mkdir -p /var/run/faillock
5 kx
5 kx # Update the current kernel level in the /etc/motd (Message Of The Day) file,
5 kx # if the first line of that file begins with the word 'Linux'.
5 kx # You are free to modify the rest of the file as you see fit.
5 kx if [ -x /bin/sed ]; then
5 kx /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr)\./}" /etc/motd
5 kx fi
5 kx
5 kx # If there are SystemV init scripts for this runlevel, run them.
5 kx if [ -x /etc/rc.d/rc.sysvinit ]; then
5 kx /etc/rc.d/rc.sysvinit
5 kx fi
5 kx
5 kx # Run serial port setup script:
5 kx # CAREFUL! This can make some systems hang if the rc.serial script isn't
5 kx # set up correctly. If this happens, you may have to edit the file from
5 kx # a boot disk, and/or set it as non-executable:
5 kx if [ -x /etc/rc.d/rc.serial ]; then
5 kx /etc/rc.d/rc.serial start
5 kx fi
5 kx
5 kx # Start the framebuffer setup procedure.
5 kx if [ -x /etc/rc.d/rc.fbset ]; then
5 kx /etc/rc.d/rc.fbset
5 kx fi
5 kx
5 kx # Start the remote control setup procedure.
5 kx if [ -x /etc/rc.d/rc.remote-control ]; then
5 kx /etc/rc.d/rc.remote-control
5 kx fi
5 kx
5 kx # Carry an entropy pool between reboots to improve randomness.
5 kx if [ -f /etc/random-seed ]; then
5 kx echo "Using /etc/random-seed to initialize /dev/urandom."
5 kx cat /etc/random-seed > /dev/urandom
5 kx fi
5 kx # Use the pool size from /proc, or 4096 bits:
5 kx if [ -r /proc/sys/kernel/random/poolsize ]; then
5 kx dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(expr $(cat /proc/sys/kernel/random/poolsize) / 8) 2> /dev/null
5 kx else
5 kx dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
5 kx fi
5 kx chmod 600 /etc/random-seed