+mount_persistent_media ()
+{
+ local device=${1}
+ local backing=""
+
+ # We can't mount into ${rootmnt}/live before ${rootmnt} has been
+ # mounted since that would cover our mountpoint.
+ if [ -n "${rootmnt}" ] && [ -z "$(what_is_mounted_on ${rootmnt})" ]
+ then
+ backing="/$(basename ${device})-backing"
+ else
+ backing="${rootmnt}/live/persistent/$(basename ${device})"
+ fi
+
+ mkdir -p "${backing}"
+ local old_backing="$(where_is_mounted ${device})"
+ if [ -z "${old_backing}" ]
+ then
+ local fstype="$(get_fstype ${device})"
+ local mount_opts="rw,noatime"
+ if [ -n "${PERSISTENT_READONLY}" ]
+ then
+ mount_opts="ro,noatime"
+ fi
+ if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
+ then
+ echo ${backing}
+ return 0
+ else
+ log_warning_msg "Failed to mount persistent media ${device}"
+ return 1
+ fi
+ elif [ "${backing}" != "${old_backing}" ]
+ then
+ if mount --move ${old_backing} ${backing} >/dev/null
+ then
+ echo ${backing}
+ return 0
+ else
+ log_warning_msg "Failed to move persistent media ${device}"
+ return 1
+ fi
+ fi
+ return 0
+}
+
+close_persistent_media () {
+ local device=${1}
+ local backing="$(where_is_mounted ${device})"
+
+ if [ -d "${backing}" ]
+ then
+ umount "${backing}" >/dev/null 2>&1
+ rmdir "${backing}" >/dev/null 2>&1
+ fi
+
+ if is_active_luks_mapping ${device}
+ then
+ /sbin/cryptsetup luksClose ${device}
+ fi
+}
+