summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2010-09-02 18:19:05 +0200
committerDaniel Baumann <daniel@debian.org>2011-03-09 17:53:27 +0100
commite446bb37f11327da83c6ce05f6c6e47d2822ff3a (patch)
treeebea2c40ea0d0bb92cc3554798614326b88d9431
parentcc8e921a9aee8e61805f40ddbc77b349e750e553 (diff)
downloadlive-boot-e446bb37f11327da83c6ce05f6c6e47d2822ff3a.tar.gz
live-boot-e446bb37f11327da83c6ce05f6c6e47d2822ff3a.zip
Adding live-toram script to copy the running live system to ram and eject the live media.
This script is an adaptation of grml2ram from Michael Schierl <schierlm-public@gmx.de> and Michael Prokop <mika@grml.org>. For squeeze+1, this script is included in live-tools but manually included too in live-boot 2.x for convenience reasons.
-rw-r--r--Makefile2
-rwxr-xr-xbin/live-toram120
2 files changed, 121 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index d38a949..966a6bd 100644
--- a/Makefile
+++ b/Makefile
@@ -43,7 +43,7 @@ build:
install:
# Installing executables
mkdir -p $(DESTDIR)/sbin
- cp bin/live-new-uuid bin/live-snapshot bin/live-swapfile $(DESTDIR)/sbin
+ cp bin/live-new-uuid bin/live-snapshot bin/live-swapfile bin/live-toram $(DESTDIR)/sbin
mkdir -p $(DESTDIR)/usr/share/live-boot
cp bin/live-preseed bin/live-reconfigure local/languagelist $(DESTDIR)/usr/share/live-boot
diff --git a/bin/live-toram b/bin/live-toram
new file mode 100755
index 0000000..b7740a2
--- /dev/null
+++ b/bin/live-toram
@@ -0,0 +1,120 @@
+#!/bin/sh
+
+set -e
+
+# Read cmdline
+for _PARAMETER in $(cat /proc/cmdline)
+do
+ case "${_PARAMETER}" in
+ module=*)
+ _MODULE="${_PARAMETER#module=}"
+ ;;
+ esac
+done
+
+# Assemble filesystems
+if [ -z "${_MODULE}" ]
+then
+ _FILESYSTEMS="/live/image/live/filesystem.squashfs"
+else
+ for _FILESYSTEM in _MODULE
+ do
+ _FILESYSTEMS="${_FILESYSTEMS} /live/image/live/${_FILESYSTEM}"
+ done
+fi
+
+# Exit if system is not debian live
+if [ ! -d /live/image ]
+then
+ echo "E: live-toram only works on Debian Live systems."
+
+ exit 1
+fi
+
+# Exit if filesystem not accessible
+for _FILESYSTEM in ${_FILESYSTEMS}
+do
+ if [ ! -r ${_FILESYSTEM} ]
+ then
+ echo "E: ${_FILESYSTEM}: No such file"
+ echo "I: live-toram already run?"
+
+ exit 1
+ fi
+done
+
+# Exit if user is unprivileged
+if [ "$(id -u)" -ne 0 ]
+then
+ echo "E: need root privileges"
+
+ exit 1
+fi
+
+# Exit if not enough free memory
+_SIZE=0
+
+for _FILESYSTEM in ${_FILESYSTEMS}
+do
+ _SIZE="$((${_SIZE} + $(du ${_FILESYSTEM} | awk '{ print $1 }')))"
+ _MEMORY="$(awk '/MemFree/ { print $2 }' /proc/meminfo)"
+done
+
+case ${@} in
+ -f|--force)
+ echo "W: Ignoring memory constrains as requested"
+ ;;
+
+ *)
+ if [ $_MEMORY -lt $_SIZE ]
+ then
+ echo "E: not enough free memory available."
+ echo "I: images need ${_SIZE}kB, free memory is ${_MEMORY}kB."
+
+ exit 1
+ fi
+ ;;
+esac
+
+# Copying image to memory
+echo "P: Copying images to memory."
+echo "P: This may take a while..."
+
+# FIXME: doesn't work with multiple filesystems
+for _FILESYSTEM in ${_FILESYSTEMS}
+do
+ if [ ! -x "$(which rsync 2>/dev/null)" ]
+ then
+ rsync -a --progress ${_FILESYSTEM} /tmp/live
+ else
+ cp -av ${_FILESYSTEM} /tmp/live
+ fi
+
+LANGUAGE=C LANG=C LC_ALL=C perl << EOF
+open LOOP, '</dev/loop0' or die $!;
+open DEST, '</tmp/live' or die $!;
+ioctl(LOOP, 0x4C06, fileno(DEST)) or die $!
+close LOOP;
+close DEST;
+EOF
+
+done
+
+# Unmounting live media
+_DEVICE="$(awk '/\/live\/image / { print $1 }' /proc/mounts)"
+
+if [ -d /live/image ]
+then
+ umount /live/image
+ rmdir --ignore-fail-on-non-empty /live/image || true
+fi
+
+# Ejecting live media if it is not an optical device
+if [ "$(expr substr ${_DEVICE} 1 2)" != "sd" ] && \
+ ! readlink /sys/block/$(expr substr ${_DEVICE} 6 3) | grep -q usb
+then
+ if [ ! -x "$(which rsync 2>/dev/null)" ]
+ then
+ eject -p -m ${_DEVICE} >/dev/null 2>&1
+ fi
+fi