[issue650] live-module revision 1.2

Tong Sun bts at bts.grml.org
Fri Jan 15 21:12:37 CET 2010


Tong Sun <suntong at cpan.org> added the comment:

- preliminary coding/testing done.
- porting the bare-bone of the feature proved to be working fine.
- able to insert / remove modules to the aufs system.
---
 bin/live-module |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/bin/live-module b/bin/live-module
index 4d5ace0..56a3f52 100755
--- a/bin/live-module
+++ b/bin/live-module
@@ -1,7 +1,21 @@
 #!/bin/sh
 
+. /usr/share/initramfs-tools/scripts/functions
 . /usr/share/initramfs-tools/scripts/live
 
+# Insert a directory tree $2 to an union specified by $1
+# Top-level read-write branch is specified by it's index 0
+# Using =rr enables aufs to optimize real readonly branches
+# $1 = union absolute path (starting with /)
+# $2 = path to data directory
+#
+union_insert_dir()
+{
+  log_begin_msg "Union_insert_dir $*"
+  mount -n -o remount,add:1:$2=rr aufs $1
+  log_end_msg
+}
+
 mount_image ()
 {
   image="${1}"
@@ -23,6 +37,43 @@ mount_image ()
   log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
   mount -n -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
   log_end_msg
+
+  union_insert_dir / "${croot}/${imagename}"
+
+}
+
+try_remount()
+{
+   mount -t aufs -o remount,verbose,del:"${croot}/${imagename}" aufs / 2>/dev/null
 }
 
-mount_image "$1"
+image="${1}"
+imagename=$(basename "${image}")
+croot=""
+
+mount_image "$image"
+
+exit 0
+set -x
+
+# Try to simply remove the dir first. If succeeds, finish
+rmdir "${croot}/${imagename}" 2>/dev/null && exit 0
+# OK the previous trick didn't work. So we have a real module here.
+
+# First, try to stop all daemons which may be started by this module
+#find_n_run_scripts ${croot}/${imagename} stop deactivate
+
+# detach it from aufs union. This may take a long time, remounting the
+# root directory is an expensive operation.
+try_remount
+
+
+# if we are here, the module has been successfuly removed from aufs union
+# so now we have to umount the lzm file and then free the loop device
+LOOP=$(cat /proc/mounts | grep "${croot}/${imagename} " | cut -d " " -f 1)
+umount -n "${croot}/${imagename}" 2>/dev/null
+if [ $? -ne 0 ]; then
+   exit 4
+fi
+losetup -d "$LOOP" 2>/dev/null # sometimes it's freed by umount automatically
+rmdir "${croot}/${imagename}" # if not empty or busy, a message will be shown
-- 
1.5.6.5

----------
assignedto: mika
messages: 2035, 2036, 2045, 2046, 2047, 2048, 2049, 2398, 2839, 2840
nosy: mika, suntong
priority: feature
status: need-eg
title: live-module revision 1.2

_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue650>
_____________________________________


More information about the Bugs-changes mailing list