New SYSTEM_DISK_ACCESS_METHOD "guestmount" - now the default if installed
authorMartin Schwenke <martin@meltin.net>
Fri, 2 Mar 2012 05:07:58 +0000 (16:07 +1100)
committerMartin Schwenke <martin@meltin.net>
Fri, 2 Mar 2012 05:07:58 +0000 (16:07 +1100)
This uses the libguestfs-mount fuse magic on Red Hat.  The real
advantage over guestfish is that "autocluster mount" gives you a real
mountpoint where you can browse the filesystem.

Signed-off-by: Martin Schwenke <martin@meltin.net>
config.d/00base.defconf
config.d/05diskimage_guestmount.defconf [new file with mode: 0644]

index 839ffd3b54f4b07d658ef410a51e81bbeb8de0fc..ff4557103878b813cf355fc1e6df217ff3cfe128 100644 (file)
@@ -100,13 +100,15 @@ defconf SYSTEM_DISK_FORMAT "qcow2" \
        "qcow2|raw|reflink|none" "system disk image format"
 
 defconf SYSTEM_DISK_ACCESS_METHOD "@uto" \
-       "loopback|guestfish" "how to setup up disk images"
+       "loopback|guestfish|guestmount" "how to setup up disk images"
 
 system_disk_access_method_hook ()
 {
     if [ "$SYSTEM_DISK_ACCESS_METHOD" = "@uto" ] ; then
        if [ "$SYSTEM_DISK_FORMAT" = "qcow2" ] ; then
-           if which guestfish >/dev/null 2>&1 ; then
+           if which guestmount >/dev/null 2>&1 ; then
+               SYSTEM_DISK_ACCESS_METHOD="guestmount"
+           elif which guestfish >/dev/null 2>&1 ; then
                SYSTEM_DISK_ACCESS_METHOD="guestfish"
            elif which qemu-nbd nbd-client >/dev/null 2>&1 ; then
                SYSTEM_DISK_ACCESS_METHOD="loopback"
@@ -136,7 +138,7 @@ system_disk_mounts ()
                (*) die "Unknown RHEL_VERSION in system_disk_mounts" ;;
            esac
            ;;
-       (guestfish) echo "/:/dev/vda1" ;;
+       (guestfish|guestmount) echo "/:/dev/vda1" ;;
        (*) die "Unknown SYSTEM_DISK_ACCESS_METHOD in system_disk_mounts" ;;
     esac
 }
diff --git a/config.d/05diskimage_guestmount.defconf b/config.d/05diskimage_guestmount.defconf
new file mode 100644 (file)
index 0000000..d57e474
--- /dev/null
@@ -0,0 +1,145 @@
+# Hey Emacs, this is a -*- shell-script -*- !!!
+
+# This file provides functions to implement access/update of disk
+# images via guestmount.
+
+######################################################################
+
+diskimage_mount_guestmount ()
+{
+    local disk="$1"
+
+    echo "Using guestmount to update disk image ${disk}..."
+
+    local mount_args=""
+    local m d
+    for m in $SYSTEM_DISK_MOUNTS ; do
+       d="${m#*:}" # Device is after colon
+       m="${m%:*}" # Mountpoint is before colon
+       mount_args="${mount_args}${mount_args:+ } --mount ${d}:${m}"
+       echo " mount ${m} from device ${d} configured"
+    done
+
+    mkdir -p mnt
+    guestmount -a "$disk" $mount_args mnt || \
+       die "Failed to mount $disk using guestmount"
+
+
+    [ -d "mnt/root" ] || {
+       echo "Mounted directory does not look like a root filesystem"
+       ls -latr mnt
+       exit 1
+    }
+}
+
+# unmount a qemu image
+diskimage_unmount_guestmount ()
+{
+    echo "Unmounting disk"
+    sync; sync;
+
+    fusermount -u mnt
+}
+
+# These are all the same as loopback.  We could do something cleverer,
+# but this will suffice for now.
+
+diskimage_mkdir_p_guestmount ()
+{
+    mkdir -p "mnt$1"
+}
+
+diskimage_substitute_vars_guestmount ()
+{
+    substitute_vars "$1" "mnt$2"
+}
+
+diskimage_chmod_guestmount ()
+{
+    local mode="$1" ; shift
+    local i
+    for i ; do
+        # this should handle wildcards
+       eval chmod "$mode" "mnt$i"
+    done
+}
+
+diskimage_chmod_reference_guestmount ()
+{
+    local ref="$1" ; shift
+    local i
+    for i ; do
+        # this should handle wildcards
+       eval chmod --reference="$ref" "mnt$i"
+    done
+}
+
+diskimage_is_file_guestmount ()
+{
+    [ -f "mnt$1" ]
+}
+
+diskimage_is_directory_guestmount ()
+{
+    [ -d "mnt$1" ]
+}
+
+diskimage_append_text_file_guestmount ()
+{
+    cat "$1" >> "mnt$2"
+}
+
+diskimage_append_text_guestmount ()
+{
+    echo "$1" >> "mnt$2"
+}
+
+diskimage_sed_guestmount ()
+{
+    local file="$1" ; shift
+    sed -i.org "$@" "mnt$file"
+}
+
+diskimage_grep_guestmount ()
+{
+    local file="$1" ; shift
+    grep "$@" "mnt$file"
+}
+
+diskimage_put_guestmount ()
+{
+    cp "$1" "mnt$2"
+}
+
+diskimage_ln_s_guestmount ()
+{
+    ln -s "$1" "mnt$2"
+}
+
+diskimage_command_guestmount ()
+{
+    chroot mnt "$@"
+}
+
+diskimage_mv_guestmount ()
+{
+    mv "mnt$1" "mnt$2"
+}
+
+diskimage_rm_f_guestmount ()
+{
+    rm -f "mnt$1"
+}
+
+######################################################################
+
+diskimage_guestmount_sanity_check ()
+{
+    if [ "$SYSTEM_DISK_FORMAT" = "qcow2" -a \
+       "$SYSTEM_DISK_ACCESS_METHOD" = "guestmount" ] ; then
+       check_command guestmount
+       check_command fusermount
+    fi
+}
+
+register_hook post_config_hooks diskimage_guestmount_sanity_check