Patch by Steven Shiau <steven@nchc.org.tw>. The only changes so far are:
[live-boot-grml.git] / components / 0020-read-only
1 #!/bin/sh
2
3 #set -e
4
5 Read_only ()
6 {
7         for _PARAMETER in ${LIVE_BOOT_CMDLINE}
8         do
9                 case "${_PARAMETER}" in
10                         live-boot.read-only=*|read-only=*)
11                                 LIVE_READ_ONLY="true"
12                                 LIVE_READ_ONLY_DEVICES="${_PARAMETER#*read-only=}"
13                                 ;;
14
15                         live-boot.read-only|read-only)
16                                 LIVE_READ_ONLY="true"
17                                 ;;
18                 esac
19         done
20
21         case "${LIVE_READ_ONLY}" in
22                 true)
23                         ;;
24
25                 *)
26                         return 0
27                         ;;
28         esac
29
30         # Marking some block devices as read-only to ensure that nothing
31         # gets written as linux still writes to 'only' read-only mounted filesystems.
32         LIVE_READ_ONLY_DEVICES="${LIVE_READ_ONLY_DEVICES:-/dev/sd* /dev/vd*}"
33
34         for _DEVICE in $(echo ${LIVE_READ_ONLY_DEVICES} | sed -e 's|,| |g')
35         do
36                 if [ ! -b "${_DEVICE}" ]
37                 then
38                         continue
39                 fi
40
41                 echo -n "live-boot: Setting ${_DEVICE} read-only..." > /dev/console
42
43                 blockdev --setro ${_DEVICE}
44                 _RETURN="${?}"
45
46                 case "${_RETURN}" in
47                         0)
48                                 echo " done, use 'blockdev --setrw ${_DEVICE}' to set read-write." > /dev/console
49                                 ;;
50
51                         *)
52                                 echo " failed." > /dev/console
53                                 ;;
54                 esac
55         done
56 }