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}"
121 log_warning_msg "Could not find image '${image}'. Most likely it is listed in a .module file, perhaps by mistake."
125 # we have a plain root system
126 mkdir -p "${croot}/filesystem"
127 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
128 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
129 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
130 rootfslist="${croot}/filesystem ${rootfslist}"
132 mount -o bind ${croot}/filesystem $mountpoint
138 mkdir -p /live/overlay
139 mount -t tmpfs tmpfs /live/overlay
141 # Looking for persistence devices or files
142 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
145 if [ -z "${QUICKUSBMODULES}" ]
148 num_block=$(ls -l /sys/block | wc -l)
149 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
151 modprobe -q -b ${module}
157 # For some reason, udevsettle does not block in this scenario,
158 # so we sleep for a little while.
160 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
161 for timeout in 5 4 3 2 1
165 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
174 if [ -n "${PERSISTENCE_MEDIA}" ]
176 case "${PERSISTENCE_MEDIA}" in
178 whitelistdev="$(removable_dev)"
182 whitelistdev="$(removable_usb_dev)"
185 if [ -z "${whitelistdev}" ]
187 whitelistdev="ignore_all_devices"
191 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
193 overlays="${custom_overlay_label}"
196 local overlay_devices
198 if [ "${whitelistdev}" != "ignore_all_devices" ]
200 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
202 media="$(echo ${media} | tr ":" " ")"
205 ${custom_overlay_label}=*)
207 overlay_devices="${overlay_devices} ${device}"
212 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
214 # check if there are any nfs options
215 if echo ${NFS_COW} | grep -q ','
217 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
218 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
220 nfs_cow_opts="-o nolock"
224 if [ -n "${PERSISTENCE_READONLY}" ]
226 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
232 cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/")
235 panic "unable to determine mac address"
239 if [ -z "${cowdevice}" ]
243 cow_mountopt="rw,noatime,mode=755"
246 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
248 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
249 root_backing="/live/persistence/$(basename ${cowdevice})-root"
250 mkdir -p ${root_backing}
252 root_backing="/live/overlay"
255 if [ "${cow_fstype}" = "nfs" ]
258 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
259 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
260 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
262 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
263 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
266 rootfscount=$(echo ${rootfslist} |wc -w)
268 rootfs=${rootfslist%% }
270 if [ -n "${EXPOSED_ROOT}" ]
272 if [ ${rootfscount} -ne 1 ]
274 panic "only one RO file system supported with exposedroot: ${rootfslist}"
277 mount --bind ${rootfs} ${rootmnt} || \
278 panic "bind mount of ${rootfs} failed"
280 if [ -z "${SKIP_UNION_MOUNTS}" ]
282 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
290 for dir in ${cow_dirs}; do
291 unionmountpoint="${rootmnt}${dir}"
292 mkdir -p ${unionmountpoint}
293 cow_dir="/live/overlay${dir}"
294 rootfs_dir="${rootfs}${dir}"
296 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
298 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
300 do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
301 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
304 # Remove persistence depending on boot parameter
307 # Correct the permissions of /:
308 chmod 0755 "${rootmnt}"
310 # Correct the permission of /tmp:
311 if [ -d "${rootmnt}/tmp" ]
313 chmod 1777 "${rootmnt}"/tmp
317 for d in ${rootfslist}
319 live_rootfs="/live/rootfs/${d##*/}"
320 live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
321 mkdir -p "${live_rootfs}"
324 # do nothing # mount -o bind "${d}" "${live_rootfs}"
327 mount -o move "${d}" "${live_rootfs}"
332 # Adding custom persistence
333 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
336 custom_mounts="/tmp/custom_mounts.list"
337 rm -f ${custom_mounts}
339 # Gather information about custom mounts from devies detected as overlays
340 get_custom_mounts ${custom_mounts} ${overlay_devices}
342 [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
344 # Now we do the actual mounting (and symlinking)
347 used_overlays=$(activate_custom_mounts ${custom_mounts})
348 rm -f ${custom_mounts}
350 # Close unused overlays (e.g. due to missing $persistence_list)
351 for overlay in ${overlay_devices}
353 if echo ${used_overlays} | grep -qve "^\(.* \)\?${overlay}\( .*\)\?$"
355 close_persistence_media ${overlay}
360 # ensure that a potentially stray tmpfs gets removed
361 # otherways, initramfs-tools is unable to remove /live
363 umount /live/overlay > /dev/null 2>&1 || true