#!/bin/bash # # fsck, mount, set quotas, and relabel filesystems. # . /etc/init.d/functions PLYMOUTH= [ -x /usr/bin/plymouth ] && PLYMOUTH=yes # Check SELinux status SELINUX_STATE= if [ -e "/selinux/enforce" ] && [ "$(cat /proc/self/attr/current)" != "kernel" ]; then if [ -r "/selinux/enforce" ] ; then SELINUX_STATE=$(cat "/selinux/enforce") else # assume enforcing if you can't read it SELINUX_STATE=1 fi fi disable_selinux() { echo $"*** Warning -- SELinux is active" echo $"*** Disabling security enforcement for system recovery." echo $"*** Run 'setenforce 1' to reenable." echo "0" > "/selinux/enforce" } relabel_selinux() { # if /sbin/init is not labeled correctly this process is running in the # wrong context, so a reboot will be required after relabel AUTORELABEL= . /etc/selinux/config echo "0" > /selinux/enforce [ -n "$PLYMOUTH" ] && plymouth --hide-splash if [ "$AUTORELABEL" = "0" ]; then echo echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required. " echo $"*** /etc/selinux/config indicates you want to manually fix labeling" echo $"*** problems. Dropping you to a shell; the system will reboot" echo $"*** when you leave the shell." sulogin else echo echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required." echo $"*** Relabeling could take a very long time, depending on file" echo $"*** system size and speed of hard drives." /sbin/fixfiles -F restore > /dev/null 2>&1 fi rm -f /.autorelabel echo $"Unmounting file systems" umount -a mount -n -o remount,ro / echo $"Automatic reboot in progress." reboot -f } [ -z "${cmdline}" ] && cmdline=$(cat /proc/cmdline) if [ -f /fastboot ] || strstr "$cmdline" fastboot ; then fastboot=yes fi if [ -f /fsckoptions ]; then fsckoptions=$(cat /fsckoptions) fi if [ -f /forcefsck ] || strstr "$cmdline" forcefsck ; then fsckoptions="-f $fsckoptions" elif [ -f /.autofsck ]; then [ -f /etc/sysconfig/autofsck ] && . /etc/sysconfig/autofsck if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then AUTOFSCK_OPT="$AUTOFSCK_OPT -f" fi if [ -n "$AUTOFSCK_SINGLEUSER" ]; then [ -n "$PLYMOUTH" ] && plymouth --hide-splash echo echo $"*** Warning -- the system did not shut down cleanly. " echo $"*** Dropping you to a shell; the system will continue" echo $"*** when you leave the shell." [ -n "$SELINUX_STATE" ] && echo "0" > /selinux/enforce sulogin [ -n "$SELINUX_STATE" ] && echo "1" > /selinux/enforce [ -n "$PLYMOUTH" ] && plymouth --show-splash fi fsckoptions="$AUTOFSCK_OPT $fsckoptions" fi if [ "$BOOTUP" = "color" ]; then fsckoptions="-C $fsckoptions" else fsckoptions="-V $fsckoptions" fi READONLY= if [ -f /etc/sysconfig/readonly-root ]; then . /etc/sysconfig/readonly-root fi if strstr "$cmdline" readonlyroot ; then READONLY=yes [ -z "$RW_MOUNT" ] && RW_MOUNT=/var/lib/stateless/writable [ -z "$STATE_MOUNT" ] && STATE_MOUNT=/var/lib/stateless/state fi if strstr "$cmdline" noreadonlyroot ; then READONLY=no fi if [[ " $fsckoptions" != *" -y"* ]]; then fsckoptions="-a $fsckoptions" fi _RUN_QUOTACHECK=0 if strstr "$cmdline" forcequotacheck || [ -f /forcequotacheck ] ; then _RUN_QUOTACHECK=1 fi if [ -z "$fastboot" -a "$READONLY" != "yes" ]; then STRING=$"Checking filesystems" echo $STRING fsck -T -t noopts=_netdev -A $fsckoptions rc=$? if [ "$rc" -eq "0" ]; then success "$STRING" echo elif [ "$rc" -eq "1" ]; then passed "$STRING" echo elif [ "$rc" -eq "2" -o "$rc" -eq "3" ]; then echo $"Unmounting file systems" umount -a mount -n -o remount,ro / echo $"Automatic reboot in progress." reboot -f fi # A return of 4 or higher means there were serious problems. if [ $rc -gt 1 ]; then [ -n "$PLYMOUTH" ] && plymouth --hide-splash failure "$STRING" echo echo echo $"*** An error occurred during the file system check." echo $"*** Dropping you to a shell; the system will reboot" echo $"*** when you leave the shell." str=$"(Repair filesystem)" PS1="$str \# # "; export PS1 [ "$SELINUX_STATE" = "1" ] && disable_selinux sulogin echo $"Unmounting file systems" umount -a mount -n -o remount,ro / echo $"Automatic reboot in progress." reboot -f elif [ "$rc" -eq "1" ]; then _RUN_QUOTACHECK=1 fi fi remount_needed() { local state oldifs [ "$READONLY" = "yes" ] && return 1 state=$(LC_ALL=C awk '/ \/ / && ($3 !~ /rootfs/) { print $4 }' /proc/mounts) oldifs=$IFS IFS="," for opt in $state ; do if [ "$opt" = "rw" ]; then IFS=$oldifs return 1 fi done IFS=$oldifs return 0 } # Remount the root filesystem read-write. update_boot_stage RCmountfs if remount_needed ; then action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw / fi # Clean up SELinux labels if [ -n "$SELINUX_STATE" ]; then restorecon /etc/mtab /etc/ld.so.cache /etc/blkid/blkid.tab /etc/resolv.conf >/dev/null 2>&1 fi # If relabeling, relabel mount points. if [ -n "$SELINUX_STATE" -a "$READONLY" != "yes" ]; then if strstr "$cmdline" autorelabel || [ -f /.autorelabel ] ; then restorecon $(awk '!/^#/ && $4 !~ /noauto/ && $2 ~ /^\// { print $2 }' /etc/fstab) >/dev/null 2>&1 fi fi if [ "$READONLY" != "yes" ] ; then # Clear mtab (> /etc/mtab) &> /dev/null # Remove stale backups rm -f /etc/mtab~ /etc/mtab~~ # Enter mounted filesystems into /etc/mtab mount -f / mount -f /proc >/dev/null 2>&1 mount -f /sys >/dev/null 2>&1 mount -f /dev/pts >/dev/null 2>&1 mount -f /dev/shm >/dev/null 2>&1 mount -f /proc/bus/usb >/dev/null 2>&1 fi # Mount all other filesystems (except for NFS and /proc, which is already # mounted). Contrary to standard usage, # filesystems are NOT unmounted in single user mode. if [ "$READONLY" != "yes" ] ; then action $"Mounting local filesystems: " mount -a -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2 -O no_netdev else action $"Mounting local filesystems: " mount -a -n -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2 -O no_netdev fi # Update quotas if necessary if [ X"$_RUN_QUOTACHECK" = X1 ] && [ -x /sbin/quotacheck ]; then action $"Checking local filesystem quotas: " /sbin/quotacheck -anug fi if [ -x /sbin/quotaon ]; then action $"Enabling local filesystem quotas: " /sbin/quotaon -aug fi # Check to see if a full relabel is needed if [ -n "$SELINUX_STATE" -a "$READONLY" != "yes" ]; then if strstr "$cmdline" autorelabel || [ -f /.autorelabel ] ; then relabel_selinux fi else if [ "$READONLY" != "yes" ] && [ -d /etc/selinux ]; then [ -f /.autorelabel ] || touch /.autorelabel fi fi