[Patch] Support multiple modules for toram parameter
Now the toram option in live-boot only accepts two modes,
1. "toram", then the whole files on the live media (CD, USB flash drive)
will be copied to RAM
2. "toram=FILE", then the file "FILE" on the live media (CD, USB flash
drive) in the /live/ directory will be copied to RAM.
However, as USB flash drive becomes larger nowadays, it's better to have
another feature for toram so that only part of the files on the USB
flash drive will be copied.
Attached please find the patch for live-boot-20160511 to support
multiple modules for toram parameter. For example, if
toram=live,syslinux
is assigned, then only the the directories "live" and "syslinux" on the
live media will be copied to RAM.
My 2 cents.
Steven
--
Steven Shiau <steven _at_ stevenshiau org>
Public Key Server PGP Key ID: 4096R/47CF935C
Fingerprint: 0240 1FEB 695D 7112 62F0 8796 11C1 12DA 47CF 935C
--- 9990-toram-todisk.sh.orig 2016-05-11 21:44:15.000000000 +0800
+++ 9990-toram-todisk.sh.new 2016-06-17 10:19:18.626582974 +0800
@@ -8,26 +8,40 @@
copytodev="${2}"
copyto="${copyfrom}_swap"
- if [ -z "${MODULETORAM}" ]
- then
- size=$(fs_size "" ${copyfrom}/ "used")
- else
- MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
-
- if [ -f "${MODULETORAMFILE}" ]
+ total_size="0"
+ # Only support one module for MODULETORAMFILE, but multiple modules for MODULETORAMDIR because if it's only one file, it's the root file system.
+ MODULETORAMDIR=""
+ for imtr in ${MODULETORAM//,/ }; do
+ if [ -z "${imtr}" ]
+ then
+ size=$(fs_size "" ${copyfrom}/ "used")
+ total_size="$( expr $total_size + $size )"
+ elif [ -d "${copyfrom}/${imtr}" ]
then
- size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
+ # Directory to be copied
+ MDIR="${copyfrom}/${imtr}"
+ size=$( expr $(du -sk ${MDIR} | awk '{print $1}') + 5000 )
+ total_size="$( expr $total_size + $size )"
+ MODULETORAMDIR="$MODULETORAMDIR $MDIR"
else
- log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
- return 1
+ MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${imtr}"
+
+ if [ -f "${MODULETORAMFILE}" ]
+ then
+ size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
+ total_size="$( expr $total_size + $size )"
+ else
+ log_warning_msg "Error: toram-module ${imtr} (${MODULETORAMFILE}) could not be read."
+ return 1
+ fi
fi
- fi
+ done
if [ "${copytodev}" = "ram" ]
then
# copying to ram:
freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
- mount_options="-o size=${size}k"
+ mount_options="-o size=${total_size}k"
free_string="memory"
fstype="tmpfs"
dev="/dev/shm"
@@ -45,9 +59,9 @@
fi
fi
- if [ "${freespace}" -lt "${size}" ]
+ if [ "${freespace}" -lt "${total_size}" ]
then
- log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
+ log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${total_size}k needed) to copy live media in ${copytodev}."
return 1
fi
@@ -80,6 +94,15 @@
else
cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
fi
+ elif [ -n "${MODULETORAMDIR}" ]
+ then
+ if [ -x /bin/rsync ]
+ then
+ echo " * Copying $MODULETORAMDIR to RAM" 1>/dev/console
+ rsync -a --progress ${MODULETORAMDIR} ${copyto} 1>/dev/console # copy only the filesystem module
+ else
+ cp -a ${MODULETORAMDIR} ${copyto} # copy the whole live directory
+ fi
else
if [ -x /bin/rsync ]
then
Reply to: