]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dmsquash-live-root: determine img type by contents, not name
authorWill Woods <wwoods@redhat.com>
Mon, 1 Aug 2011 20:21:08 +0000 (16:21 -0400)
committerHarald Hoyer <harald@redhat.com>
Fri, 12 Aug 2011 06:03:55 +0000 (08:03 +0200)
Currently dmsquash-live-root requires that squashfs images be named
"squashfs.img" and all others be "ext3fs.img" or "rootfs.img".

If we've got a live image in initramfs, this patch will make dracut use
losetup and det_fs to determine the actual filesystem type of the image.

Signed-off-by: Will Woods <wwoods@redhat.com>
modules.d/90dmsquash-live/dmsquash-live-root

index a76cbc7aae9c29ed6a149547c1368302a8b1ad47..265de19b538ab6bf879d3da5864ff913d1a0e5d4 100755 (executable)
@@ -41,14 +41,23 @@ if [ -n "$check" ]; then
     [ -x /bin/plymouth ] && /bin/plymouth --show-splash
 fi
 
+# determine filesystem type for a filesystem image
+det_img_fs() {
+    local _img="$1" _loop=$(losetup -f) _fs
+    losetup $_loop $_img; _fs=$(det_fs $_loop); losetup -d $_loop
+    echo $_fs
+}
+
 for arg in $CMDLINE; do case $arg in ro|rw) liverw=$arg ;; esac; done
 # mount the backing of the live image first
 mkdir -m 0755 -p /run/initramfs/live
 if [ -f $livedev ]; then
     # no mount needed - we've already got the LiveOS image in initramfs
-    case $livedev in
-        *squashfs.img) SQUASHED=$livedev ;;
-        *ext3fs.img|*rootfs.img) FSIMG=$livedev ;;
+    # check filesystem type and handle accordingly
+    case `det_img_fs $livedev` in
+        squashfs) SQUASHED=$livedev ;;
+        auto) die "cannot mount live image (unknown filesystem type)" ;;
+        *) FSIMG=$livedev ;;
     esac
 else
     mount -n -t $fstype -o ${liverw:-ro} $livedev /run/initramfs/live