9 addimage_directory="${3}"
12 aufs|unionfs|overlayfs)
13 modprobe -q -b ${UNIONTYPE}
15 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
17 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
18 echo "This might be really slow."
20 UNIONTYPE="unionfs-fuse"
25 case "${UNIONTYPE}" in
31 # run-init can't deal with images in a subdir, but we're going to
32 # move all of these away before it runs anyway. No, we're not,
33 # put them in / since move-mounting them into / breaks mono and
38 # Let's just mount the read-only file systems first
41 if [ -z "${PLAIN_ROOT}" ]
43 # Read image names from ${MODULE}.module if it exists
44 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
46 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
48 image_string="${image_string} ${image_directory}/${IMAGE}"
50 elif [ -e "${image_directory}/${MODULE}.module" ]
52 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
54 image_string="${image_string} ${image_directory}/${IMAGE}"
57 # ${MODULE}.module does not exist, create a list of images
58 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
60 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
64 image_string="${image_string} ${IMAGE}"
69 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
71 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
73 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
77 image_string="${image_string} ${IMAGE}"
84 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
87 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
91 for image in ${image_string}
93 imagename=$(basename "${image}")
96 maybe_break live-realpremount
97 log_begin_msg "Running /scripts/live-realpremount"
98 run_scripts /scripts/live-realpremount
103 # it is a plain directory: do nothing
104 rootfslist="${image} ${rootfslist}"
105 elif [ -f "${image}" ]
107 if losetup --help 2>&1 | grep -q -- "-r\b"
109 backdev=$(get_backing_device "${image}" "-r")
111 backdev=$(get_backing_device "${image}")
113 fstype=$(get_fstype "${backdev}")
117 panic "Unknown file system type on ${backdev} (${image})"
121 fstype="${imagename##*.}"
122 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
126 case "${UNIONTYPE}" in
129 rootfslist="${rootmnt} ${rootfslist}"
133 mpoint="${croot}/${imagename}"
134 rootfslist="${mpoint} ${rootfslist}"
139 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
140 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
145 # we have a plain root system
146 mkdir -p "${croot}/filesystem"
147 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
148 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
149 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
150 rootfslist="${croot}/filesystem ${rootfslist}"
152 mount -o bind ${croot}/filesystem $mountpoint
158 mkdir -p /live/overlay
159 mount -t tmpfs tmpfs /live/overlay
161 # Looking for persistence devices or files
162 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
165 if [ -z "${QUICKUSBMODULES}" ]
168 num_block=$(ls -l /sys/block | wc -l)
169 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
171 modprobe -q -b ${module}
177 # For some reason, udevsettle does not block in this scenario,
178 # so we sleep for a little while.
180 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
181 for timeout in 5 4 3 2 1
185 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
192 local whitelistdev=""
193 if [ -n "${PERSISTENCE_MEDIA}" ]
195 case "${PERSISTENCE_MEDIA}" in
197 whitelistdev="$(removable_dev)"
201 whitelistdev="$(removable_usb_dev)"
204 if [ -z "${whitelistdev}" ]
206 whitelistdev="ignore_all_devices"
210 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
212 overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
215 local overlay_devices=""
216 if [ "${whitelistdev}" != "ignore_all_devices" ]
218 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
220 media="$(echo ${media} | tr ":" " ")"
223 ${old_root_overlay_label}=*)
225 fix_backwards_compatibility ${device} / union
226 overlay_devices="${overlay_devices} ${device}"
229 ${old_home_overlay_label}=*)
231 fix_backwards_compatibility ${device} /home bind
232 overlay_devices="${overlay_devices} ${device}"
235 ${custom_overlay_label}=*)
237 overlay_devices="${overlay_devices} ${device}"
242 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
244 # check if there are any nfs options
245 if echo ${NFS_COW} | grep -q ','
247 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
248 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
250 nfs_cow_opts="-o nolock"
254 if [ -n "${PERSISTENCE_READONLY}" ]
256 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
262 cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/")
265 panic "unable to determine mac address"
269 if [ -z "${cowdevice}" ]
273 cow_mountopt="rw,noatime,mode=755"
276 if [ "${UNIONTYPE}" != "unionmount" ]
278 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
280 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
281 root_backing="/live/persistence/$(basename ${cowdevice})-root"
282 mkdir -p ${root_backing}
284 root_backing="/live/overlay"
287 if [ "${cow_fstype}" = "nfs" ]
290 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
291 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
292 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
294 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
295 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
299 rootfscount=$(echo ${rootfslist} |wc -w)
301 rootfs=${rootfslist%% }
303 if [ -n "${EXPOSED_ROOT}" ]
305 if [ ${rootfscount} -ne 1 ]
307 panic "only one RO file system supported with exposedroot: ${rootfslist}"
310 mount --bind ${rootfs} ${rootmnt} || \
311 panic "bind mount of ${rootfs} failed"
313 if [ -z "${SKIP_UNION_MOUNTS}" ]
315 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
323 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
325 true # FIXME: Maybe it does, I don't really know.
326 #panic "unionmount does not support subunions (${cow_dirs})."
329 for dir in ${cow_dirs}; do
330 unionmountpoint="${rootmnt}${dir}"
331 mkdir -p ${unionmountpoint}
332 if [ "${UNIONTYPE}" = "unionmount" ]
334 # FIXME: handle PERSISTENCE_READONLY
335 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
336 mount_full $unionmountopts "${unionmountpoint}"
338 cow_dir="/live/overlay${dir}"
339 rootfs_dir="${rootfs}${dir}"
341 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
343 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
345 do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
347 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
350 # Correct the permissions of /:
351 chmod 0755 "${rootmnt}"
353 # Correct the permission of /tmp:
354 if [ -d "${rootmnt}/tmp" ]
356 chmod 1777 "${rootmnt}"/tmp
360 for d in ${rootfslist}
362 live_rootfs="/live/rootfs/${d##*/}"
363 live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
364 mkdir -p "${live_rootfs}"
367 # do nothing # mount -o bind "${d}" "${live_rootfs}"
370 case "${UNIONTYPE}" in
372 mount -o bind "${d}" "${live_rootfs}"
376 mount -o move "${d}" "${live_rootfs}"
383 # move all /live mountpoints that the custom persistence
384 # system depends on into /lib/live on the root filesystem
385 for _DIRECTORY in rootfs
387 if [ -d "/live/${_DIRECTORY}" ]
389 mkdir -p "${rootmnt}/lib/live/mount/${_DIRECTORY}"
391 for _MOUNT in $(ls /live/${_DIRECTORY})
393 mkdir -p "${rootmnt}/lib/live/mount/${_DIRECTORY}/${_MOUNT}"
394 mount -o move "/live/${_DIRECTORY}/${_MOUNT}" "${rootmnt}/lib/live/mount/${_DIRECTORY}/${_MOUNT}" > /dev/null 2>&1 || \
395 mount -o bind "/live/${_DIRECTORY}/${_MOUNT}" "${rootmnt}/lib/live/mount/${_DIRECTORY}/${_MOUNT}" || \
396 log_warning_msg "W: failed to mount /live/${_DIRECTORY}/${_MOUNT} to ${rootmnt}/lib/live/mount/${_DIRECTORY}/${_MOUNT}"
401 mkdir -p "${rootmnt}/lib/live/mount/overlay"
402 mount -o move /live/overlay "${rootmnt}/lib/live/mount/overlay" > /dev/null 2>&1 || \
403 mount -o bind /live/overlay "${rootmnt}/lib/live/mount/overlay" || \
404 log_warning_msg "W: failed to mount /live/overlay to ${rootmnt}/lib/live/mount/overlay"
406 # Adding custom persistence
407 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
409 local custom_mounts="/tmp/custom_mounts.list"
410 rm -rf ${custom_mounts} 2> /dev/null
412 # Gather information about custom mounts from devies detected as overlays
413 get_custom_mounts ${custom_mounts} ${overlay_devices}
415 [ -n "${DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
417 # Now we do the actual mounting (and symlinking)
418 local used_overlays=""
419 used_overlays=$(activate_custom_mounts ${custom_mounts})
422 # Close unused overlays (e.g. due to missing $persistence_list)
423 for overlay in ${overlay_devices}
425 if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
427 close_persistence_media ${overlay}
432 # ensure that a potentially stray tmpfs gets removed
433 # otherways, initramfs-tools is unable to remove /live
435 umount /live/overlay || true