Extending read-only parameters to allow specifying custom list of devices.
[live-boot-grml.git] / scripts / boot / 0120-read-only
1 #!/bin/sh
2
3 #set -e
4
5 Read_only ()
6 {
7         for _PARAMETER in ${_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         if [ "${LIVE_READ_ONLY}" != "true" ]
22         then
23                 return 0
24         fi
25
26         # Marking some block devices as read-only to ensure that nothing
27         # gets written as linux still writes to 'only' read-only mounted filesystems.
28         LIVE_READ_ONLY_DEVICES="${LIVE_READ_ONLY_DEVICES:-/dev/sd* /dev/vd*}"
29
30         for _DEVICE in $(echo ${LIVE_READ_ONLY_DEVICES} | sed -e 's|,| |g')
31         do
32                 if [ ! -b "${_DEVICE}" ]
33                 then
34                         continue
35                 fi
36
37                 echo -n "live-boot: Setting ${_DEVICE} read-only..." > /dev/console
38
39                 blockdev --setro ${_DEVICE}
40                 _RETURN="${?}"
41
42                 case "${_RETURN}" in
43                         0)
44                                 echo " done, use 'blockdev --setrw ${_DEVICE}' to set read-write." > /dev/console
45                                 ;;
46
47                         *)
48                                 echo " failed." > /dev/console
49                                 ;;
50                 esac
51         done
52 }