How do I manually mount a linux file system read/write as a normal user?

19

6

This may seem like a stupid question, but with most Linux stuff, it seems to me that a lot of trivial things are not documented.

Anyway, I want to simply mount an ext4 file-system onto a normal mount point in Ubuntu (/media/whereever), as read-writable for the current logged-in user, i.e. me.

I don't want to add anything into /etc/fstab, I just want to do it now, manually. I need super-user privileges to mount a device, but then only root can read-write that mount. I've tried various of the mount options, added it into fstab, but with no luck.

nicodemus13

Posted 2010-10-06T18:53:52.140

Reputation: 303

Is there a reason why you don't want to mount it somewhere within your home directory? – Robert S Ciaccio – 2010-10-06T19:14:57.880

Answers

13

On an ext4 filesystem (like ext2, ext3, and most other unix-originating filesystems), the effective file permissions don't depend on who mounted the filesystem or on mount options, only on the metadata stored within the filesystem.

With Ubuntu, mounting should happen automatically when you insert the disk, or you should be able to click on an icon to mount. You can also install pmount to mount filesystems as an ordinary user from the command line.

If you have a removable filesystem that uses different user IDs from your system, you can use bindfs (in the Ubuntu package of the same name) to provide a view of any filesystem with different ownership or permissions. The removable filesystem must be mounted already, e.g. on /media/disk9; then, if you want to appear as the owner of all files, you can run

mkdir ~/disk9
sudo bindfs -u $(id -u) -g $(id -g) /media/disk9 ~/disk9

Gilles 'SO- stop being evil'

Posted 2010-10-06T18:53:52.140

Reputation: 58 319

Thanks! This worked for me with ext3. Note that I had to first mount the ext3 filesystem into some mount directory, then mount that directory with bindfs into the final directory. – Ilari Kajaste – 2011-06-09T12:19:37.600

8

When you mount the ext4 file system, it uses the permissions that are embedded in that file system. If you wish to override these, then use the following:
1. Find the UID of the user you want to mount as: id <username> and look for UID=<userid>(<username>) GID=<groupid>(<groupname>) 2. sudo mount -o nosuid,uid=<userid>,gid=<groupid> /dev/whatever /media/wherever

This will mount the filesystem and mark the specified user as the owner of all files, and the specified group as the group for all files. nosuid is a security measure that prevents the user from bringing in suid programs and using them to gain root access to the system (i.e, a suid version of bash on the filesystem). Adding the noexec option will provide additional security, but will prevent the user from executing files on the filesystem.

Note: If you're just trying to interact with the file system yourself, you should either fix the permissions on the device, or interact with it as root if it's just a temporary thing (i.e., recovering a broken install).

If this is for mounting a USB or other removable external drive, you should check out the pmount system which can automate the process for you, or at least make it considerably easier (i.e., pmount <device> should create the folders for you, mount it as your user, and allow you to unmount it as your user)

Darth Android

Posted 2010-10-06T18:53:52.140

Reputation: 35 133

1Any idea whether this should work with EXT3 as well? I get EXT3-fs: Unrecognized mount option "uid=1000" or missing value in dmesg when I try it with ext3. – Ilari Kajaste – 2011-06-09T11:25:29.570

@Ilari: It won't work with ext3, nor with ext4 for that matter. Most Linux drivers for unix filesystems don't have UID and GID mapping options. – Gilles 'SO- stop being evil' – 2011-06-09T12:31:32.873

-1 Doesn't work. – Ilari Kajaste – 2011-06-10T06:16:25.813

2

You can use:

mount -o user /dev/devicename and user option in your fstab.

Andrey Regentov

Posted 2010-10-06T18:53:52.140

Reputation: 1 196

1

If you're not in the mood to hand-edit your /etc/fstab file, I'd suggest trying out PySDM to define the rules for mounting your ext4 file system on a regular basis. It can be installed by installing the "pysdm" package in Synaptic, or by searching the Ubuntu Software Center for "pysdm". Once installed, it is available under the System --> Administration --> Storage Device Manager..

PySDM in action

Zoot

Posted 2010-10-06T18:53:52.140

Reputation: 435

1

Just realised after reading last comment at http://ubuntuforums.org/showthread.php?t=2142284 that all one has to do is a sudo chown -Rvf <user>:<group> <mountpoint>

This is all that is required ...

SACHIN GARG

Posted 2010-10-06T18:53:52.140

Reputation: 11

2This is a destructive operation. If you do it before mounting, it won't make any difference to file ownership on the mounted drive; if you do it after mounting then it will overwrite all of the permissions. If the drive contains a Linux installation, changing permissions like this will make it unbootable after you unmount it. – Warbo – 2018-04-12T09:14:01.243