6

It's a bit indirect, but it's possible to mount a partition with a disk image using mount or losetup's "offset" parameter.

I'm looking to be able to use fuse to do the same thing in user space

Use Case

My use case is building disk images on an autobuild server where the build job is not allowed to have root permissions, and the server should not need a custom setup for particular build jobs.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Catskul
  • 1,988

5 Answers5

3

It's possible to do with fuse, but would probably be cleaner with custom tools.

Solution

With apt-get-able tools the following kludge is possible:

mkdir mnt
xmount --in dd --out vdi disk.img mnt

mkdir mnt2
vdfuse -f mnt/disk.vdi 

mkdir mnt3
fuseext2 -o "rw" mnt2/Partition1 mnt3

Explanation

The basic idea is that fuse can be used to separate a full disk image in place into files that point to it's partitions. vdfuse does this, but is a VirtualBox tool and requires a VDI or VMDK file to work. xmount uses fuse to make a raw disk image appear as a VDI file.

Finally once the partition file is available via vdfuse, it can be mounted via an ext2/3/4 tool fuseext2.

It's ugly but it works completely in userspace.

Update

vdfuse should be able to mount a raw image without the help of xmount, but there is a bug which ignores the RAW option.

I tracked down and fixed the bug with a patch here:

https://bugs.launchpad.net/ubuntu/+source/virtualbox-ose/+bug/1019075

Catskul
  • 1,988
  • Addition: it should also be possible to make a simple vmdk file which references the disk image as RW 55296000 FLAT "disk.img" 0 or something like that (with extra headers and the correct size in 512-byte blocks) (I don't know if there's a tool to easily generate those). – HoverHell Jun 19 '13 at 11:27
1

There is pmount utility that is a wrapper around the standard mount program which permits normal users to mount removable devices without a matching /etc/fstab entry.

The only thing you need to allow user to use it is to add user to plugdev group.

rush
  • 27,403
0

libguestfs now has a command guestmount which spins up a virtual machine to allow you to mount arbitrary partitions in user space.

Catskul
  • 1,988
  • One or two line answers are often not the most helpful. Consider expanding your answer with links, elaboration or documentation which support your suggested solution. – HalosGhost Aug 28 '14 at 19:22
0
  1. losetup the image
  2. kpartx -av the resulting loopback-device
  3. Use the resulting partitions from /dev/mapper/... as you would do with a physical disk

You can accomplish all these tasks using an executable automount-map.

A chdir could trigger all the above actions. Or use sudo for a setup/removal script. Or...

Nils
  • 18,492
  • It seems that some/all of that would require root permission. – Catskul Jun 29 '12 at 21:29
  • @Catskul set set up the above, yes. To use it no. But same is true for your image. How do you create root-owned files if you do not have root permissions? – Nils Jun 30 '12 at 20:19
  • fakeroot will allow such a thing. – Catskul Jul 01 '12 at 02:26
  • Actually, after more reading and experimentation, it appears that fuse mounting allows you to modify files as if you were root without the use of fakeroot. – Catskul Jul 03 '12 at 00:57
0

Mounting thought loopback device with offset, might be helpful.

VDIfile=VirtData.vdi
mountingpoint=/mnt/VDI
offData=$( VBoxManage internalcommands dumphdinfo "$VDIfile" |grep offData | sed 's:.*offData=\([0-9]*\).*:\1:' )
offset=$(( $offData + 32256 ))
mount -t ext4 -o rw,noatime,noexec,loop,offset="$offset" "$VDIfile" "$mountingpoint"

More details here: https://unix.stackexchange.com/a/45019/9689