I'm trying to adapt a tutorial into an easy to use script http://qt-project.org/wiki/RaspberryPi_Beginners_guide.

I'm trying to reduce the need for sudo/root as much as possible (preferably, only for the final dd step).

My questions are:

  1. Can I mount the ext4 file system without sudo/root privileges in any way?

  2. Can I mount it in a way so that users/groups on the FS are ignored in some way (so I can run make install without sudo)?

The Filesystem is currently mounted loopback from an offset of a file (i.e. -o loop,offset=62914560).

This file is the image that will be copied onto the SD card used to boot the Raspberry Pi.


You want libguestfs. You can use it via guestfish or guestmount, or use the library directly through its C interface or any of the many language bindings, like Python.

  • 3
    While this seems to be the best answer, I think it's a bit overkill for this script. E.g. you need to manually change permissions on files in /boot for it to work properly on Ubuntu thanks to this. I think using sudo to mount and install is going to be the easier, and safer way to go. – Keyz182 Aug 28 '12 at 14:35

If your system uses udisks (and polkit allows udisks to mount for non-root users), you can mount the file with:

udisksctl loop-setup -f file.img -o <OFFSET>

<OFFSET> is an integer value to represent the number of bytes at which to start the loopback mount. You can use the -r switch if you want to mount read only.


Concerning this one the following comes into my mind.

You can add a line to your /etc/fstab for the device you want to mount as a user with normal privileges.

An example line would look like

/dev/mydevice    /mnt/directory    auto    rw,user    0    0

With this line a normal user can mount mydevice to /mnt/directory and additionally can read from- and write to the device. You only have to invoke

mount mydevice


mount /mnt/directory

For an excellent explanation of the syntax of/etc/fstab you should look at


Since the raspberry is an usb device you can achieve this more elegantly with udev by adding a specific udev-rule (auto-mounting etc.). In this case let me now if you want to have a further explanation.

  • Good advice, but unfortunately I don't think it's helpful in my case. I'm trying to adapt the tutorial into a distributable script for beginners to get an environment set up easily. I don't think I should be changing their fstab for that. Also, going to add more info to the question. – Keyz182 Aug 27 '12 at 10:46
  • 3
    maybe mountlo is interesting for your purpose!? mountlo can mount loopback devices from user space, at least this is mentioned in the description. You could add it to your distribution as a binary (or compile it on the fly), so your script can invoke it easily!? – user1146332 Aug 27 '12 at 11:15

You need superuser privileges to be able to mount. But those could be given to you by setuid helper commands like sudo, mount or fusermount. In /etc/fstab, and admin can grant some mere users to mount specific FS. Some users can be allowed to mount filesystems via fuse (for instance, if the FS is ext, you may be able to use fuseext.

Or maybe you can do without mounting, by using applications that can write inside a filesystem. For instance, debugfs can write to a ext fs image (create dirs, files, change ownership...), debugfs can be scripted easily You can also use qemu to run a Linux kernel and associated commands to write to that FS.


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