9 addimage_directory="${3}"
11 modprobe -q -b ${UNIONTYPE}
13 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
15 panic "${UNIONTYPE} not available."
18 croot="/run/live/rootfs"
20 # Let's just mount the read-only file systems first
23 if [ -z "${PLAIN_ROOT}" ]
25 # Read image names from ${MODULE}.module if it exists
26 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
28 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
30 image_string="${image_string} ${image_directory}/${IMAGE}"
32 elif [ -e "${image_directory}/${MODULE}.module" ]
34 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
36 image_string="${image_string} ${image_directory}/${IMAGE}"
39 # ${MODULE}.module does not exist, create a list of images
40 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
42 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
46 image_string="${image_string} ${IMAGE}"
51 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
53 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
55 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
59 image_string="${image_string} ${IMAGE}"
66 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
69 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
73 for image in ${image_string}
75 imagename=$(basename "${image}")
78 maybe_break live-realpremount
79 log_begin_msg "Running /scripts/live-realpremount"
80 run_scripts /scripts/live-realpremount
85 # it is a plain directory: do nothing
86 rootfslist="${image} ${rootfslist}"
87 elif [ -f "${image}" ]
89 if losetup --help 2>&1 | grep -q -- "-r\b"
91 backdev=$(get_backing_device "${image}" "-r")
93 backdev=$(get_backing_device "${image}")
95 fstype=$(get_fstype "${backdev}")
99 panic "Unknown file system type on ${backdev} (${image})"
103 fstype="${imagename##*.}"
104 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
108 mpoint=$(trim_path "${croot}/${imagename}")
109 rootfslist="${mpoint} ${rootfslist}"
112 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
113 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
116 log_warning_msg "Could not find image '${image}'. Most likely it is listed in a .module file, perhaps by mistake."
120 # we have a plain root system
121 mkdir -p "${croot}/filesystem"
122 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
123 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
124 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
125 rootfslist="${croot}/filesystem ${rootfslist}"
127 mount -o bind ${croot}/filesystem $mountpoint
133 mkdir -p /run/live/overlay
135 # Looking for persistence devices or files
136 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
139 if [ -z "${QUICKUSBMODULES}" ]
142 num_block=$(ls -l /sys/block | wc -l)
143 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
145 modprobe -q -b ${module}
151 # For some reason, udevsettle does not block in this scenario,
152 # so we sleep for a little while.
154 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
155 for timeout in 5 4 3 2 1
159 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
168 if [ -n "${PERSISTENCE_MEDIA}" ]
170 case "${PERSISTENCE_MEDIA}" in
172 whitelistdev="$(removable_dev)"
176 whitelistdev="$(removable_usb_dev)"
179 if [ -z "${whitelistdev}" ]
181 whitelistdev="ignore_all_devices"
185 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
187 overlays="${custom_overlay_label}"
190 local overlay_devices
192 if [ "${whitelistdev}" != "ignore_all_devices" ]
194 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
196 media="$(echo ${media} | tr ":" " ")"
199 ${custom_overlay_label}=*)
201 overlay_devices="${overlay_devices} ${device}"
206 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
208 # check if there are any nfs options
209 if echo ${NFS_COW} | grep -q ','
211 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
212 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
214 nfs_cow_opts="-o nolock"
218 if [ -n "${PERSISTENCE_READONLY}" ]
220 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
226 cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/")
229 panic "unable to determine mac address"
233 if [ -z "${cowdevice}" ]
237 cow_mountopt="rw,noatime,mode=755,size=${OVERLAY_SIZE:-50%}"
240 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
242 mount -t tmpfs -o rw,noatime,mode=755,size=${OVERLAY_SIZE:-50%} tmpfs "/live/overlay"
243 root_backing="/run/live/persistence/$(basename ${cowdevice})-root"
244 mkdir -p ${root_backing}
246 root_backing="/run/live/overlay"
249 if [ "${cow_fstype}" = "nfs" ]
252 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
253 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
254 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
256 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
257 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
260 rootfscount=$(echo ${rootfslist} |wc -w)
262 rootfs=${rootfslist%% }
264 if [ -n "${EXPOSED_ROOT}" ]
266 if [ ${rootfscount} -ne 1 ]
268 panic "only one RO file system supported with exposedroot: ${rootfslist}"
271 mount -o bind ${rootfs} ${rootmnt} || \
272 panic "bind mount of ${rootfs} failed"
274 if [ -z "${SKIP_UNION_MOUNTS}" ]
276 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
284 for dir in ${cow_dirs}; do
285 unionmountpoint=$(trim_path "${rootmnt}${dir}")
286 mkdir -p ${unionmountpoint}
287 cow_dir=$(trim_path "/run/live/overlay${dir}")
288 rootfs_dir="${rootfs}${dir}"
290 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
292 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
294 do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
295 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
298 # Remove persistence depending on boot parameter
301 # Correct the permissions of /:
302 chmod 0755 "${rootmnt}"
304 # Correct the permission of /tmp:
305 if [ -d "${rootmnt}/tmp" ]
307 chmod 1777 "${rootmnt}"/tmp
310 # Adding custom persistence
311 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
314 custom_mounts="/tmp/custom_mounts.list"
315 rm -f ${custom_mounts}
317 # Gather information about custom mounts from devies detected as overlays
318 get_custom_mounts ${custom_mounts} ${overlay_devices}
320 [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/run/live/persistence"
322 # Now we do the actual mounting (and symlinking)
325 used_overlays=$(activate_custom_mounts ${custom_mounts})
326 rm -f ${custom_mounts}
328 # Close unused overlays (e.g. due to missing $persistence_list)
329 for overlay in ${overlay_devices}
331 if echo ${used_overlays} | grep -qve "^\(.* \)\?${overlay}\( .*\)\?$"
333 close_persistence_media ${overlay}