Here is my setup:

  • I am non-privileged user (non-root).
  • I cannot use sudo, nor I can use any other command to switch to root (e.g. su), or run commands as root.
  • As a consequence, I cannot modify the /etc/* configuration files.

I'd like to achieve the following:

  1. Create sparse file of let's say 10MB. Already done.
  2. Format the sparse file with let's say Ext2. Problem!!!
  3. Mount the sparse file and add some content in it. Problem!!!

I can do all of this as root user but if I am a normal user then to me it seems like "mission impossible" to mount the file because I have to use losetup and mount which both require root privileges.

Is there a way to do all of this without switching to root context?

  • 1
    Note, you can do the mkfs.ext2 on a file without being root by using the -F flag.
    – meuh
    Commented Apr 12, 2016 at 9:14
  • The question title doesn't describe what you want at all. The question is about mounting a disk image, but the title doesn't mention that. The answer to the title is truncate and/or dd and/or fallocate Commented Aug 7, 2016 at 1:56

1 Answer 1


Long story short - there's no way to do all of this without root permissions. For example, mount requires root permissions and there is no way to workaround this. It's for security reasons - if a user has mount privileges, this user can overmount let's say /etc and use whatever content there. It's a serious security risk and therefore by default only the root user is allowed to use mount.

I implemented my solution by introducing proper checks - if the current user is root then I use mount and other root specific commands. If the user is another one, then I go to another execution branch and I don't use root specific stuff.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .