20

I want to mount a supplementary ext4 data disk drive with specified rwx permission for a certain user. The mount point is inside the home of such a user and it's owned by the user. I added the new data disk in /etc/fstab in the standard way:

/dev/hda  /home/user/new_disk  ext4  defaults,errors=remount-ro  0 1

Anyway when the new partition is mounted, the ownership of the mount point change from user.group to root.root and so the user has no write permissions there. I can change manually the ownership of the mount point so the user can write there, but the problem reappear at each rebooting. I've even tried to add the disk in the fstab in the following way:

/dev/hda  /home/user/new_disk  ext4  umask=0077,uid=1000,gid=1000,errors=remount-ro  0 1

But in this case the system gives me an error because the volume has ext4 format. I want to either:

  • mount the ext4 drive already with specified user permission, or
  • change the ownership of the mount point at each startup after the disk has been mounted.
3
  • Who will be mounting the disk? Should the user himself be able to mount it?
    – holgero
    Dec 15, 2012 at 21:42
  • I think that if I use the words "user,users" in the mounting options of fstab, the user would be able to mount the disk.
    – green69
    Dec 16, 2012 at 11:41
  • 1
    There's a similar question on Ask Ubuntu. Aug 1, 2014 at 12:32

5 Answers 5

16

Use bindfs:

A FUSE filesystem for mirroring the contents of a directory to another directory. Additionally, one can change the permissions of files in the mirrored directory.

Mount the ext4 filesystem as /media/disk:

sudo mount -o user /dev/sdXN /media/disk

Bind the mounted filesystem with permissions for the current user (or any other user/group):

sudo bindfs -u $(id -u) -g $(id -g) /media/disk /home/user/new_disk
1
  • 1
    Just be careful as BindFS imply some overhead when accessing file. See here for details.
    – Doc Davluz
    Dec 8, 2014 at 8:45
9

Only FAT, vFAT, exFAT support the uid, gid, umask options. You can check this by reading the list of the possible options in the mount man page, section "Mount options for fat".

However, you can change ownership of the existing directory system by using chown on the filesystem's mount point, like:

# mount /dev/sda* /mnt/your/mountpoint/
# chown user:group 741 /mnt/your/mountpoint/
1
  • 3
    That changes the permissions on the file system permanently. Any user/group differences will be wiped out, and any SUID/SGID bits will be reset.
    – vonbrand
    Jan 30, 2014 at 16:10
0

I've just encountered the same problem. What I've done is mounted the filesystem first, then changed all the permissions and owner:group on the mount point, subdirectories, and files. Then when I umount the filesystem and remount it these changes appear to be persistent.

15:24@boromir:/media$ cat /etc/fstab
UUID=95446ed0-b6a6-42cd-8c37-ea81a0836e98 /media/cavalry1  auto   defaults,nofail       0 0

15:26@boromir:/media$ sudo umount cavalry1/
15:27@boromir:/media$ l
total 28
drwxrwxrwx 2 boincuser boincuser 4096 2012-12-17 15:00 cavalry1/

15:27@boromir:/media$ sudo mount -a
15:28@boromir:/media$ l
total 28
drwxr-xr-x 3 boincuser boincuser 4096 2012-12-17 11:05 cavalry1/

Here you can see the permissions and owner aren't reset upon remounting the filesystem.

0

When mounting an EXT filesystem, the permissions from the perspective of host filesystem appears to be what ever the guest filesystem already has.

0

Mount block devices as a user. To add to this topic, if all else fails, try guestmount from the libguestfs package, available in some distros since 2009, but also as source code. guestmount, uses file system in userspace (FUSE) to permit mounting, as a user, with user permissions. As long as said user owns the mount point, and has the appropriate access to the block device or image to be mounted. On some distros, (but for sure not Fedora or RedHat) the user may need to be a member of the fuse group in order to do this.

$ mkdir ~/mnt && guestmount -a /dev/hda -m /dev/hda ~/mnt

This may also be used to mount any type of media for other platforms and file system images that QEMU knows about, not just linux media and windows flash drives. The operating system, file system type (ext4?) sub-device or partition number (did you mean /dev/hda1?), and logical block offsets are figured out automatically, so you might not even need to specify them in most cases.

Guest images. If you wish to mount drive images as a user, there is no need anymore to run fdisk -l to examine the partition table and multiply by the sector size to obtain the offset, for example, mount -o loop,offset=49152. Good thing, since in some cases the image isn't recognizable to fdisk. Something like this might still work though.

mkdir my_disk; guestmount -a my_disk.img -m /dev/sda1 my_disk

It can even guess the operating system with the -i option and emulate the appropriate processors and drivers. Several examples are in the man page.

Known issues.

  • As with bindfs mentioned in https://superuser.com/a/831316/963137, there is some overhead accessing devices via fuse. So it's not a permanent solution.

  • The mounted file system will appear to have permissions set to root when examined with ls -l, but, surprisingly, the user can indeed access and write to it. Try it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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