Making persistent-read-only work for home-rw overlays.
[live-boot-grml.git] / scripts / live
index 688c0a7..a8ac678 100755 (executable)
@@ -262,6 +262,10 @@ Arguments ()
                                PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
                                export PERSISTENT_PATH
                                ;;
+                       persistent-read-only)
+                               PERSISTENT_READONLY="Yes"
+                               export PERSISTENT_READONLY
+                               ;;
 
                        persistent-storage=*)
                                PERSISTENT_STORAGE="${ARGUMENT#persistent-storage=}"
@@ -391,19 +395,23 @@ Arguments ()
                export UNIONTYPE
        fi
 
-       if [ "${PERSISTENT_ENCRYPTION}" = "luks" ]
+       if [ -z "${PERSISTENT_ENCRYPTION}" ]
+       then
+               PERSISTENT_ENCRYPTION="none"
+               export PERSISTENT_ENCRYPTION
+       elif echo ${PERSISTENT_ENCRYPTION} | grep -qw luks
        then
                if ! modprobe dm-crypt
                then
                        log_warning_msg "Unable to load module dm-crypt"
-                       PERSISTENT_ENCRYPTION="none"
+                       PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
                        export PERSISTENT_ENCRYPTION
                fi
 
                if [ ! -x /lib/cryptsetup/askpass ] || [ ! -x /sbin/cryptsetup ]
                then
                        log_warning_msg "cryptsetup in unavailable"
-                       PERSISTENT_ENCRYPTION="none"
+                       PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
                        export PERSISTENT_ENCRYPTION
                fi
        fi
@@ -1186,7 +1194,10 @@ try_snap ()
                return 1
        fi
 
-       echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
+       if [ -z ${PERSISTENT_READONLY} ]
+       then
+               echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
+       fi
        return 0
 }
 
@@ -1567,7 +1578,17 @@ setup_unionfs ()
 
                if [ -b "${homecow}" ]
                then
-                       mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
+                       if [ -z "${PERSISTENT_READONLY}" ]
+                       then
+                               mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
+                       else
+                               homerw="/cow/home"
+                               homero="/$(basename ${homecow})-backing"
+                               homemountpoint="${rootmnt}/home"
+                               mkdir -p ${homerw} ${homero} ${homemountpoint}
+                               mount -t $(get_fstype "${homecow}") -o ro "${homecow}" "${homero}"
+                               mount -t "${UNIONTYPE}" -o "noatime,${noxino_opt}dirs=${homerw}=rw:${homero}=${roopt}" "${UNIONTYPE}" "${homemountpoint}"
+                       fi
                        export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
                else
                        log_warning_msg "Unable to find the persistent home medium"