948c2d569a0a8ac06668be23fff1eed93ed12d02
[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                                 ;;
13                 esac
14         done
15
16         if [ "${LIVE_READ_ONLY}" != "true" ]
17         then
18                 return 0
19         fi
20
21         # Marking some block devices as read-only to ensure that nothing
22         # gets written as linux still writes to 'only' read-only mounted filesystems.
23         _DEVICES="/dev/sd* /dev/vd*"
24
25         for _DEVICE in ${_DEVICES}
26         do
27                 if [ ! -b "${_DEVICE}" ]
28                 then
29                         continue
30                 fi
31
32                 echo -n "live-boot: Setting ${_DEVICE} read-only..." > /dev/console
33
34                 blockdev --setro ${_DEVICE}
35                 _RETURN="${?}"
36
37                 case "${_RETURN}" in
38                         0)
39                                 echo " done, use 'blockdev --setrw ${_DEVICE}' to set read-write." > /dev/console
40                                 ;;
41
42                         *)
43                                 echo " failed." > /dev/console
44                                 ;;
45                 esac
46         done
47 }