[arch-releng] [PATCH 6/6] [RFC] Another batch of improvements for archiso hook

Gerardo Exequiel Pozzi vmlinuz386 at yahoo.com.ar
Wed Feb 17 00:57:02 EST 2010


* make /dev/loop0 at archiso install hook, to take advantage of
  automatic module loading. There is no need for wait cycle.
* Mount squashfs images directly with mount instead of first using
  losetup, then mounting. These images are now mounted at
  /tmpfs/mnt/name-of-the-image instead of /tmpfs/mnt/loopN
  (count variable removed)
* Use "/newroot" passed as argument to mount hook.
* Drop to a recovery shell in cases when FSTYPE detection fail instead of
  just fail, then kernel panic!
* $newroot is passed to other _mnt_ functions in the same mountpoint.
* $copytoram code is removed since does not work with AUFS.
* Misc code style fixed.

Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386 at yahoo.com.ar>
---
 archiso/hooks/archiso   |   89 +++++++++++++++++++++--------------------------
 archiso/install/archiso |    1 +
 2 files changed, 41 insertions(+), 49 deletions(-)

diff --git a/archiso/hooks/archiso b/archiso/hooks/archiso
index 7b4d756..b54e1e5 100644
--- a/archiso/hooks/archiso
+++ b/archiso/hooks/archiso
@@ -1,48 +1,31 @@
 # args: source, mountpoint
-_mnt_bind()
-{
-    msg "::: Binding ${1} to ${2}"
-    mkdir -p $newroot${2}
-    /bin/mount -o bind ${1} $newroot${2}
+_mnt_bind() {
+    src="${1}"
+    mnt="${2}"
+    msg "::: Binding ${src} to ${mnt}"
+    mkdir -p "${mnt}"
+    /bin/mount -o bind "${src}" "${mnt}"
 }
 
-# args: /path/to/image_file
-_mnt_squashfs()
-{
-    /sbin/modprobe -q loop > /dev/null 2>&1
-
+# args: /path/to/image_file, mountpoint
+_mnt_squashfs() {
     img="${1}"
-    base_img="${img##*/}";
     mnt="${2}"
-
-    # FIX: This options does not work (see FS#17182)
-    if [ "${copytoram}" = "y" ]; then
-        msg ":: Copying squashfs image to RAM"
-        /bin/cat ${img} > "/tmpfs/${base_img}"
-        img="/tmpfs/${base_img}"
-    fi
-
-    msg "::: Adding new aufs branch: ${base_img%.*}"
-    mkdir -p "/tmpfs/mnt/loop${LOOP_NUM}"
-    # sometimes it takes udev a while to create device nodes
-    while [ ! -e "/dev/loop${LOOP_NUM}" ]; do
-        sleep 1
-    done
-    if ! /sbin/losetup "/dev/loop${LOOP_NUM}" ${img}; then
-        echo "ERROR: Cannot mount loop device /dev/loop${LOOP_NUM}"
-        break
-    fi
-    /bin/mount -r -t squashfs "/dev/loop${LOOP_NUM}" "/tmpfs/mnt/loop${LOOP_NUM}"
-    if [ "${mnt}" = "/" ]; then
-        /bin/mount -t aufs -o remount,append:/tmpfs/mnt/loop${LOOP_NUM}=ro none "$newroot"
+    img_fullname="${img##*/}";
+    img_name="${img_fullname%.*}"
+    tmp_mnt="/tmpfs/mnt/${img_name}"
+
+    msg "::: Adding new aufs branch: ${img_name}"
+    mkdir -p "${tmp_mnt}"
+    /bin/mount -r -t squashfs "${img}" "${tmp_mnt}"
+    if [ "/${mnt#/*/}" = "/" ]; then
+        /bin/mount -t aufs -o remount,append:${tmp_mnt}=ro none "${mnt}"
     else
-        _mnt_bind "/tmpfs/mnt/loop${LOOP_NUM}" "${mnt}"
+        _mnt_bind "${tmp_mnt}" "${mnt}"
     fi
-    export LOOP_NUM=$(( $LOOP_NUM + 1 ))
 }
 
-run_hook ()
-{
+run_hook () {
     if [ "x${arch}" = "x" ]; then
         arch="$(uname -m)"
     fi
@@ -66,7 +49,7 @@ run_hook ()
 }
 
 archiso_mount_handler() {
-    newroot="$1"
+    newroot="${1}"
 
     msg -n ":: Mounting tmpfs, size=${tmpfs_size}..."
     mount -t tmpfs -o "size=${tmpfs_size}" tmpfs /tmpfs
@@ -74,10 +57,10 @@ archiso_mount_handler() {
 
     msg ":: Waiting for boot device..."
     while ! poll_device ${archisodevice} 30; do
-      echo "ERROR: boot device didn't show up after 30 seconds..."
-      echo "   Falling back to interactive prompt"
-      echo "   You can try to fix the problem manually, log out when you are finished"
-      launch_interactive_shell
+        echo "ERROR: boot device didn't show up after 30 seconds..."
+        echo "   Falling back to interactive prompt"
+        echo "   You can try to fix the problem manually, log out when you are finished"
+        launch_interactive_shell
     done
 
     FSTYPE=$(blkid -o value -s TYPE ${archisodevice} 2> /dev/null)
@@ -85,26 +68,34 @@ archiso_mount_handler() {
         if mount -r -t "${FSTYPE}" ${archisodevice} /bootmnt > /dev/null 2>&1; then
             if [ -e "${isomounts}" ]; then
                 echo "SUCCESS: Mounted archiso volume successfully."
+                fserror="0"
             else
                 echo "ERROR: Mounting was successful, but the ${isomounts} file does not exist."
-                exit 1
+                fserror="1"
             fi
         else
             echo "ERROR; Failed to mount ${archisodevice} (FS is ${FSTYPE})"
-            exit 1
+            fserror="1"
         fi
     else
         echo "ERROR: ${archisodevice} found, but the filesystem type is unknown."
+        fserror="1"
     fi
 
-    msg ":: Mounting root (aufs) filesystem"
-    /bin/mount -t aufs -o dirs=/tmpfs=rw none $newroot
+    if [ "${fserror}" = "1" ]; then
+        echo "   Falling back to interactive prompt"
+        echo "   You can try to fix the problem manually, log out when you are finished"
+        launch_interactive_shell
+    fi
+
+    msg -n ":: Mounting root (aufs) filesystem"
+    /bin/mount -t aufs -o dirs=/tmpfs=rw none "${newroot}"
     if [ $? -ne 0 ]; then
         echo "ERROR: while mounting root (aufs) filesystem."
         exit 1
     fi
+    msg "done."
 
-    export LOOP_NUM="0"
     msg ":: Mounting images"
     while read img imgarch mountpoint type; do
         # check if this line is a comment (starts with #)
@@ -115,14 +106,14 @@ archiso_mount_handler() {
         [ ! -r "/bootmnt/${img}" ] && continue
 
         if [ "${type}" = "bind" ]; then
-            _mnt_bind "/bootmnt/${img}" ${mountpoint}
+            _mnt_bind "/bootmnt/${img}" "${newroot}${mountpoint}"
         elif [ "${type}" = "squashfs" ]; then
-            _mnt_squashfs "/bootmnt/${img}" "${mountpoint}"
+            _mnt_squashfs "/bootmnt/${img}" "${newroot}${mountpoint}"
         fi
     done < "${isomounts}"
 
     # Bind our bootmnt dir into the live system
-    _mnt_bind /bootmnt /bootmnt
+    _mnt_bind /bootmnt "${newroot}/bootmnt"
 
     if [ "${FSTYPE}" = "iso9660" -o "${FSTYPE}" = "udf" ]; then
         if [ -d /proc/sys/dev/cdrom ]; then
diff --git a/archiso/install/archiso b/archiso/install/archiso
index 5978f33..4d36412 100644
--- a/archiso/install/archiso
+++ b/archiso/install/archiso
@@ -11,6 +11,7 @@ install ()
     FILES=""
     add_dir /tmpfs
     add_dir /bootmnt
+    add_device /dev/loop0 b 7 0
     SCRIPT="archiso"
 }
 
-- 
1.6.6.1




More information about the arch-releng mailing list