I'm attempting to mount an ext4 partition image in userspace. (no sudo, no special config/permissions modification to /dev/loop0 or /etc/fstab etc). So I'm hoping FUSE will come to the rescue.

However it seems that each file system mounted through the FUSE system needs to have a special FUSE driver, and I've not been able to find a linux read-write ext4 FUSE driver for linux.

Is there a way to mount ext4 images via FUSE (with write permission)?

  • Maybe something like this. First search result on Google. – rchhe Jun 28 '12 at 19:39
  • Note: that is read-only. – Zoredache Jun 28 '12 at 19:41
  • 1
    I've seen that. It doesn't solve the problem for two reasons: It's OSX specific (unless I'm mistaken) and it's read-only. I should have specified that I need write access, but please be more polite before you know if someone has actually done their homework. – Catskul Jun 28 '12 at 19:47
  • 1
    Apologies, I skipped over the word "result" in your answer : / Sorry. The use-case is building and manipulating disk images in userspace, where root access is not available. – Catskul Jun 29 '12 at 0:15
  • 1
    Discussion on U/L StackExchange – palswim Mar 12 '18 at 6:32

fuseext2 apparently will mount ext4 partitions read-write.

Caveat: ext4 support is not advertised in their documentation, and attempts to mount come with a warning:

This is experimental code, opening rw a real file system could be
dangerous for your data. Please add "-o ro" if you want to open the file
system image in read-only mode, or "-o rw+" if you accept the risk to test
this module
  • AFAIK, even fuseext2 only mounts ext4 read only. That still comes back to the original question- why do you need FUSE driver that writes to your ext4 partition? And how and why is this question on a website for system administrators? – rchhe Jun 29 '12 at 3:27
  • 1
    The text of my post specifically includes the warning that mentions that it does rw. As stated in my reply to your answer, the use case is manipulating disk images without root access. And this is definitely a system administration issue. – Catskul Jun 29 '12 at 4:21
  • 1
    your link to fuseext2 has disappeared, replaced by advertisement. – sylvainulg Dec 19 '14 at 10:35
  • 1
    @sylvainulg: Link is fixed now. – krlmlr Feb 27 '15 at 17:25

You need a specific fuse driver for each file system type, as the point of fuse is to have the file system code running in user-land. So any pre-existing kernel driver code, running in kernel-land (ext2, ext3, ext4, xfs...) can't be used 'as-is' by fuse.

Nothing prevent developers to re-use part of the code from the corresponding kernel driver to implement a user-land fuse driver. But anyway, you always have to create a new driver for fuse for each file-system type. Kernel C code and user-land C code are quite different (no standard libc in the kernel, the driver entry-points do not have the same signature, etc...)

  • 2
    It would be an interesting project to be able to use a kernel module as a fuse driver though. I'm wondering if it's possible (running a kernel module in a kind of "emulated kernel environment"). – Laurent Grégoire Mar 10 '13 at 15:59

guestmount libguestfs trickery

sudo apt-get install libguestfs-tools

# Workarounds for Ubuntu 18.04 bugs.
# https://serverfault.com/questions/246835/convert-directory-to-qemu-kvm-virtual-disk-image/916697#916697
sudo rm -rf /var/cache/.guestfs-*
echo dash | sudo tee /usr/lib/x86_64-linux-gnu/guestfs/supermin.d/zz-dash-packages
sudo chmod +r /boot/vmlinuz-*

# Create a test image.
mkdir sysroot
dd if=/dev/urandom of=sysroot/myfile bs=1024 count=1024
virt-make-fs --format=raw --type=ext2 sysroot sysroot.ext2

# Mount it, have fun, unmount!
mkdir -p mnt
# /dev/sda becuase we have a raw filesystem.
guestmount -a sysroot.ext2.qcow2 -m /dev/sda mnt
cmp sysroot/myfile mnt/myfile
guestunmount mnt

Relies on:

  • userland implementation of the filesystems
  • FUSE

Docs: http://libguestfs.org/guestmount.1.html

Tested on Ubuntu 18.04, libguestfs-tools 1:1.36.13-1ubuntu3.

Not the answer you're looking for? Browse other questions tagged or ask your own question.