FUSE userspace mounting of .qcow2 images
Usage: qcow2fuse.bash [-o fakeroot] [-o ro] [-o rawnbd] [-p PART_ID] imagefile mountpoint qcow2fuse.bash -u mountpoint qcow2fuse.bash -l imagefile
Supports read-write and read-only modes.
Supports .qcow2 files with backing files.
qcow2fuse uses qemu-nbd and nbdfuse first to mount the whole .qcow2 image to a temporary location. It then checks the mounted image for partitions using parted:
- if it is a non-partitioned image and partition ID was not specified with
-p
, qcow2fuse goes ahead and mounts the whole image to the specified mount point using fuse2fs. - if it is a partitioned image, and the specified partition ID (
-p
) matches an existing partition, then the offset and size of that partition are noted, then the initial qemu-nbd/nbdfuse mount is unmounted, then remounted using just the discovered offset and size to the temporary location. This raw partition is then mounted to the specified mount point using fuse2fs.
-u
unmounts an existing mountpoint, as well as the qemu-nbd/nbdfuse mount at a temporary location.
-l
lists partitions, or lack thereof, discovered in the .qcow2 image.
-o ro
mounts the image read-only
-o fakeroot
allows non-privileged access to files in the disk image that are owned by user 0 (root)
-o rawnbd
mounts the .qcow2 simply as a raw block device image file nbd
. This is useful for partition manipulation.
- FUSE. FUSE support must be in the kernel, such that
/dev/fuse
has read-write permissions for all users. Also libfuse.so and fusermount must be available. - qemu-nbd. This binary exports a .qcow2 file as a read-write NBD, in this case via a unix socket
- nbdfuse. This binary takes the NBD exported by qemu-nbd and FUSE mounts it to the filesystem
- parted. parted was chosen over fdisk and gdisk for a couple of reasons:
- It supports both MBR and GPT partition tables
- It can provide output in machine-readable format
- fuse2fs. This binary takes a raw disk image and FUSE mounts it to the filesystem. In this case, the raw disk image is the one provided by the nbdfuse/qemu-nbd mount.
The dependencies are all easily satisfied in Ubuntu 20.04.1. In particular, full FUSE support is already present, as is GNU parted. qemu-nbd, nbdfuse and fuse2fs may all easily be installed with the apt package manager:
sudo apt install qemu-utils sudo apt install nbdfuse sudo apt install fuse2fs
If sudo access for apt is not available, these dependencies are all buildable from source, without further dependencies.
By default, the script will use the first instances of qemu-nbd, nbdfuse, fuse2fs, fusermount, parted and mountpoint binaries that it finds in the $PATH
environment variable. However these may be overriden by exporting $QEMU_NBD
, $NBDFUSE
, $FUSE2FS
, $FUSERMOUNT
, $PARTED
and $MOUNTPOINT
respective environment variables giving the required path to the appropriate binaries.