1 | 3 | czfcentos | #!/bin/bash |
2 | | | |
3 | | | echo -n "Re-mounting root ... " |
4 | | | |
5 | | | if mount / -noremount,ro,noatime; then |
6 | | | echo "done." |
7 | | | echo Root is now read-only. |
8 | | | exit 0 |
9 | | | else |
10 | | | if [[ "$1" == "-f" ]]; then |
11 | | | echo Filesystem busy, forcing remount. |
12 | | | |
13 | | | echo -n Locating data partitions ... |
14 | | | NODEV=`echo \`grep < /proc/filesystems nodev | awk '{print "^" $2 "|"}'\` | sed -e "s/ //g" -e "s/|$//g"` |
15 | | | RWFS=`awk < /proc/mounts "\\$4 ~ \"^rw\" { if (\\$1!=\"none\" && \\$2!=\"/\" && \\$3 !~ /$NODEV/) print \\$2}"` |
16 | | | echo " done." |
17 | | | |
18 | | | echo -n Syncing filesystems ... |
19 | | | sync |
20 | | | echo " done." |
21 | | | |
22 | | | echo -n Re-mounting everything read-only ... |
23 | | | echo u > /proc/sysrq-trigger |
24 | | | echo " done." |
25 | | | |
26 | | | if [[ $RWFS ]]; then |
27 | | | echo -n Re-mounting data partitions read-write: |
28 | | | for FS in $RWFS; do |
29 | | | echo -n " [$FS]" |
30 | | | mount $FS -noremount,rw,noatime |
31 | | | done |
32 | | | echo " done." |
33 | | | fi |
34 | | | echo Root is now read-only. |
35 | | | exit 0 |
36 | | | fi |
37 | | | echo Failed. If you\'re sure you know what are you doing, try \"mro -f\". |
38 | | | exit 1 |
39 | | | fi |
40 | | | |
41 | | | |