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 # old linuxrc version:
23 [ -d /cdrom ] && export LIVECD_PATH=/cdrom
24 # initramfs layout until around December 2012:
25 [ -d /live/image ] && export LIVECD_PATH=/live/image
26 # initramfs layout since around December 2012:
27 [ -d /lib/live/mount/medium ] && export LIVECD_PATH=/lib/live/mount/medium
29 if [ -z "$CMDLINE" ]; then
30 # if CMDLINE was set from the outside, we're debugging.
31 # otherwise, take CMDLINE from Kernel and config files.
32 CMDLINE="$(cat /proc/cmdline)"
33 [ -d ${LIVECD_PATH}/bootparams/ ] && CMDLINE="$CMDLINE $(cat ${LIVECD_PATH}/bootparams/* | tr '\n' ' ')"
43 result="${line##*[$ws]$1=}"
44 result="${result%%[$ws]*}"
52 MEDIA_PATH="$(getbootparam live-media-path)"
53 MEDIA_PATH="${MEDIA_PATH:-.}"
55 IMAGE=$(find ${LIVECD_PATH}/${MEDIA_PATH}/ -name *.squashfs 2>/dev/null | head -1)
56 if ! [ -r "$IMAGE" ] ; then
57 if [ -r /cdrom/GRML/GRML ] ; then
58 IMAGE='/cdrom/GRML/GRML'
60 eerror "Can not access grml squashfs file."
61 eerror "Looks like you did run grml2ram already?" ; eend 1
66 GRMLSIZE="$(du $IMAGE | awk '{print $1}')"
67 RAM=$(/usr/bin/gawk '/MemFree/{print $2}' /proc/meminfo)
69 case "$*" in -f|--force)
70 ewarn "Forcing copy process for grml-image (${GRMLSIZE}kB) as requested via force option." ; eend 0
73 if test $RAM -lt $GRMLSIZE ; then
74 eerror "Sorry, not enough free RAM (${RAM}kB) available for grml-image (${GRMLSIZE}kB)." ; eend 1
80 einfo "Copying $IMAGE to RAM, this might take a while."
81 rsync -a --progress $IMAGE /tmp/GRML
82 LANGUAGE=C LANG=C LC_ALL=C perl << EOF
83 open LOOP, '</dev/loop0' or die $!;
84 open DEST, '</tmp/GRML' or die $!;
85 ioctl(LOOP, 0x4C06, fileno(DEST)) or die $!;
91 GRMLDEV=$(awk '{if ($2 ~ /^\/lib\/live\/mount\/medium$/ ) print $1}' /etc/mtab)
92 if [ -z "$GRMLDEV" ]; then
93 GRMLDEV=$(awk '{if ($2 ~ /^\/live\/image$/ ) print $1}' /etc/mtab)
95 if [ -z "$GRMLDEV" ]; then
96 GRMLDEV=$(awk '{if ($2 ~ /^\/cdrom$/ ) print $1}' /etc/mtab)
98 [ -n "$GRMLDEV" ] || GRMLDEV='/dev/cdrom'
100 einfo "Unmounting cdrom"
101 [ -d $LIVECD_PATH ] && umount $LIVECD_PATH || umount /cdrom
103 einfo "Now you can eject your grml-cd (e.g. run 'eject $GRMLDEV')." ; eend 0
105 ## END OF FILE #################################################################