From a5273dc798ebe007ca31734186cf232202927494 Mon Sep 17 00:00:00 2001 From: Qixiang Wan Date: Tue, 11 Oct 2016 11:25:00 +0800 Subject: [PATCH] Replace mount/umount with guestfsmount and 'fusermount -u' 'mount -o loop' requires root privileges, guestmount from libguestfs-tools-c package can work without root privileges. Fixes: #19 Signed-off-by: Qixiang Wan --- pungi.spec | 1 + pungi/phases/buildinstall.py | 6 ++++-- pungi/phases/product_img.py | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pungi.spec b/pungi.spec index 6d41dbff..84f024d2 100644 --- a/pungi.spec +++ b/pungi.spec @@ -37,6 +37,7 @@ Requires: gettext Requires: syslinux Requires: git Requires: python-jsonschema +Requires: libguestfs-tools-c BuildArch: noarch diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index 3792d261..556635f9 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -253,7 +253,9 @@ def tweak_buildinstall(src, dst, arch, variant, label, volid, kickstart_file=Non if not os.path.isfile(image): continue mount_tmp_dir = tempfile.mkdtemp(prefix="tweak_buildinstall") - cmd = ["mount", "-o", "loop", image, mount_tmp_dir] + # use guestmount to mount the image, which doesn't require root privileges + # LIBGUESTFS_BACKEND=direct: running qemu directly without libvirt + cmd = ["LIBGUESTFS_BACKEND=direct", "guestmount", "-a", image, "-m", "/dev/sda", mount_tmp_dir] run(cmd) for config in configs: @@ -264,7 +266,7 @@ def tweak_buildinstall(src, dst, arch, variant, label, volid, kickstart_file=Non cmd = ["cp", "-v", "--remove-destination", config_path, config_in_image] run(cmd) - cmd = ["umount", mount_tmp_dir] + cmd = ["fusermount", "-u", mount_tmp_dir] run(cmd) shutil.rmtree(mount_tmp_dir) diff --git a/pungi/phases/product_img.py b/pungi/phases/product_img.py index dc3e316f..bab7fb09 100644 --- a/pungi/phases/product_img.py +++ b/pungi/phases/product_img.py @@ -138,7 +138,9 @@ def create_product_img(compose, arch, variant): "dd if=/dev/zero of=%s bs=1k count=5760" % pipes.quote(image), # create file system "mke2fs -F %s" % pipes.quote(image), - "mount -o loop %s %s" % (pipes.quote(image), pipes.quote(mount_tmp)), + # use guestmount to mount the image, which doesn't require root privileges + # LIBGUESTFS_BACKEND=direct: running qemu directly without libvirt + "LIBGUESTFS_BACKEND=direct guestmount -a %s -m /dev/sda %s" % (pipes.quote(image), pipes.quote(mount_tmp)), "mkdir -p %s/run/install/product" % pipes.quote(mount_tmp), "cp -rp %s/* %s/run/install/product/" % (pipes.quote(product_tmp), pipes.quote(mount_tmp)), "mkdir -p %s/run/install/product/pyanaconda" % pipes.quote(mount_tmp), @@ -148,7 +150,7 @@ def create_product_img(compose, arch, variant): "ln -s run/install/product/locale %s" % pipes.quote(mount_tmp), # compat symlink: run/install/product/pyanaconda/installclasses -> ../installclasses "ln -s ../installclasses %s/run/install/product/pyanaconda/installclasses" % pipes.quote(mount_tmp), - "umount %s" % pipes.quote(mount_tmp), + "fusermount -u %s" % pipes.quote(mount_tmp), # tweak last mount path written in the image "tune2fs -M /run/install/product %s" % pipes.quote(image), ]