3 # Purpose: copy compressed GRML image to RAM
4 # Authors: (c) Michael Schierl <schierlm-public@gmx.de>, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
11 . /etc/grml/lsb-functions
12 . /etc/grml/script-functions
15 check4progs rsync gawk || exit 2
18 eerror "Not running grml in live-cd mode. Nothing to be done, exiting." ; eend 1
22 if [ -z "$CMDLINE" ]; then
23 # if CMDLINE was set from the outside, we're debugging.
24 # otherwise, take CMDLINE from Kernel and config files.
25 CMDLINE="$(cat /proc/cmdline)"
26 [ -d /cdrom/bootparams/ ] && CMDLINE="$CMDLINE $(cat /cdrom/bootparams/* | tr '\n' ' ')"
27 [ -d /live/image/bootparams/ ] && CMDLINE="$CMDLINE $(cat /live/image/bootparams/* | tr '\n' ' ')"
37 result="${line##*[$ws]$1=}"
38 result="${result%%[$ws]*}"
46 MEDIA_PATH="$(getbootparam live-media-path)"
47 MEDIA_PATH="${MEDIA_PATH:-.}"
49 IMAGE=$(find /live/image/${MEDIA_PATH}/ -name *.squashfs 2>/dev/null | head -1)
50 if ! [ -r "$IMAGE" ] ; then
51 if [ -r /cdrom/GRML/GRML ] ; then
52 IMAGE='/cdrom/GRML/GRML'
54 eerror "Can not access grml squashfs file."
55 eerror "Looks like you did run grml2ram already?" ; eend 1
60 GRMLSIZE="$(du $IMAGE | awk '{print $1}')"
61 RAM=$(/usr/bin/gawk '/MemFree/{print $2}' /proc/meminfo)
63 case "$*" in -f|--force)
64 ewarn "Forcing copy process for grml-image (${GRMLSIZE}kB) as requested via force option." ; eend 0
67 if test $RAM -lt $GRMLSIZE ; then
68 eerror "Sorry, not enough free RAM (${RAM}kB) available for grml-image (${GRMLSIZE}kB)." ; eend 1
74 einfo "Copying $IMAGE to RAM, this might take a while."
75 rsync -a --progress $IMAGE /tmp/GRML
76 LANGUAGE=C LANG=C LC_ALL=C perl << EOF
77 open LOOP, '</dev/loop0' or die $!;
78 open DEST, '</tmp/GRML' or die $!;
79 ioctl(LOOP, 0x4C06, fileno(DEST)) or die $!;
85 GRMLDEV=$(awk '{if ($2 ~ /^\/live\/image$/ ) print $1}' /etc/mtab)
86 if [ -z "$GRMLDEV" ]; then
87 GRMLDEV=$(awk '{if ($2 ~ /^\/cdrom$/ ) print $1}' /etc/mtab)
89 [ -n "$GRMLDEV" ] || GRMLDEV='/dev/cdrom'
91 einfo "Unmounting cdrom"
92 [ -d /live/image ] && umount /live/image || umount /cdrom
94 einfo "Now you can eject your grml-cd (e.g. run 'eject $GRMLDEV')." ; eend 0
96 ## END OF FILE #################################################################