4 # Provides: live-initramfs
5 # Required-Start: $syslog
7 # Should-Start: $local_fs
8 # Should-Stop: halt reboot
9 # X-Stop-After: umountroot
12 # Short-Description: live-initramfs init script
13 # Description: Resyncs snapshots, evantually caches files in order to
14 # let remove the media.
17 # Authors: Tollef Fog Heen <tfheen@canonical.com>
18 # Marco Amadori <marco.amadori@gmail.com>
20 PATH=/usr/sbin:/usr/bin:/sbin:/bin
22 SCRIPTNAME=/etc/init.d/${NAME}
23 DO_SNAPSHOT=/sbin/live-snapshot
25 # Exit if system was not booted by live-initramfs
26 grep -qs boot=live /proc/cmdline || exit 0
28 # Exit if the system was booted from an ISO image rather than a physical CD
29 grep -qs find_iso= /proc/cmdline && exit 0
31 # Read configuration variable file if it is present
32 [ -r /etc/live.conf ] && . /etc/live.conf
34 # Load the VERBOSE setting and other rcS variables
35 [ -f /etc/default/rcS ] && . /etc/default/rcS
37 # Define LSB log_* functions.
38 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
39 . /lib/lsb/init-functions
41 # Try to cache everything we're likely to need after ejecting. This
42 # is fragile and simple-minded, but our options are limited.
49 find "${path}" -type f | xargs cat > /dev/null 2>&1
54 if file "${path}" | grep -q 'dynamically linked'
56 for lib in $(ldd "${path}" | awk '{ print $3 }')
63 cat "${path}" >/dev/null 2>&1
69 # search in /proc/mounts for the device that is mounted at /live/image
70 while read DEVICE MOUNT REST
72 if [ "${MOUNT}" = "/live/image" ]
80 device_is_USB_flash_drive()
82 # remove leading "/dev/" and all trailing numbers from input
83 DEVICE=$(expr substr ${1} 6 3)
85 # check that device starts with "sd"
86 [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
88 # check that the device is an USB device
89 if readlink /sys/block/${DEVICE} | grep -q usb ||
90 readlink /sys/block/${DEVICE}/device | grep -q usb # linux < 2.6.29
100 if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline
102 if [ ! -z "${ROOTSNAP}" ]
104 ${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
107 if [ ! -z "${HOMESNAP}" ]
109 ${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
114 if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline || grep -qsi root=/dev/cifs /proc/cmdline
119 # Don't prompt to eject the SD card on Babbage board, where we reuse it
120 # as a quasi-boot-floppy. Technically this uses a bit of ubiquity
121 # (archdetect), but since this is mostly only relevant for
122 # installations, who cares ...
123 if type archdetect >/dev/null 2>&1
125 subarch="$(archdetect)"
135 if grep -qs noprompt /proc/cmdline
140 for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty)
145 for x in $(cat /proc/cmdline)
154 if [ -z ${QUICKREBOOT} ]
157 BOOT_DEVICE="$(get_boot_device)"
159 if device_is_USB_flash_drive ${BOOT_DEVICE}
161 # do NOT eject USB flash drives!
162 # otherwise rebooting with most USB flash drives
163 # failes because they actually remember the
164 # "ejected" state even after reboot
165 MESSAGE="Please remove the USB flash drive"
167 # ejecting is a very good idea here
168 MESSAGE="Please remove the disc, close the the tray (if any)"
170 if [ -x /usr/bin/eject ]
172 eject -p -m /live/image >/dev/null 2>&1
177 [ "$prompt" ] || return 0
179 if [ -x /bin/plymouth ] && plymouth --ping
181 plymouth message --text="${MESSAGE} and press ENTER to continue:"
182 plymouth watch-keystroke > /dev/null
184 stty sane < /dev/console
186 printf "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
188 if [ -x /sbin/usplash_write ]
190 /sbin/usplash_write "TIMEOUT 86400"
191 /sbin/usplash_write "TEXT-URGENT ${MESSAGE}"
192 /sbin/usplash_write "TEXT-URGENT and press ENTER to continue"
195 read x < /dev/console
201 restart|reload|force-reload|status)
202 [ "${VERBOSE}" != no ] && log_end_msg 0
206 log_begin_msg "${NAME} is resyncing snapshots and caching reboot files..."
211 [ "${VERBOSE}" != no ] && log_end_msg 0
215 [ "${VERBOSE}" != no ] && log_end_msg 1
219 mount -o remount,ro /live/cow
223 log_success_msg "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload}" >&2