#!/bin/sh # # /etc/rc.d/rc.S: System initialization script. # # Mostly written by: Patrick J. Volkerding, # Zenly modified by: JP Guillemin, # PATH=/sbin:/usr/sbin:/bin:/usr/bin . /etc/shell-colors # Mount /proc right away: /sbin/mount -v proc /proc -n -t proc echo -e "${BOLDMAGENTA}System initialization${COLOR_RESET}" # Check for splash availability SPLASHSCREEN="no" [[ -x /sbin/splash && -e /proc/splash ]] && export SPLASHSCREEN="yes" progressbar() { echo "show $(( 65534 * $1 / 100 ))" > /proc/splash } #### Progress bar #### [ "$SPLASHSCREEN" = "yes" ] && (progressbar 5 ; sleep 0.2; \ progressbar 10 ; sleep 0.2; \ progressbar 15 ; sleep 0.2; \ progressbar 20 ; sleep 0.2; \ progressbar 25 ; sleep 0.2; \ progressbar 30 ; sleep 0.2; \ progressbar 35 ) & # Mount sysfs next: mkdir /sys 2>/dev/null if ! cat /proc/mounts | grep -w sysfs 1> /dev/null 2> /dev/null ; then /sbin/mount -v sysfs /sys -n -t sysfs fi if [ -x /etc/rc.d/rc.udev ]; then echo -e "${BOLDCYAN}Starting udev${COLOR_RESET}" /etc/rc.d/rc.udev start 1>/dev/null 2>/dev/null fi #### Progress bar #### [ "$SPLASHSCREEN" = "yes" ] && progressbar 40 & # Test to see if the root partition is read-only, like it ought to be. READWRITE=no if touch /fsrwtestfile 2>/dev/null; then rm -f /fsrwtestfile READWRITE=yes else echo -e "${BOLDCYAN}Testing root filesystem status: read-only filesystem${COLOR_RESET}" fi # See if a forced filesystem check was requested at shutdown: if [ -r /etc/forcefsck ]; then FORCEFSCK="-f" fi # Check the root filesystem: if [ ! $READWRITE = yes ]; then RETVAL=0 if [ "$( cat /etc/fstab | grep " / " | grep "ext" 2>/dev/null )" ]; then echo -e "${BOLDCYAN}Testing root filesystem status${COLOR_RESET}" /sbin/fsck $FORCEFSCK -C -a / RETVAL=$? fi # An error code of 2 or higher will require a reboot. if [ $RETVAL -ge 2 ]; then # An error code equal to or greater than 4 means that some errors # could not be corrected. This requires manual attention, so we # offer a chance to try to fix the problem in single-user mode: if [ $RETVAL -ge 4 ]; then echo -e "${BOLDYELLOW}" echo "***********************************************************" echo "*** An error occurred during the root filesystem check. ***" echo "*** You will now be given a chance to log into the ***" echo "*** system in single-user mode to fix the problem. ***" echo "*** ***" echo "*** If you are using the ext2 filesystem, running ***" echo "*** 'e2fsck -v -y ' might help. ***" echo "***********************************************************" echo echo "Once you exit the single-user shell, the system will reboot." echo -e "${COLOR_RESET}" PS1="(Repair filesystem) \#"; export PS1 sulogin else # With an error code of 2 or 3, reboot the machine automatically: echo -e "${BOLDYELLOW}" echo "***********************************" echo "*** The filesystem was changed. ***" echo "*** The system will now reboot. ***" echo "***********************************" echo -e "${COLOR_RESET}" fi echo "Unmounting file systems." /sbin/umount -a -r /sbin/mount -n -o remount,ro / echo "Rebooting system." sleep 2 reboot -f fi # Remount the root filesystem in read-write mode echo -e "${BOLDCYAN}Remounting root device with read-write enabled${COLOR_RESET}" /sbin/mount -w -v -n -o remount / if [ $? -gt 0 ] ; then echo -e "${BOLDYELLOW}" echo "Attempt to remount root device as read-write failed! This is going to" echo "cause serious problems." echo echo "You can get into your system by using a command like this on the LILO" echo "prompt line: (change the root partition name as needed)" echo echo "LILO: mount root=/dev/hda1 rw" echo echo "Please press ENTER to continue, then reboot and use one of the above methods to" echo -n "get into your machine and start looking for the problem. " echo -e "${COLOR_RESET}" read junk; fi fi # Done checking root filesystem #### Progress bar #### [ "$SPLASHSCREEN" = "yes" ] && progressbar 45 & # Any /etc/mtab that exists here is old, so we delete it to start over: /bin/rm -f /etc/mtab* # Remounting the / partition will initialize the new /etc/mtab: /sbin/mount -w -o remount / # Fix /etc/mtab to list sys and proc if they were not yet entered in # /etc/mtab because / was still mounted read-only: if [ -d /proc/sys ]; then /sbin/mount -f proc /proc -t proc fi if [ -d /sys/bus ]; then /sbin/mount -f sysfs /sys -t sysfs fi # Set the system time from the hardware clock using hwclock --hctosys. if [ -x /sbin/hwclock ]; then # Check for a broken motherboard RTC clock (where ioports for rtc are # unknown) to prevent hwclock causing a hang: if ! grep -q -w rtc /proc/ioports ; then CLOCK_OPT="--directisa" fi if grep "^UTC" /etc/hardwareclock 1> /dev/null 2> /dev/null ; then echo -e "${BOLDWHITE}Setting system time from the hardware clock (UTC)${COLOR_RESET}" /sbin/hwclock $CLOCK_OPT --utc --hctosys else echo -e "${BOLDWHITE}Setting system time from the hardware clock (localtime)${COLOR_RESET}" /sbin/hwclock $CLOCK_OPT --localtime --hctosys fi fi #### Progress bar #### [ "$SPLASHSCREEN" = "yes" ] && progressbar 50 & # This loads any kernel modules that are needed. These might be required to # use your ethernet card, sound card, or other optional hardware. if [ -x /etc/rc.d/rc.modules -a -r /proc/modules ]; then . /etc/rc.d/rc.modules fi # Configure runtime kernel parameters: if [ -x /sbin/sysctl -a -r /etc/sysctl.conf ]; then /sbin/sysctl -e -p /etc/sysctl.conf fi # Configure runtime IO scheduler for device in $(mount | sed -n 's/.*\/\(sd[a-z]\)[0-9].*/\1/p' | sort -u) ; do echo '0' > /sys/block/$device/queue/iosched/slice_idle done # Initialize the Logical Volume Manager. # This won't start unless we find /etc/lvmtab (LVM1) or # /etc/lvm/backup/ (LVM2). This is created by /sbin/vgscan, so to # use LVM you must run /sbin/vgscan yourself the first time (and # create some VGs and LVs). if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then echo -e "${BOLDWHITE}Initializing LVM (Logical Volume Manager)${COLOR_RESET}" # Check for device-mapper support. if ! cat /proc/devices | grep -w device-mapper 1> /dev/null 2> /dev/null ; then # If device-mapper exists as a module, try to load it. if [ -r /lib/modules/$(/bin/uname -r)/kernel/drivers/md/dm-mod.ko ]; then insmod /lib/modules/$(/bin/uname -r)/kernel/drivers/md/dm-mod.ko fi fi # Scan for new volume groups: /sbin/vgscan --mknodes --ignorelockingfailure 2> /dev/null if [ $? = 0 ]; then # Make volume groups available to the kernel. # This should also make logical volumes available. /sbin/vgchange -ay --ignorelockingfailure # Enable swapping again in case any LVs are used for swap. Ignore previous error. :-) /sbin/swapon -a fi fi # Check all the non-root filesystems: if [ ! -r /etc/fastboot ]; then echo -e "${BOLDCYAN}Checking non-root filesystems${COLOR_RESET}" /sbin/fsck $FORCEFSCK -C -R -A -a fi # mount non-root file systems in fstab (but not NFS or SMB # because TCP/IP is not yet configured, and not proc or sysfs # because those have already been mounted): /sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs #### Progress bar #### [ "$SPLASHSCREEN" = "yes" ] && progressbar 55 & # Enable swapping again. This is needed in case a swapfile is used, # as it can't be enabled until the filesystem it resides on has been # mounted read-write. /sbin/swapon -a # Clean up some temporary files: ( cd /var/log/setup/tmp && rm -rf * ) /bin/rm -f /var/run/utmp /var/run/*pid /etc/nologin /var/run/lpd* \ /var/run/ppp* /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot # Create a fresh utmp file: touch /var/run/utmp chown root:utmp /var/run/utmp chmod 664 /var/run/utmp # Setup the /etc/motd to reflect the current kernel level: # THIS WIPES ANY CHANGES YOU MAKE TO /ETC/MOTD WITH EACH BOOT. # COMMENT THIS OUT IF YOU WANT TO MAKE A CUSTOM VERSION. echo "Zenwalk $(/bin/uname -sr)." > /etc/motd # Update /dev/urandom if [ -f /etc/random-seed ]; then echo -e "${BOLDWHITE}Using /etc/random-seed to initialize /dev/urandom${COLOR_RESET}" cat /etc/random-seed > /dev/urandom fi # Update the shared library links (if needed at first boot, else leave this for rc.6) if [[ -x /sbin/ldconfig && ! -e /etc/ld.so.cache ]]; then echo -e "${BOLDWHITE}Updating shared library links${COLOR_RESET}" /sbin/ldconfig & fi # Check quotas and then turn quota system on: if grep -q quota /etc/fstab ; then if [ -x /sbin/quotacheck ]; then echo -e "${BOLDWHITE}Checking filesystem quotas: /sbin/quotacheck -avugm${COLOR_RESET}" /sbin/quotacheck -avugm fi if [ -x /sbin/quotaon ]; then echo -e "${BOLDWHITE}Activating filesystem quotas: /sbin/quotaon -avug${COLOR_RESET}" /sbin/quotaon -avug fi fi