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.
48 find "${path}" -type f | xargs cat > /dev/null 2>&1
53 if file "${path}" | grep -q 'dynamically linked'
55 for lib in $(ldd "${path}" | awk '{ print $3 }')
62 cat "${path}" >/dev/null 2>&1
68 # search in /proc/mounts for the device that is mounted at /live/image
69 while read DEVICE MOUNT REST
71 if [ "${MOUNT}" = "/live/image" ]
79 device_is_USB_flash_drive()
81 # remove leading "/dev/" and all trailing numbers from input
82 DEVICE=$(expr substr ${1} 6 3)
84 # check that device starts with "sd"
85 [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
87 # check that the device is an USB device
88 if readlink /sys/block/${DEVICE} | grep -q usb ||
89 readlink /sys/block/${DEVICE}/device | grep -q usb # linux < 2.6.29
99 if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline
101 if [ ! -z "${ROOTSNAP}" ]
103 ${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
106 if [ ! -z "${HOMESNAP}" ]
108 ${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
113 if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline || grep -qsi root=/dev/cifs /proc/cmdline
119 if grep -qs noprompt /proc/cmdline
124 for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty)
129 for x in $(cat /proc/cmdline)
138 if [ -z ${QUICKREBOOT} ]
140 # in order to deal with the aufs unmount problem, we do a sync here.
146 BOOT_DEVICE="$(get_boot_device)"
148 if device_is_USB_flash_drive ${BOOT_DEVICE}
150 # do NOT eject USB flash drives!
151 # otherwise rebooting with most USB flash drives
152 # failes because they actually remember the
153 # "ejected" state even after reboot
154 MESSAGE="Please remove the USB flash drive"
156 # ejecting is a very good idea here
157 MESSAGE="Please remove the disc, close the the tray (if any)"
159 if [ -x /usr/bin/eject ]
161 eject -p -m /live/image >/dev/null 2>&1
166 [ "$prompt" ] || return 0
168 stty sane < /dev/console
170 printf "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
172 if [ -x /sbin/usplash_write ]
174 /sbin/usplash_write "TIMEOUT 86400"
175 /sbin/usplash_write "TEXT-URGENT ${MESSAGE}"
176 /sbin/usplash_write "TEXT-URGENT and press ENTER to continue"
179 read x < /dev/console
184 start|restart|reload|force-reload|status)
185 [ "${VERBOSE}" != no ] && log_end_msg 0
189 log_begin_msg "${NAME} is resyncing snapshots and caching reboot files..."
194 [ "${VERBOSE}" != no ] && log_end_msg 0
198 [ "${VERBOSE}" != no ] && log_end_msg 1
204 log_success_msg "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload}" >&2