Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I mount a device with specific user rights on start up? I still have some problems figuring it out. I would like to mount the divide with uid=1000 and gid=1000. My current entry to the /etc/fstab/ file looks like this:

dev /var/www vboxsf rw, suid, dev, exec, auto, nouser, async, uid=1000
share|improve this question
    
Don't forget gui=1000. Also, what is the ownership/rights to /var/www. It should be owned by root. –  skub Aug 8 '11 at 12:57
    
@skub: The owner of /var/www/ is root. dev /var/www vboxsf rw, suid, dev, exec, auto, nouser, async, uid=1000 gui=1000 didin't work so well (Ubuntu removed the entry after a failed restart). –  wowpatrick Aug 8 '11 at 21:14
    
Your mount source is "dev"?? –  Doc Aug 8 '11 at 21:51
    
@wowpatrick - your mount device should be something like /dev/sda1 it should not be 'dev'. –  skub Aug 8 '11 at 22:53
    
@skub: It's a VirtualBox shared folder, so /dev is is right. I figured it out by now, sudo mount -t vboxsf -o umask=0022,gid=33,uid=33 dev /var/www works just fine. –  wowpatrick Aug 8 '11 at 23:16
show 1 more comment

2 Answers

up vote 34 down vote accepted

To mount a device with certain rights, you can use the -o Option directive while mounting the device. To mount the device you described, run:

 mount -t deviceFileFormat -o umask=filePermissons,gid=ownerGroupID,uid=ownerID /device /mountpoint

For example mountig a VirtualBox shared folder to /var/www with www-data as owner would look like this:

mount -t vboxsf -o umask=0022,gid=33,uid=33 dev /var/www

If you want to mount the device on startup, you can add the following entry to your /etc/fstab file:

 /device /mountpoint deviceFileFormat umask=filePermissons,gid=ownerGroupID,uid=ownerID

Again, with the same example the entry to the /etc/fstab file would look like this:

dev /var/www vboxsf umask=0022,gid=33,uid=33

For filesystems that does not support mounting as a specific user (like ext4) the above will give the error

Unrecognized mount option "uid=33" or missing value

to change the owner of an ext4 mount simply run

chown username /mountpoint

after it has been mounted.

share|improve this answer
add comment

For a file-system like ext3 or ext4, after doing

    chown -R username:group /mountpoint

to change the owner of the currently existing files you can set the group id bit to have new files created with the specific group (doesn't work for the user id under Linux):

    find /mountpoint -type d -exec chmod g+ws {} \;

The Wikipedia entry on setuid and setgid is quite informative, see the section on directories.

share|improve this answer
5  
Changing the ownership of all the files on the device is very invasive. Since there is a -o option for mount, it is the better way. –  Limited Atonement Apr 29 '13 at 15:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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