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 # shellcheck disable=SC1091
12 . /etc/grml/lsb-functions
13 # shellcheck disable=SC1091
14 . /etc/grml/script-functions
17 check4progs rsync gawk || exit 2
20 eerror "Not running grml in live-cd mode. Nothing to be done, exiting." ; eend 1
24 # initramfs layout since December 2012, backwards compatibility:
25 [ -d /lib/live/mount/medium ] && export LIVECD_PATH='/lib/live/mount/medium'
26 # initramfs layout since December 2018:
27 [ -d /run/live/medium ] && export LIVECD_PATH='/run/live/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 if [ -d $LIVECD_PATH ] ;
108 einfo "Now you can eject your grml-cd (e.g. run 'eject $GRMLDEV')." ; eend 0
110 ## END OF FILE #################################################################