4 # Provides: live-initramfs
5 # Required-Start: $syslog
6 # Required-Stop: $syslog
7 # Should-Start: $local_fs
8 # Should-Stop: $local_fs
9 # Default-Start: 1 2 3 4 5
11 # Short-Description: live-initramfs init script
12 # Description: Resyncs snapshots, evantually caches files in order to
13 # let remove the media.
16 # Authors: Tollef Fog Heen <tfheen@canonical.com>
17 # Marco Amadori <marco.amadori@gmail.com>
19 PATH=/usr/sbin:/usr/bin:/sbin:/bin
21 SCRIPTNAME=/etc/init.d/${NAME}
22 DO_SNAPSHOT=/sbin/live-snapshot
24 # Exit if system was not booted by live-initramfs
25 grep -qs boot=live /proc/cmdline || exit 0
27 # Exit if the system was booted from an ISO image rather than a physical CD
28 grep -qs find_iso= /proc/cmdline && exit 0
30 # Read configuration variable file if it is present
31 [ -r /etc/live.conf ] && . /etc/live.conf
33 # Load the VERBOSE setting and other rcS variables
34 [ -f /etc/default/rcS ] && . /etc/default/rcS
36 # Define LSB log_* functions.
37 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
38 . /lib/lsb/init-functions
40 # Try to cache everything we're likely to need after ejecting. This
41 # is fragile and simple-minded, but our options are limited.
45 if [ -d "${path}" ]; then
46 find "${path}" -type f | xargs cat > /dev/null 2>&1
47 elif [ -f "${path}" ]; then
48 if [ -x "${path}" ]; then
49 if file "${path}" | grep -q 'dynamically linked'; then
50 for lib in $(ldd "${path}" | awk '{ print $3 }'); do
55 cat "${path}" >/dev/null 2>&1
60 # search in /proc/mounts for the device that is mounted at /live/image
61 while read DEVICE MOUNT REST; do
62 if [ "${MOUNT}" == "/live/image" ]; then
69 device_is_USB_flash_drive()
71 # remove leading "/dev/" and all trailing numbers from input
72 DEVICE=$(expr substr ${1} 6 3)
73 # check that device starts with "sd"
74 [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
75 # check that the device is an USB device
76 if readlink /sys/block/${DEVICE}/device | grep -q usb ; then
84 if [ ! -z "${ROOTSNAP}" ]; then
85 ${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
88 if [ ! -z "${HOMESNAP}" ]; then
89 ${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
93 if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline || grep -qsi root=/dev/cifs /proc/cmdline ; then
98 if grep -qs noprompt /proc/cmdline; then
102 for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty); do
106 for x in $(cat /proc/cmdline); do
114 if [ -z ${QUICKREBOOT} ]; then
116 if [ -x /usr/bin/eject ]
118 BOOT_DEVICE="$(get_boot_device)"
119 if device_is_USB_flash_drive ${BOOT_DEVICE}; then
120 # do NOT eject USB flash drives!
121 # otherwise rebooting with most USB flash drives failes because
122 # they actually remember the "ejected" state even after reboot
123 MESSAGE="Please remove the USB flash drive"
125 # ejecting is a very good idea here
126 eject -p -m /live/image >/dev/null 2>&1
129 MESSAGE="Please remove the ${MEDIUM}, close the ${MEDIUM} tray (if any)"
131 MESSAGE="${MESSAGE} and press ENTER:"
133 [ "$prompt" ] || return 0
136 stty sane < /dev/console
138 echo -n -e "\n\n${MESSAGE}" > /dev/console
139 if [ -x /sbin/usplash_write ]; then
140 /sbin/usplash_write "TIMEOUT 86400"
141 /sbin/usplash_write "TEXT-URGENT Please remove the disc, close the tray (if any)"
142 /sbin/usplash_write "TEXT-URGENT and press ENTER to continue"
145 read x < /dev/console
150 start|restart|reload|force-reload|status)
151 [ "${VERBOSE}" != no ] && log_end_msg 0
154 log_begin_msg "${NAME} is resyncing snapshots and caching reboot files..."
157 0|1) [ "${VERBOSE}" != no ] && log_end_msg 0 ;;
158 2) [ "${VERBOSE}" != no ] && log_end_msg 1 ;;
162 log_success_msg "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload}" >&2