#! /bin/sh ### BEGIN INIT INFO # Provides: umountroot # Required-Start: # Required-Stop: # Should-Stop: halt reboot kexec # Default-Start: # Default-Stop: 0 6 # Short-Description: Mount the root filesystem read-only. ### END INIT INFO global PATH := '/sbin:/bin' source /lib/init/vars.sh source /lib/lsb/init-functions proc do_stop { test $VERBOSE = no || log_action_begin_msg "Mounting root filesystem read-only" # Ask init to re-exec itself before we go down if it has been # upgraded this cycle. It'll lose all its state, but at least # it won't hold open files on the root filesystem (lp:#672177). if test -f /var/run/init.upgraded { global old_map := $[ cat /proc/1/maps] global map := $old_map telinit u || : global i := '0' global timeout := '5' while [ "$map" = "$old_map" ] { sleep 1 global map := $[ cat /proc/1/maps] /usr/bin/logger "waiting for init to respawn" global i := $(i+1) if test $i -eq $timeout { break } } if test $map = $old_map { /usr/bin/logger "FAIL: init failed to respawn in $timeout seconds - unmounting anyway" } else { /usr/bin/logger "SUCCESS: init respawned after $i seconds (within $timeout seconds timeout)" } } global MOUNT_FORCE_OPT := '' test $[uname -s] = "GNU/kFreeBSD" && global MOUNT_FORCE_OPT := '-f' # This: # mount -n -o remount,ro / # will act on a bind mount of / if there is one. # See #339023 and the comment in checkroot.sh mount $MOUNT_FORCE_OPT -n -o remount,ro -t dummytype dummydev / !2 >/dev/null \ || mount $MOUNT_FORCE_OPT -n -o remount,ro dummydev / !2 >/dev/null \ || mount $MOUNT_FORCE_OPT -n -o remount,ro / global ES := $Status test $VERBOSE = no || log_action_end_msg $ES } matchstr $1 { start|status { # No-op } restart|reload|force-reload { echo "Error: argument '$1' not supported" > !2 exit 3 } stop { do_stop } * { echo "Usage: $0 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)} spids: [31] ) ] spids: [31] ) (C {(.)} {(/lib/init/vars.sh)}) (C {(.)} {(/lib/lsb/init-functions)}) (FuncDef name: do_stop body: (BraceGroup children: [ (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(Lit_Other "=")} {(no)} {(Lit_Other "]")} ) (C {(log_action_begin_msg)} {(DQ ("Mounting root filesystem read-only"))}) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [(C {(Lit_Other "[")} {(-f)} {(/var/run/init.upgraded)} {(Lit_Other "]")})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:old_map) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(cat)} {(/proc/1/maps)})]) left_token: spids: [102 108] ) } spids: [101] ) ] spids: [101] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:map) op: Equal rhs: {($ VSub_Name "$old_map")} spids: [111] ) ] spids: [111] ) (AndOr children: [(C {(telinit)} {(u)}) (C {(Lit_Other ":")})] op_id: Op_DPipe ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:i) op:Equal rhs:{(0)} spids:[124])] spids: [124] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:timeout) op:Equal rhs:{(5)} spids:[128])] spids: [128] ) (While cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$map"))} {(Lit_Other "=")} {(DQ ($ VSub_Name "$old_map"))} {(Lit_Other "]")} ) ] body: (DoGroup children: [ (C {(sleep)} {(1)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:map) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(cat)} {(/proc/1/maps)})] ) left_token: spids: [158 164] ) } spids: [157] ) ] spids: [157] ) (C {(/usr/bin/logger)} {(DQ ("waiting for init to respawn"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:i) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:i) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [175 180] ) } spids: [174] ) ] spids: [174] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$i")} {(-eq)} {($ VSub_Name "$timeout")} {(Lit_Other "]")} ) terminator: ) ] action: [(ControlFlow token:)] spids: [-1 197] ) ] spids: [-1 203] ) ] spids: [149 206] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$map"))} {(Lit_Other "=")} {(DQ ($ VSub_Name "$old_map"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(/usr/bin/logger)} { (DQ ("FAIL: init failed to respawn in ") ($ VSub_Name "$timeout") (" seconds - unmounting anyway") ) } ) ] spids: [-1 228] ) ] else_action: [ (C {(/usr/bin/logger)} { (DQ ("SUCCESS: init respawned after ") ($ VSub_Name "$i") (" seconds (within ") ($ VSub_Name "$timeout") (" seconds timeout)") ) } ) ] spids: [240 254] ) ] spids: [-1 98] ) ] spids: [-1 257] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MOUNT_FORCE_OPT) op: Equal rhs: {(SQ )} spids: [261] ) ] spids: [261] ) (AndOr children: [ (C {(Lit_Other "[")} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(uname)} {(-s)})]) left_token: spids: [267 271] ) ) } {(Lit_Other "=")} {(DQ (GNU/kFreeBSD))} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MOUNT_FORCE_OPT) op: Equal rhs: {(-f)} spids: [284] ) ] spids: [284] ) ] op_id: Op_DAmp ) (AndOr children: [ (SimpleCommand words: [ {(mount)} {($ VSub_Name "$MOUNT_FORCE_OPT")} {(-n)} {(-o)} {(remount) (Lit_Comma ",") (ro)} {(-t)} {(dummytype)} {(dummydev)} {(/)} ] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[324])] ) (AndOr children: [ (SimpleCommand words: [ {(mount)} {($ VSub_Name "$MOUNT_FORCE_OPT")} {(-n)} {(-o)} {(remount) (Lit_Comma ",") (ro)} {(dummydev)} {(/)} ] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[347])] ) (C {(mount)} {($ VSub_Name "$MOUNT_FORCE_OPT")} {(-n)} {(-o)} {(remount) (Lit_Comma ",") (ro)} {(/)} ) ] op_id: Op_DPipe ) ] op_id: Op_DPipe ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ES) op: Equal rhs: {($ VSub_QMark "$?")} spids: [369] ) ] spids: [369] ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(Lit_Other "=")} {(no)} {(Lit_Other "]")} ) (C {(log_action_end_msg)} {($ VSub_Name "$ES")}) ] op_id: Op_DPipe ) ] spids: [51] ) spids: [46 50] ) (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list:[{(start)}{(status)}] spids:[403406413-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:[432])] ) (C {(exit)} {(3)}) ] spids: [416 421 441 -1] ) (case_arm pat_list:[{(stop)}] action:[(C {(do_stop)})] spids:[444445451-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Usage: ") ($ VSub_Number "$0") (" start|stop"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[466])] ) (C {(exit)} {(3)}) ] spids: [454 455 475 -1] ) ] spids: [394 400 477] ) (C {(Lit_Other ":")}) ] )