6

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)?

Catskul
  • 1,999

3 Answers3

3

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
krlmlr
  • 563
Catskul
  • 1,999
2

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...)

1

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.