Patch for 9990-toram-todisk.sh
Hi.
I have been using Debian Live for many years. Most of the time I load the image with the live system into the memory of computer using the "toram" option. Here I am posting a patch file /lib/live/boot/9990-toram-todisk.sh that slightly modifies the
behavior of "toram" as follows.
- When "toram" is selected, only the squashfs images that are listed in the filesystem.module file are loaded into the system memory, not the entire disk as it is now. (These files are then mounted as an overlay to /.)
- The size of the temporary filesystem (tmpfs) is set according to the total size of the squashfs images being loaded.
- The device file name of the temporary filesystem is changed from "/dev/shm" to "tmpfs", because the original choice is wrong (at least nowadays) and causes error messages when the system runs.
Regards
Vladimir Smelhaus
--
--- 9990-toram-todisk.sh 2023-01-31 00:00:00.000000000 +0100
+++ 9990-toram-todisk.sh.new 2023-11-18 19:20:49.510912055 +0100
@@ -10,13 +9,21 @@
if [ -z "${MODULETORAM}" ]
then
- size=$(fs_size "" ${copyfrom}/ "used")
+ if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/"filesystem.${MODULE}.module" ]
+ then
+ size=$(cd ${copyfrom}/${LIVE_MEDIA_PATH} ; ls -l $(cat filesystem.${MODULE}.module) | awk '{ sum += $5 } END { sum = sum / 1024 + 512 ; print sum }')
+ elif [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/"${MODULE}.module" ]
+ then
+ size=$(cd ${copyfrom}/${LIVE_MEDIA_PATH} ; ls -l $(cat ${MODULE}.module) | awk '{ sum += $5 } END { sum = sum / 1024 + 512 ; print sum }')
+ else
+ size=$(ls -l ${copyfrom}/${LIVE_MEDIA_PATH}/ | awk '{ sum += $5 } END { sum = sum / 1024 + 512 ; print sum }')
+ fi
else
MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
if [ -f "${MODULETORAMFILE}" ]
then
- size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
+ size=$(ls -l ${MODULETORAMFILE} | awk '{ sum += $5 } END { sum = sum / 1024 + 512 ; print sum }')
else
log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
return 1
@@ -30,7 +37,7 @@
mount_options="-o size=${size}k"
free_string="memory"
fstype="tmpfs"
- dev="/dev/shm"
+ dev="tmpfs"
else
# it should be a writable block device
if [ -b "${copytodev}" ]
@@ -81,19 +87,60 @@
cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
fi
else
+ image_directory="${copyfrom}/${LIVE_MEDIA_PATH}"
+ if [ -n "${MODULE}" ]
+ then
+ image_directory="${copyfrom}/${LIVE_MEDIA_PATH}"
+ image_string=""
+ # Read image names from ${MODULE}.module if it exists
+ if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
+ then
+ for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
+ do
+ image_string="${image_string} ${IMAGE}"
+ done
+ elif [ -e "${image_directory}/${MODULE}.module" ]
+ then
+ for IMAGE in $(cat ${image_directory}/${MODULE}.module)
+ do
+ image_string="${image_string} ${IMAGE}"
+ done
+ else
+ for IMAGE in $(ls ${image_directory}/ | grep -v "vmlinuz\|initrd\|\.packages" )
+ do
+ image_string="${image_string} ${IMAGE}"
+ done
+ fi
+ echo " * Copying modules to RAM" 1>/dev/console
+ mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
+ if [ -x /bin/rsync ]
+ then
+ for modulefile in ${image_string}
+ do
+ # echo " ..... ${modulefile}" 1>/dev/console
+ rsync --progress ${copyfrom}/${LIVE_MEDIA_PATH}/${modulefile} ${copyto}/${LIVE_MEDIA_PATH} 1>/dev/console
+ done
+ else
+ for modulefile in ${image_string}
+ do
+ # echo " ..... ${modulefile}" 1>/dev/console
+ cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/${modulefile} ${copyto}/${LIVE_MEDIA_PATH}/
+ done
+ fi
+ else
if [ -x /bin/rsync ]
then
- echo " * Copying whole medium to RAM" 1>/dev/console
- rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
+ echo " * Copying whole live_media_path to RAM" 1>/dev/console
+ rsync --progress ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} 1>/dev/console # "cp -a" from busybox also copies hidden files
else
- cp -a ${copyfrom}/* ${copyto}/
+ cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}/
if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
then
cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
fi
fi
fi
-
+ fi
umount ${copyfrom}
mount -r -o move ${copyto} ${copyfrom}
fi
Reply to: