9 addimage_directory="${3}"
11 modprobe -q -b ${UNIONTYPE}
13 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
15 panic "${UNIONTYPE} not available."
18 # run-init can't deal with images in a subdir, but we're going to
19 # move all of these away before it runs anyway. No, we're not,
20 # put them in / since move-mounting them into / breaks mono and
25 # Let's just mount the read-only file systems first
28 if [ -z "${PLAIN_ROOT}" ]
30 # Read image names from ${MODULE}.module if it exists
31 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
33 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
35 image_string="${image_string} ${image_directory}/${IMAGE}"
37 elif [ -e "${image_directory}/${MODULE}.module" ]
39 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
41 image_string="${image_string} ${image_directory}/${IMAGE}"
44 # ${MODULE}.module does not exist, create a list of images
45 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
47 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
51 image_string="${image_string} ${IMAGE}"
56 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
58 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
60 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
64 image_string="${image_string} ${IMAGE}"
71 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
74 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
78 for image in ${image_string}
80 imagename=$(basename "${image}")
83 maybe_break live-realpremount
84 log_begin_msg "Running /scripts/live-realpremount"
85 run_scripts /scripts/live-realpremount
90 # it is a plain directory: do nothing
91 rootfslist="${image} ${rootfslist}"
92 elif [ -f "${image}" ]
94 if losetup --help 2>&1 | grep -q -- "-r\b"
96 backdev=$(get_backing_device "${image}" "-r")
98 backdev=$(get_backing_device "${image}")
100 fstype=$(get_fstype "${backdev}")
104 panic "Unknown file system type on ${backdev} (${image})"
108 fstype="${imagename##*.}"
109 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
113 mpoint="${croot}/${imagename}"
114 rootfslist="${mpoint} ${rootfslist}"
117 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
118 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
123 # we have a plain root system
124 mkdir -p "${croot}/filesystem"
125 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
126 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
127 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
128 rootfslist="${croot}/filesystem ${rootfslist}"
130 mount -o bind ${croot}/filesystem $mountpoint
136 mkdir -p /live/overlay
137 mount -t tmpfs tmpfs /live/overlay
139 # Looking for persistence devices or files
140 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
143 if [ -z "${QUICKUSBMODULES}" ]
146 num_block=$(ls -l /sys/block | wc -l)
147 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
149 modprobe -q -b ${module}
155 # For some reason, udevsettle does not block in this scenario,
156 # so we sleep for a little while.
158 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
159 for timeout in 5 4 3 2 1
163 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
172 if [ -n "${PERSISTENCE_MEDIA}" ]
174 case "${PERSISTENCE_MEDIA}" in
176 whitelistdev="$(removable_dev)"
180 whitelistdev="$(removable_usb_dev)"
183 if [ -z "${whitelistdev}" ]
185 whitelistdev="ignore_all_devices"
189 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
191 overlays="${custom_overlay_label}"
194 local overlay_devices
196 if [ "${whitelistdev}" != "ignore_all_devices" ]
198 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
200 media="$(echo ${media} | tr ":" " ")"
203 ${custom_overlay_label}=*)
205 overlay_devices="${overlay_devices} ${device}"
210 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
212 # check if there are any nfs options
213 if echo ${NFS_COW} | grep -q ','
215 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
216 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
218 nfs_cow_opts="-o nolock"
222 if [ -n "${PERSISTENCE_READONLY}" ]
224 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
230 cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/")
233 panic "unable to determine mac address"
237 if [ -z "${cowdevice}" ]
241 cow_mountopt="rw,noatime,mode=755"
244 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
246 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
247 root_backing="/live/persistence/$(basename ${cowdevice})-root"
248 mkdir -p ${root_backing}
250 root_backing="/live/overlay"
253 if [ "${cow_fstype}" = "nfs" ]
256 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
257 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
258 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
260 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
261 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
264 rootfscount=$(echo ${rootfslist} |wc -w)
266 rootfs=${rootfslist%% }
268 if [ -n "${EXPOSED_ROOT}" ]
270 if [ ${rootfscount} -ne 1 ]
272 panic "only one RO file system supported with exposedroot: ${rootfslist}"
275 mount --bind ${rootfs} ${rootmnt} || \
276 panic "bind mount of ${rootfs} failed"
278 if [ -z "${SKIP_UNION_MOUNTS}" ]
280 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
288 for dir in ${cow_dirs}; do
289 unionmountpoint="${rootmnt}${dir}"
290 mkdir -p ${unionmountpoint}
291 cow_dir="/live/overlay${dir}"
292 rootfs_dir="${rootfs}${dir}"
294 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
296 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
298 do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
299 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
302 # Remove persistence depending on boot parameter
305 # Correct the permissions of /:
306 chmod 0755 "${rootmnt}"
308 # Correct the permission of /tmp:
309 if [ -d "${rootmnt}/tmp" ]
311 chmod 1777 "${rootmnt}"/tmp
315 for d in ${rootfslist}
317 live_rootfs="/live/rootfs/${d##*/}"
318 live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
319 mkdir -p "${live_rootfs}"
322 # do nothing # mount -o bind "${d}" "${live_rootfs}"
325 mount -o move "${d}" "${live_rootfs}"
330 # Adding custom persistence
331 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
334 custom_mounts="/tmp/custom_mounts.list"
335 rm -f ${custom_mounts}
337 # Gather information about custom mounts from devies detected as overlays
338 get_custom_mounts ${custom_mounts} ${overlay_devices}
340 [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
342 # Now we do the actual mounting (and symlinking)
345 used_overlays=$(activate_custom_mounts ${custom_mounts})
346 rm -f ${custom_mounts}
348 # Close unused overlays (e.g. due to missing $persistence_list)
349 for overlay in ${overlay_devices}
351 if echo ${used_overlays} | grep -qve "^\(.* \)\?${overlay}\( .*\)\?$"
353 close_persistence_media ${overlay}
358 # ensure that a potentially stray tmpfs gets removed
359 # otherways, initramfs-tools is unable to remove /live
361 umount /live/overlay > /dev/null 2>&1 || true