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)
68 LOOPDEV=$(/sbin/losetup -j "${IMAGE}" -n -O NAME)
70 case "$*" in -f|--force)
71 ewarn "Forcing copy process for grml-image (${GRMLSIZE}kB) as requested via force option." ; eend 0
74 if test "$RAM" -lt "$GRMLSIZE" ; then
75 eerror "Sorry, not enough free RAM (${RAM}kB) available for grml-image (${GRMLSIZE}kB)." ; eend 1
81 einfo "Copying $IMAGE to RAM, this might take a while."
82 rsync -a --progress $IMAGE /tmp/GRML
83 LANGUAGE=C LANG=C LC_ALL=C perl << EOF
84 open LOOP, '<${LOOPDEV}' or die $!;
85 open DEST, '</tmp/GRML' or die $!;
86 ioctl(LOOP, 0x4C06, fileno(DEST)) or die $!;
92 GRMLDEV=$(awk '{if ($2 ~ /^\/lib\/live\/mount\/medium$/ ) print $1}' /etc/mtab)
93 if [ -z "$GRMLDEV" ]; then
94 GRMLDEV=$(awk '{if ($2 ~ /^\/live\/image$/ ) print $1}' /etc/mtab)
96 if [ -z "$GRMLDEV" ]; then
97 GRMLDEV=$(awk '{if ($2 ~ /^\/cdrom$/ ) print $1}' /etc/mtab)
99 [ -n "$GRMLDEV" ] || GRMLDEV='/dev/cdrom'
101 einfo "Unmounting cdrom"
102 if [ -d $LIVECD_PATH ] ;
109 einfo "Now you can eject your grml-cd (e.g. run 'eject $GRMLDEV')." ; eend 0
111 ## END OF FILE #################################################################