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