5 if [ -e /scripts
/functions
]
7 # initramfs-tools specific (FIXME)
11 for _SCRIPT
in /lib
/live
/boot
/*
13 if [ -e "${_SCRIPT}" ]
19 export PATH
="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
21 echo "/root/lib" >> /etc
/ld.so.conf
22 echo "/root/usr/lib" >> /etc
/ld.so.conf
24 mountpoint
="/live/image"
25 alt_mountpoint
="/media"
26 LIVE_MEDIA_PATH
="live"
30 mkdir
-p "${mountpoint}"
33 # Create /etc/mtab for debug purpose and future syncs
44 if [ ! -x "/bin/fstype" ]
46 # klibc not in path -> not in initramfs
47 export PATH
="${PATH}:/usr/lib/klibc/bin"
50 # handle upgrade path from old udev (using udevinfo) to
51 # recent versions of udev (using udevadm info)
52 if [ -x /sbin
/udevadm
]
54 udevinfo
='/sbin/udevadm info'
59 old_root_overlay_label
="live-rw"
60 old_home_overlay_label
="home-rw"
61 custom_overlay_label
="custom-ov"
62 root_snapshot_label
="live-sn"
63 old_root_snapshot_label
="live-sn"
64 home_snapshot_label
="home-sn"
65 persistence_list
="live-persistence.conf"
67 if [ ! -f /live.vars
]
76 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
78 for FILESYSTEM
in squashfs ext2 ext3 ext4 xfs dir jffs2
80 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
92 if [ "${IGNORE_UUID}" ] ||
[ ! -e /conf
/uuid.conf
]
98 uuid
="$(cat /conf/uuid.conf)"
100 for try_uuid_file
in "${path}/.disk/live-uuid"*
102 [ -e "${try_uuid_file}" ] ||
continue
104 try_uuid
="$(cat "${try_uuid_file}")"
106 if [ "${uuid}" = "${try_uuid}" ]
115 get_backing_device
()
118 *.squashfs|
*.ext2|
*.ext3|
*.ext4|
*.jffs2
)
119 echo $
(setup_loop
"${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
127 panic
"Unrecognized live filesystem: ${1}"
132 match_files_in_dir
()
134 # Does any files match pattern ${1} ?
137 if [ "$(echo ${pattern})" != "${pattern}" ]
145 mount_images_in_directory
()
152 if match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
153 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
154 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
155 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
156 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
157 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.dir"
159 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
160 setup_unionfs
"${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
162 panic
"No supported filesystem images found at /${LIVE_MEDIA_PATH}."
168 sysfs_path
="${1#/sys}"
170 if [ -e /lib
/udev
/path_id
]
173 PATH_ID
="/lib/udev/path_id"
175 # wheezy/sid (udev >= 174)
176 PATH_ID
="/sbin/udevadm test-builtin path_id"
179 if ${PATH_ID} "${sysfs_path}" |
egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)"
182 elif echo "${sysfs_path}" |
grep -q '^/block/vd[a-z]$'
185 elif echo ${sysfs_path} |
grep -q "^/block/dm-"
188 elif echo ${sysfs_path} |
grep -q "^/block/mtdblock"
200 skip_uuid_check
="${3}"
202 # support for fromiso=.../isofrom=....
205 ISO_DEVICE
=$
(dirname $FROMISO)
206 if ! [ -b $ISO_DEVICE ]
208 # to support unusual device names like /dev/cciss/c0d0p1
209 # as well we have to identify the block device name, let's
210 # do that for up to 15 levels
212 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
214 ISO_DEVICE
=$
(dirname ${ISO_DEVICE})
215 [ -b "$ISO_DEVICE" ] && break
220 if [ "$ISO_DEVICE" = "/" ]
222 echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
224 fs_type
=$
(get_fstype
"${ISO_DEVICE}")
225 if is_supported_fs
${fs_type}
228 mount
-t $fs_type "$ISO_DEVICE" /live
/fromiso
229 ISO_NAME
="$(echo $FROMISO | sed "s|
$ISO_DEVICE||
")"
230 loopdevname
=$
(setup_loop
"/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
231 devname
="${loopdevname}"
233 echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
238 if [ -z "${devname}" ]
240 devname
=$
(sys2dev
"${sysdev}")
243 if [ -d "${devname}" ]
245 mount
-o bind "${devname}" $mountpoint ||
continue
247 if is_live_path
$mountpoint
257 for device
in ${devname}
262 if [ -x /scripts
/local-top
/lvm2
]
264 ROOT
="$device" resume
="" /scripts
/local-top
/lvm2
269 # Adding raid support
270 if [ -x /scripts
/local-top
/mdadm
]
272 cp /conf
/conf.d
/md
/conf
/conf.d
/md.orig
273 echo "MD_DEVS=$device " >> /conf
/conf.d
/md
274 /scripts
/local-top
/mdadm
275 mv /conf
/conf.d
/md.orig
/conf
/conf.d
/md
282 [ -n "$device" ] && devname
="$device"
284 [ -e "$devname" ] ||
continue
286 if [ -n "${LIVE_MEDIA_OFFSET}" ]
288 loopdevname
=$
(setup_loop
"${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
289 devname
="${loopdevname}"
292 fstype
=$
(get_fstype
"${devname}")
294 if is_supported_fs
${fstype}
296 devuid
=$
(blkid
-o value
-s UUID
"$devname")
297 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
298 mount
-t ${fstype} -o ro,noatime "${devname}" ${mountpoint} ||
continue
299 [ -n "$devuid" ] && echo "$devuid" >> $tried
301 if [ -n "${FINDISO}" ]
303 if [ -f ${mountpoint}/${FINDISO} ]
306 mkdir
-p /live
/findiso
307 mount
-t ${fstype} -o ro
,noatime
"${devname}" /live
/findiso
308 loopdevname
=$
(setup_loop
"/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
309 devname
="${loopdevname}"
310 mount
-t iso9660
-o ro
,noatime
"${devname}" ${mountpoint}
316 if is_live_path
${mountpoint} && \
317 ([ "${skip_uuid_check}" ] || matches_uuid
${mountpoint})
322 umount
${mountpoint} 2>/dev
/null
326 if [ -n "${LIVE_MEDIA_OFFSET}" ]
328 losetup
-d "${loopdevname}"
338 # don't start autodetection before timeout has expired
339 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
341 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
347 # first look at the one specified in the command line
348 case "${LIVE_MEDIA}" in
350 for sysblock
in $
(removable_usb_dev
"sys")
352 for dev
in $
(subdevices
"${sysblock}")
354 if check_dev
"${dev}"
364 for sysblock
in $
(removable_dev
"sys")
366 for dev
in $
(subdevices
"${sysblock}")
368 if check_dev
"${dev}"
378 if [ ! -z "${LIVE_MEDIA}" ]
380 if check_dev
"null" "${LIVE_MEDIA}" "skip_uuid_check"
388 # or do the scan of block devices
389 # prefer removable devices over non-removable devices, so scan them first
390 devices_to_scan
="$(removable_dev 'sys') $(non_removable_dev 'sys')"
392 for sysblock
in $devices_to_scan
394 devname
=$
(sys2dev
"${sysblock}")
395 [ -e "$devname" ] ||
continue
396 fstype
=$
(get_fstype
"${devname}")
398 if /lib
/udev
/cdrom_id
${devname} > /dev
/null
400 if check_dev
"null" "${devname}"
404 elif is_nice_device
"${sysblock}"
406 for dev
in $
(subdevices
"${sysblock}")
408 if check_dev
"${dev}"
413 elif [ "${fstype}" = "squashfs" -o \
414 "${fstype}" = "btrfs" -o \
415 "${fstype}" = "ext2" -o \
416 "${fstype}" = "ext3" -o \
417 "${fstype}" = "ext4" -o \
418 "${fstype}" = "jffs2" ]
420 # This is an ugly hack situation, the block device has
421 # an image directly on it. It's hopefully
422 # live-boot, so take it and run with it.
423 ln -s "${devname}" "${devname}.${fstype}"
424 echo "${devname}.${fstype}"
434 if [ -x /scripts
/local-top
/cryptroot
]; then
435 /scripts
/local-top
/cryptroot
442 tail -f boot.log
>&7 &
449 case "${LIVE_READ_ONLY}" in
457 # Needed here too because some things (*cough* udev *cough*)
458 # changes the timeout
460 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
464 livefs_root
="${mountpoint}"
466 panic
"Unable to find a live file system on the network"
469 if [ -n "${ISCSI_PORTAL}" ]
471 do_iscsi
&& livefs_root
="${mountpoint}"
472 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
474 # Do a local boot from hd
477 if [ -x /usr
/bin
/memdiskfind
]
479 MEMDISK
=$
(/usr
/bin
/memdiskfind
)
483 # We found a memdisk, set up phram
484 modprobe phram phram
=memdisk
,${MEMDISK}
486 # Load mtdblock, the memdisk will be /dev/mtdblock0
491 # Scan local devices for the image
493 while [ "$i" -lt 60 ]
495 livefs_root
=$
(find_livefs
${i})
497 if [ -n "${livefs_root}" ]
508 if [ -z "${livefs_root}" ]
510 panic
"Unable to find a medium containing a live file system"
513 case "${LIVE_VERIFY_CHECKSUMS}" in
515 Verify_checksums
"${livefs_root}"
524 live_dest
="${TODISK}"
527 if [ "${live_dest}" ]
529 log_begin_msg
"Copying live media to ${live_dest}"
530 copy_live_to
"${livefs_root}" "${live_dest}"
534 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
535 # because the mountpoint is left behind in /proc/mounts, so let's get
536 # rid of it when running from RAM
537 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
539 losetup
-d /dev
/loop0
541 if is_mountpoint
/live
/fromiso
544 rmdir --ignore-fail-on-non-empty /live
/fromiso \
545 >/dev
/null
2>&1 || true
549 if [ -n "${MODULETORAMFILE}" ] ||
[ -n "${PLAIN_ROOT}" ]
551 setup_unionfs
"${livefs_root}" "${rootmnt}"
554 mac
="$(echo ${mac} | sed 's/-//g')"
555 mount_images_in_directory
"${livefs_root}" "${rootmnt}" "${mac}"
559 if [ -n "${ROOT_PID}" ] ; then
560 echo "${ROOT_PID}" > "${rootmnt}"/live
/root.pid
565 # unionfs-fuse needs /dev to be bind-mounted for the duration of
566 # live-bottom; udev's init script will take care of things after that
567 if [ "${UNIONTYPE}" = unionfs-fuse
]
569 mount
-n -o bind /dev
"${rootmnt}/dev"
572 # Move to the new root filesystem so that programs there can get at it.
573 if [ ! -d /root
/live
/image
]
575 mkdir
-p /root
/live
/image
576 mount
--move /live
/image
/root
/live
/image
579 # aufs2 in kernel versions around 2.6.33 has a regression:
580 # directories can't be accessed when read for the first the time,
581 # causing a failure for example when accessing /var/lib/fai
582 # when booting FAI, this simple workaround solves it
583 ls /root
/* >/dev
/null
2>&1
585 # Move findiso directory to the new root filesystem so that programs there can get at it.
586 if [ -d /live
/findiso
] && [ ! -d /root
/live
/findiso
]
588 mkdir
-p /root
/live
/findiso
589 mount
-n --move /live
/findiso
/root
/live
/findiso
592 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
593 # because the mountpoint is left behind in /proc/mounts, so let's get
594 # rid of it when running from RAM
595 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
597 losetup
-d /dev
/loop0
599 if is_mountpoint
/root
/live
/findiso
601 umount
/root
/live
/findiso
602 rmdir --ignore-fail-on-non-empty /root
/live
/findiso \
603 >/dev
/null
2>&1 || true
607 # copy snapshot configuration if exists
608 if [ -f snapshot.conf
]
610 log_begin_msg
"Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
611 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
613 mkdir
-p "${rootmnt}/etc/live/boot.d"
615 cp snapshot.conf
"${rootmnt}/etc/live/boot.d/"
619 if [ -f /etc
/resolv.conf
] && [ ! -s ${rootmnt}/etc
/resolv.conf
]
621 log_begin_msg
"Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
622 cp -v /etc
/resolv.conf
${rootmnt}/etc
/resolv.conf
626 maybe_break live-bottom
627 log_begin_msg
"Running /scripts/live-bottom\n"
629 run_scripts
/scripts
/live-bottom
632 if [ "${UNIONFS}" = unionfs-fuse
]
634 umount
"${rootmnt}/dev"
640 [ -w "${rootmnt}/var/log/" ] && mkdir
-p /var
/log
/live
&& cp boot.log
"${rootmnt}/var/log/live" 2>/dev
/null