3 # Exit if system was not booted by live-boot
4 grep -qs boot=live /proc/cmdline || exit 0
6 DO_SNAPSHOT=/sbin/live-snapshot
7 SNAPSHOT_CONF="/etc/live/boot.d/snapshot.conf"
9 # Read snapshot configuration variables
10 [ -r ${SNAPSHOT_CONF} ] && . ${SNAPSHOT_CONF}
12 # Define LSB log_* functions.
13 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
14 . /lib/lsb/init-functions
16 # Try to cache everything we're likely to need after ejecting. This
17 # is fragile and simple-minded, but our options are limited.
24 find "${path}" -type f | xargs cat > /dev/null 2>&1
27 if file -L "${path}" | grep -q 'dynamically linked'
29 # ldd output can be of three forms:
30 # 1. linux-vdso.so.1 => (0x00007fffe3fb4000)
31 # This is a virtual, kernel shared library and we want to skip it
32 # 2. libc.so.6 => /lib/libc.so.6 (0x00007f5e9dc0c000)
33 # We want to cache the third word.
34 # 3. /lib64/ld-linux-x86-64.so.2 (0x00007f5e9df8b000)
35 # We want to cache the first word.
36 ldd "${path}" | while read line
38 if echo "$line" | grep -qs ' => '
41 elif echo "$line" | grep -qs ' => '
43 lib=$(echo "${line}" | awk '{ print $3 }')
45 lib=$(echo "${line}" | awk '{ print $1 }')
51 cat "${path}" >/dev/null 2>&1
57 # search in /proc/mounts for the device that is mounted at /live/image
58 while read DEVICE MOUNT REST
60 if [ "${MOUNT}" = "/live/image" ]
68 device_is_USB_flash_drive()
70 # remove leading "/dev/" and all trailing numbers from input
71 DEVICE=$(expr substr ${1} 6 3)
73 # check that device starts with "sd"
74 [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
76 # check that the device is an USB device
77 if readlink /sys/block/${DEVICE} | grep -q usb
85 log_begin_msg "live-boot: resyncing snapshots and caching reboot files..."
87 if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline
89 # ROOTSNAP and HOMESNAP are defined in ${SNAPSHOT_CONF} file
90 if [ ! -z "${ROOTSNAP}" ]
92 ${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
95 if [ ! -z "${HOMESNAP}" ]
97 ${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
102 if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline || grep -qsi root=/dev/cifs /proc/cmdline
108 if grep -qs toram /proc/cmdline
113 # Don't prompt to eject the SD card on Babbage board, where we reuse it
114 # as a quasi-boot-floppy. Technically this uses a bit of ubiquity
115 # (archdetect), but since this is mostly only relevant for
116 # installations, who cares ...
117 if type archdetect >/dev/null 2>&1
119 subarch="$(archdetect)"
129 if [ "${NOPROMPT}" = "Yes" ]
134 for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty) /bin/plymouth
139 for x in $(cat /proc/cmdline)
148 mount -o remount,ro /live/cow
150 if [ -z ${QUICKREBOOT} ]
152 # Exit if the system was booted from an ISO image rather than a physical CD
153 grep -qs find_iso= /proc/cmdline && return 0
155 BOOT_DEVICE="$(get_boot_device)"
157 if device_is_USB_flash_drive ${BOOT_DEVICE}
159 # do NOT eject USB flash drives!
160 # otherwise rebooting with most USB flash drives
161 # failes because they actually remember the
162 # "ejected" state even after reboot
163 MESSAGE="Please remove the USB flash drive"
165 if [ "${NOPROMPT}" = "usb" ]
171 # ejecting is a very good idea here
172 MESSAGE="Please remove the disc, close the tray (if any)"
174 if [ -x /usr/bin/eject ]
176 eject -p -m /live/image >/dev/null 2>&1
179 if [ "${NOPROMPT}" = "cd" ]
185 [ "$prompt" ] || return 0
187 if [ -x /bin/plymouth ] && plymouth --ping
189 plymouth message --text="${MESSAGE} and press ENTER to continue:"
190 plymouth watch-keystroke > /dev/null
192 stty sane < /dev/console
194 printf "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
196 read x < /dev/console