14

I cannot create files in my newly mounted partition . The folder to which i am mount the partition, /media/hrmount, is owned by root so even if I add a fstab line like

UUID=irrelevant /media/hrmount  ext4   defaults,user      0      2

/media/hrmount is still owned by root when i remount "irrelevant" .

And if i delete the directory in hope that "mount" will create it automatically and make it owned the user that issued the mount command I'll just get an error message saying the directory does not exist.

I could just use chown to make the directory owned by uid1000 but I understand it should not be needed plu I am positive that if i create another user, let's call him uid1001, then if we unmount the partition fs and then remount it as uid1001 it's mount point, /media/hrmount will still be owned by uid1000. This means I'll have to fiddle with permissions and while I can do that I have heard that just by adding the device to fstab like above should just work. How can I achieve that?

The ideal behaviour would be to just issue the mount device command either by sudoing or normally and the partition is mounted and also the folder is automatically created.

PS: I'm on Linux Mint 13

6 Answers 6

14

If a Linux filesystem (not e.g. FAT32, NTFS) is mounted then the directory permissions for the root directory are taken from the filesystem.

root must either change the owner (chown) or permissions (chmod, setfacl) of the root directory or has to create subdirectories which are writable by the users. The latter is what happens with the normal root volume: With the exception of tmp no standard directory is writable by users. The users can write to their directory below /home (and maybe to non-standard directories and subdirectories).

8

You are confusing the generic option user with the filesystem specific option uid.

from fstab(5)

user allow a user to mount

and from mount(8)

uid=value and gid=value Set the owner and group of all files. (Default: the uid and gid of the current process.)

which applies to the msdos, umsdos and vfat filesystems. you can do similar options with adfs, affs, devpts, hfs, hpfs, iso9660, ntfs, tmpfs, udf and usbfs filesystems. you do not need to set the uid on any filesystem that was designed for unix, Indeed you do not want to, as the filesystem can do this itself.

2
  • uid=1000 or some other number does not work in fstab for non ntfs files from what i can see
    – bloys
    Commented Jan 27, 2015 at 13:52
  • 2
    Setting the uid ONLY WORKS on the filesystems listed. It does not work with any ext filesystem. It does not work on jfs, xfs, or any filesystem designed for UNIX or Linux. There would be advantages to extending the uid option to all filesystems (expecialy for removable media used on multiple computers) but that is not the case. but my main point was that the user option (which works fine) not only does not do what you want, it does something you probably do not want.
    – hildred
    Commented Jan 27, 2015 at 14:17
4

After the mounting the uid:gid and permissions of the mount point are set to ones from the root directory of the mounted partition. So to change the owner/permissions mount the partition as root, chdir to the mount point and set them as you want using

# chmod 777 .

or

# chown johndoe:users .

2
  • Welcome to unix.SE. This will need to be done when unmounted, right?
    – Tom Hale
    Commented Feb 26, 2017 at 12:49
  • 4
    chmod 777is one of the worst practices in the unix world. Forget it, unless you know what you are doing... Also, it's important to emphasise that the chown command needs to be applied to the mounted filesystems root directory. (Unmounted, a mountpoint is typically a directory of the root filesystem (some exceptions apply), while after mount, the mountpoint is the root directory of the newly mounted filesystem. e.g. /mnt/hd when empty, is directory /mnt/hd of the / filesystem. /mnt/hd is the / of the mounted filesystem. )
    – Bgs
    Commented Feb 18, 2021 at 15:11
2

To automatically set ownership of a partition

This is what I did on Ubuntu is.

  1. Find and launch Disks app
  2. Select the storage disk and select the partition.
  3. Click the option button and select edit mount options...
  4. Switch off Defaults
  5. append uid=1000,gid=1000 to the listed mount options.
  6. Click OK.
  7. Unmount and remount the partition and you are done.

To allow executing file as program

This guide is useful if you want to grant execution permission to executable files, just add exec to the option list

1

Mount NORMALLY replaces the mount-point directory ownership and permissions with those of the top directory of the mount device. So yes, you should (onetime) mount the file system and then 'sudo chown $(id -u):$(id -g) /somewhere/mntpt' From then on it will mount w/ your uid:gid.

An exception is that some filesystems (like vfat) do not have a uid, gid mappable ownership concept.

-2

Thank you all for the provide information. I have managed to mount the partition's filesystem as I wanted. The correct way to achieve what I wanted was to edit /etc/fstab ( i gave up using the user/users option ) then do a sudo mount -a and it worked great. When I dismount irrelevant, /media/hrmount becomes owned by root:root . After I do a sudo mount -a the mount point switches the owner to uid1000:uid1000 .

1
  • 7
    You say that you edited /etc/fstab — what did you put in it?  Your question shows that your /etc/fstab entry says ext4 — are you sure that the filesystem is really an ext4 filesystem?  Did you chown the filesystem to 1000:1000? Commented Jun 23, 2015 at 11:11

You must log in to answer this question.

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