1 | 3 | czfcentos | #!/bin/bash |
2 | | | |
3 | | | echo -n "Re-mounting root ... " |
4 | | | |
5 | | | if mount / -noremount,ro; 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 -v \`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 $NODEV |
23 | | | echo $RWFS |
24 | | | echo "ahoj \n" |
25 | | | exit 0 |
26 | | | echo -n Re-mounting everything read-only ... |
27 | | | echo u > /proc/sysrq-trigger |
28 | | | echo " done." |
29 | | | |
30 | | | if [[ $RWFS ]]; then |
31 | | | echo -n Re-mounting data partitions read-write: |
32 | | | for FS in $RWFS; do |
33 | | | echo -n " [$FS]" |
34 | | | mount $FS -noremount,rw |
35 | | | done |
36 | | | echo " done." |
37 | | | fi |
38 | | | echo Root is now read-only. |
39 | | | exit 0 |
40 | | | fi |
41 | | | echo Failed. If you\'re sure you know what are you doing, try \"mro -f\". |
42 | | | exit 1 |
43 | | | fi |
44 | | | |
45 | | | |