#! /bin/sh ### BEGIN INIT INFO # Provides: checkfs # Required-Start: checkroot # Required-Stop: # Should-Start: # Default-Start: S # Default-Stop: # X-Interactive: true # Short-Description: Check all filesystems. ### END INIT INFO # Include /usr/bin in path to find on_ac_power if /usr/ is on the root # partition. global PATH := '/sbin:/bin:/usr/bin' global FSCK_LOGFILE := '/var/log/fsck/checkfs' test $FSCKFIX || global FSCKFIX := 'no' source /lib/init/vars.sh source /lib/lsb/init-functions source /lib/init/mount-functions.sh source /lib/init/swap-functions.sh proc do_start { # Trap SIGINT so that we can handle user interupt of fsck. trap "" INT # See if we're on AC Power. If not, we're not gonna run our # check. If on_ac_power (in /usr/) is unavailable, behave as # before and check all file systems needing it. # Disabled AC power check until fsck can be told to only check the # file system if it is corrupt when running on battery. (bug #526398) # if which on_ac_power >/dev/null 2>&1 # then # on_ac_power >/dev/null 2>&1 # if [ $? -eq 1 ] # then # [ "$VERBOSE" = no ] || log_success_msg "Running on battery power, so skipping file system check." # BAT=yes # fi # fi global BAT := ''"" global fscheck := '"yes'" if is_fastboot_active { test $fscheck = yes && log_warning_msg "Fast boot enabled, so skipping file system check." global fscheck := 'no' } # # Check the rest of the file systems. # if test $fscheck = yes && test ! $BAT && test $FSCKTYPES != "none" { # Execute swapon command again, in case there are lvm # or md swap partitions. fsck can suck RAM. swaponagain 'lvm and md' if test -f /forcefsck || grep -q -s -w -i "forcefsck" /proc/cmdline { global force := '"-f'" } else { global force := ''"" } if test $FSCKFIX = yes { global fix := '"-y'" } else { global fix := '"-a'" } global spinner := '"-C'" matchstr $TERM { dumb|network|unknown|"" { global spinner := ''"" } } test $[uname -m] = s390x && global spinner := ''"" # This should go away global FSCKTYPES_OPT := ''"" test $FSCKTYPES && global FSCKTYPES_OPT := ""-t $FSCKTYPES"" proc handle_failed_fsck { log_failure_msg "File system check failed. A log is being saved in $(FSCK_LOGFILE) if that location is writable. Please repair the file system manually." log_warning_msg "A maintenance shell will now be started. CONTROL-D will terminate this shell and resume system boot." # Start a single user shell on the console if ! sulogin $CONSOLE { log_failure_msg "Attempt to start maintenance shell failed. Continuing with system boot in 5 seconds." sleep 5 } } if test $VERBOSE = no { log_action_begin_msg "Checking file systems" logsave -s $FSCK_LOGFILE fsck $spinner -M -A $fix $force $FSCKTYPES_OPT global FSCKCODE := $Status if test $FSCKCODE -eq 32 { log_action_end_msg 1 "code $FSCKCODE" log_warning_msg "File system check was interrupted by user" } elif test $FSCKCODE -gt 1 { log_action_end_msg 1 "code $FSCKCODE" handle_failed_fsck } else { log_action_end_msg 0 } } else { if test $FSCKTYPES { log_action_msg "Will now check all file systems of types $FSCKTYPES" } else { log_action_msg "Will now check all file systems" } logsave -s $FSCK_LOGFILE fsck $spinner -V -M -A $fix $force $FSCKTYPES_OPT global FSCKCODE := $Status if test $FSCKCODE -eq 32 { log_warning_msg "File system check was interrupted by user" } elif test $FSCKCODE -gt 1 { handle_failed_fsck } else { log_success_msg "Done checking file systems. A log is being saved in $(FSCK_LOGFILE) if that location is writable." } } } rm -f /fastboot /forcefsck !2 >/dev/null } matchstr $1 { start|"" { do_start } restart|reload|force-reload { echo "Error: argument '$1' not supported" > !2 exit 3 } stop|status { # No-op } * { echo "Usage: checkfs.sh [start|stop]" > !2 exit 3 } } : (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: {(/sbin) (Lit_Other ":") (/bin) (Lit_Other ":") (/usr/bin)} spids: [40] ) ] spids: [40] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FSCK_LOGFILE) op: Equal rhs: {(/var/log/fsck/checkfs)} spids: [47] ) ] spids: [47] ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKFIX"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:FSCKFIX) op:Equal rhs:{(no)} spids:[60])] spids: [60] ) ] op_id: Op_DPipe ) (C {(.)} {(/lib/init/vars.sh)}) (C {(.)} {(/lib/lsb/init-functions)}) (C {(.)} {(/lib/init/mount-functions.sh)}) (C {(.)} {(/lib/init/swap-functions.sh)}) (FuncDef name: do_start body: (BraceGroup children: [ (C {(trap)} {(DQ )} {(INT)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:BAT) op:Equal rhs:{(DQ )} spids:[148])] spids: [148] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:fscheck) op:Equal rhs:{(DQ (yes))} spids:[153])] spids: [153] ) (If arms: [ (if_arm cond: [(C {(is_fastboot_active)})] action: [ (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$fscheck"))} {(Lit_Other "=")} {(yes)} {(Lit_Other "]")} ) (C {(log_warning_msg)} {(DQ ("Fast boot enabled, so skipping file system check."))} ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fscheck) op: Equal rhs: {(no)} spids: [189] ) ] spids: [189] ) ] spids: [-1 165] ) ] spids: [-1 193] ) (If arms: [ (if_arm cond: [ (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$fscheck"))} {(Lit_Other "=")} {(yes)} {(Lit_Other "]")} ) (AndOr children: [ (C {(Lit_Other "[")} {(KW_Bang "!")} {(DQ ($ VSub_Name "$BAT"))} {(Lit_Other "]")} ) (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKTYPES"))} {(KW_Bang "!") (Lit_Other "=")} {(DQ (none))} {(Lit_Other "]")} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] action: [ (C {(swaponagain)} {(SQ <"lvm and md">)}) (If arms: [ (if_arm cond: [ (AndOr children: [ (C {(Lit_Other "[")} {(-f)} {(/forcefsck)} {(Lit_Other "]")}) (C {(grep)} {(-q)} {(-s)} {(-w)} {(-i)} {(DQ (forcefsck))} {(/proc/cmdline)}) ] op_id: Op_DPipe ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:force) op: Equal rhs: {(DQ (-f))} spids: [305] ) ] spids: [305] ) ] spids: [-1 302] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:force) op: Equal rhs: {(DQ )} spids: [314] ) ] spids: [314] ) ] spids: [311 319] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKFIX"))} {(Lit_Other "=")} {(yes)} {(Lit_Other "]")} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fix) op: Equal rhs: {(DQ (-y))} spids: [340] ) ] spids: [340] ) ] spids: [-1 337] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fix) op: Equal rhs: {(DQ (-a))} spids: [349] ) ] spids: [349] ) ] spids: [346 355] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:spinner) op: Equal rhs: {(DQ (-C))} spids: [358] ) ] spids: [358] ) (Case to_match: {(DQ ($ VSub_Name "$TERM"))} arms: [ (case_arm pat_list: [{(dumb)} {(network)} {(unknown)} {(DQ )}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:spinner) op: Equal rhs: {(DQ )} spids: [384] ) ] spids: [384] ) ] spids: [373 381 389 -1] ) ] spids: [364 370 392] ) (AndOr children: [ (C {(Lit_Other "[")} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(uname)} {(-m)})]) left_token: spids: [398 402] ) ) } {(Lit_Other "=")} {(s390x)} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:spinner) op: Equal rhs: {(DQ )} spids: [413] ) ] spids: [413] ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FSCKTYPES_OPT) op: Equal rhs: {(DQ )} spids: [421] ) ] spids: [421] ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKTYPES"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FSCKTYPES_OPT) op: Equal rhs: {(DQ ("-t ") ($ VSub_Name "$FSCKTYPES"))} spids: [436] ) ] spids: [436] ) ] op_id: Op_DAmp ) (FuncDef name: handle_failed_fsck body: (BraceGroup children: [ (C {(log_failure_msg)} { (DQ ("File system check failed. \n") ("A log is being saved in ") (${ VSub_Name FSCK_LOGFILE) (" if that location is writable. \n") ("Please repair the file system manually.") ) } ) (C {(log_warning_msg)} { (DQ ("A maintenance shell will now be started. \n") ("CONTROL-D will terminate this shell and resume system boot.") ) } ) (If arms: [ (if_arm cond: [ (Pipeline children: [(C {(sulogin)} {($ VSub_Name "$CONSOLE")})] negated: True ) ] action: [ (C {(log_failure_msg)} { (DQ ("Attempt to start maintenance shell failed. \n") ("Continuing with system boot in 5 seconds.") ) } ) (C {(sleep)} {(5)}) ] spids: [-1 484] ) ] spids: [-1 500] ) ] spids: [447] ) spids: [443 446] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(Lit_Other "=")} {(no)} {(Lit_Other "]")} ) ] action: [ (C {(log_action_begin_msg)} {(DQ ("Checking file systems"))}) (C {(logsave)} {(-s)} {($ VSub_Name "$FSCK_LOGFILE")} {(fsck)} {($ VSub_Name "$spinner")} {(-M)} {(-A)} {($ VSub_Name "$fix")} {($ VSub_Name "$force")} {($ VSub_Name "$FSCKTYPES_OPT")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FSCKCODE) op: Equal rhs: {($ VSub_QMark "$?")} spids: [552] ) ] spids: [552] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKCODE"))} {(-eq)} {(32)} {(Lit_Other "]")} ) ] action: [ (C {(log_action_end_msg)} {(1)} {(DQ ("code ") ($ VSub_Name "$FSCKCODE"))} ) (C {(log_warning_msg)} {(DQ ("File system check was interrupted by user"))} ) ] spids: [-1 572] ) (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKCODE"))} {(-gt)} {(1)} {(Lit_Other "]")} ) ] action: [ (C {(log_action_end_msg)} {(1)} {(DQ ("code ") ($ VSub_Name "$FSCKCODE"))} ) (C {(handle_failed_fsck)}) ] spids: [592 607] ) ] else_action: [(C {(log_action_end_msg)} {(0)})] spids: [623 631] ) ] spids: [-1 521] ) ] else_action: [ (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKTYPES"))} {(Lit_Other "]")}) ] action: [ (C {(log_action_msg)} { (DQ ("Will now check all file systems of types ") ($ VSub_Name "$FSCKTYPES") ) } ) ] spids: [-1 648] ) ] else_action: [ (C {(log_action_msg)} {(DQ ("Will now check all file systems"))}) ] spids: [659 669] ) (C {(logsave)} {(-s)} {($ VSub_Name "$FSCK_LOGFILE")} {(fsck)} {($ VSub_Name "$spinner")} {(-V)} {(-M)} {(-A)} {($ VSub_Name "$fix")} {($ VSub_Name "$force")} {($ VSub_Name "$FSCKTYPES_OPT")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FSCKCODE) op: Equal rhs: {($ VSub_QMark "$?")} spids: [695] ) ] spids: [695] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKCODE"))} {(-eq)} {(32)} {(Lit_Other "]")} ) ] action: [ (C {(log_warning_msg)} {(DQ ("File system check was interrupted by user"))} ) ] spids: [-1 714] ) (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FSCKCODE"))} {(-gt)} {(1)} {(Lit_Other "]")} ) ] action: [(C {(handle_failed_fsck)})] spids: [724 739] ) ] else_action: [ (C {(log_success_msg)} { (DQ ("Done checking file systems. \n") ("A log is being saved in ") (${ VSub_Name FSCK_LOGFILE) (" if that location is writable.") ) } ) ] spids: [745 760] ) ] spids: [634 763] ) ] spids: [-1 253] ) ] spids: [-1 766] ) (SimpleCommand words: [{(rm)} {(-f)} {(/fastboot)} {(/forcefsck)}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[777])] ) ] spids: [86] ) spids: [81 85] ) (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list:[{(start)}{(DQ )}] action:[(C {(do_start)})] spids:[792796802-1]) (case_arm pat_list: [{(restart)} {(reload)} {(force-reload)}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: argument '") ($ VSub_Number "$1") ("' not supported"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[821])] ) (C {(exit)} {(3)}) ] spids: [805 810 830 -1] ) (case_arm pat_list:[{(stop)}{(status)}] spids:[833836843-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Usage: checkfs.sh [start|stop]"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[856])] ) (C {(exit)} {(3)}) ] spids: [846 847 865 -1] ) ] spids: [783 789 867] ) (C {(Lit_Other ":")}) ] )