9 addimage_directory="${3}"
13 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
15 panic "${UNIONTYPE} not available."
18 modprobe -q -b ${UNIONTYPE}
22 # run-init can't deal with images in a subdir, but we're going to
23 # move all of these away before it runs anyway. No, we're not,
24 # put them in / since move-mounting them into / breaks mono and
29 # Let's just mount the read-only file systems first
32 if [ -z "${PLAIN_ROOT}" ]
34 # Read image names from ${MODULE}.module if it exists
35 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
37 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
39 image_string="${image_string} ${image_directory}/${IMAGE}"
41 elif [ -e "${image_directory}/${MODULE}.module" ]
43 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
45 image_string="${image_string} ${image_directory}/${IMAGE}"
48 # ${MODULE}.module does not exist, create a list of images
49 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
51 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
55 image_string="${image_string} ${IMAGE}"
60 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
62 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
64 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
68 image_string="${image_string} ${IMAGE}"
75 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
78 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
82 for image in ${image_string}
84 imagename=$(basename "${image}")
87 maybe_break live-realpremount
88 log_begin_msg "Running /scripts/live-realpremount"
89 run_scripts /scripts/live-realpremount
94 # it is a plain directory: do nothing
95 rootfslist="${image} ${rootfslist}"
96 elif [ -f "${image}" ]
98 if losetup --help 2>&1 | grep -q -- "-r\b"
100 backdev=$(get_backing_device "${image}" "-r")
102 backdev=$(get_backing_device "${image}")
104 fstype=$(get_fstype "${backdev}")
108 panic "Unknown file system type on ${backdev} (${image})"
112 fstype="${imagename##*.}"
113 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
117 case "${UNIONTYPE}" in
120 rootfslist="${rootmnt} ${rootfslist}"
124 mpoint="${croot}/${imagename}"
125 rootfslist="${mpoint} ${rootfslist}"
130 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
131 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
136 # we have a plain root system
137 mkdir -p "${croot}/filesystem"
138 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
139 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
140 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
141 rootfslist="${croot}/filesystem ${rootfslist}"
143 mount -o bind ${croot}/filesystem $mountpoint
149 mkdir -p /live/overlay
150 mount -t tmpfs tmpfs /live/overlay
152 # Looking for persistence devices or files
153 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
156 if [ -z "${QUICKUSBMODULES}" ]
159 num_block=$(ls -l /sys/block | wc -l)
160 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
162 modprobe -q -b ${module}
168 # For some reason, udevsettle does not block in this scenario,
169 # so we sleep for a little while.
171 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
172 for timeout in 5 4 3 2 1
176 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
185 if [ -n "${PERSISTENCE_MEDIA}" ]
187 case "${PERSISTENCE_MEDIA}" in
189 whitelistdev="$(removable_dev)"
193 whitelistdev="$(removable_usb_dev)"
196 if [ -z "${whitelistdev}" ]
198 whitelistdev="ignore_all_devices"
202 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
204 overlays="${custom_overlay_label}"
207 local overlay_devices
209 if [ "${whitelistdev}" != "ignore_all_devices" ]
211 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
213 media="$(echo ${media} | tr ":" " ")"
216 ${custom_overlay_label}=*)
218 overlay_devices="${overlay_devices} ${device}"
223 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
225 # check if there are any nfs options
226 if echo ${NFS_COW} | grep -q ','
228 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
229 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
231 nfs_cow_opts="-o nolock"
235 if [ -n "${PERSISTENCE_READONLY}" ]
237 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
243 cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/")
246 panic "unable to determine mac address"
250 if [ -z "${cowdevice}" ]
254 cow_mountopt="rw,noatime,mode=755"
257 if [ "${UNIONTYPE}" != "unionmount" ]
259 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
261 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
262 root_backing="/live/persistence/$(basename ${cowdevice})-root"
263 mkdir -p ${root_backing}
265 root_backing="/live/overlay"
268 if [ "${cow_fstype}" = "nfs" ]
271 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
272 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
273 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
275 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
276 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
280 rootfscount=$(echo ${rootfslist} |wc -w)
282 rootfs=${rootfslist%% }
284 if [ -n "${EXPOSED_ROOT}" ]
286 if [ ${rootfscount} -ne 1 ]
288 panic "only one RO file system supported with exposedroot: ${rootfslist}"
291 mount --bind ${rootfs} ${rootmnt} || \
292 panic "bind mount of ${rootfs} failed"
294 if [ -z "${SKIP_UNION_MOUNTS}" ]
296 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
304 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
306 true # FIXME: Maybe it does, I don't really know.
307 #panic "unionmount does not support subunions (${cow_dirs})."
310 for dir in ${cow_dirs}; do
311 unionmountpoint="${rootmnt}${dir}"
312 mkdir -p ${unionmountpoint}
313 if [ "${UNIONTYPE}" = "unionmount" ]
315 # FIXME: handle PERSISTENCE_READONLY
316 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
317 # unionmount only works with util-linux mount
318 mount.util-linux $unionmountopts "${unionmountpoint}"
320 cow_dir="/live/overlay${dir}"
321 rootfs_dir="${rootfs}${dir}"
323 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
325 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
327 do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
329 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
332 # Correct the permissions of /:
333 chmod 0755 "${rootmnt}"
335 # Correct the permission of /tmp:
336 if [ -d "${rootmnt}/tmp" ]
338 chmod 1777 "${rootmnt}"/tmp
342 for d in ${rootfslist}
344 live_rootfs="/live/rootfs/${d##*/}"
345 live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
346 mkdir -p "${live_rootfs}"
349 # do nothing # mount -o bind "${d}" "${live_rootfs}"
352 mount -o move "${d}" "${live_rootfs}"
357 # Adding custom persistence
358 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
361 custom_mounts="/tmp/custom_mounts.list"
362 rm -f ${custom_mounts}
364 # Gather information about custom mounts from devies detected as overlays
365 get_custom_mounts ${custom_mounts} ${overlay_devices}
367 [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
369 # Now we do the actual mounting (and symlinking)
372 used_overlays=$(activate_custom_mounts ${custom_mounts})
373 rm -f ${custom_mounts}
375 # Close unused overlays (e.g. due to missing $persistence_list)
376 for overlay in ${overlay_devices}
378 if echo ${used_overlays} | grep -qve "^\(.* \)\?${overlay}\( .*\)\?$"
380 close_persistence_media ${overlay}
385 # ensure that a potentially stray tmpfs gets removed
386 # otherways, initramfs-tools is unable to remove /live
388 umount /live/overlay > /dev/null 2>&1 || true