Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

It's a bit indirect, but it's possible 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.

share|improve this question
    
I do not understand why you want to mount the image that has been generated. –  Nils Jun 29 '12 at 19:55
    
To copy files over, chroot, rsync or otherwise backup, etc. –  Catskul Jun 29 '12 at 20:04
    
Also, deboostrap. –  Catskul Jun 29 '12 at 20:14

5 Answers 5

up vote 3 down vote accepted

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

share|improve this answer
    
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

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.

share|improve this answer
    
Only works if the "device" lives in /dev/ –  Catskul Aug 6 at 18:43
  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...

share|improve this answer
    
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 1 '12 at 2: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 3 '12 at 0:57

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: http://unix.stackexchange.com/a/45019/9689

share|improve this answer

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

share|improve this answer
    
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 at 19:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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