LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   mount USB drive as user (https://www.linuxquestions.org/questions/linux-software-2/mount-usb-drive-as-user-681113/)

RAFAL 11-04-2008 02:12 PM

mount USB drive as user
 
Hi,
I have some external USB drives (WD) which are not considered by system as removable. I have one with NTFS and two with FAT32.

When I try to mount I get error:

rafal@linux-39sr:~> mount /dev/sdb1 /mnt/usb1
mount: only root can do that

I know this was discussed several times, but no solution worked for me.
Here what didn't work:

1)
chmod +s /bin/mount
chmod +s /bin/umount

2)
giving sudo:
In YaST (I am using suse) I added my user option to execute /bin/mount, but it still does not work. maybe its about the access to /dev/sdb1 ?


I don't want to add any entry to /etc/fstab because I have several USB slots and disks. Some are NTFS, some FAT32. If I add entry in fstab then I never sure whether next time my sdb1 will be FAT32 or NTFS. It depends which drive I will connect as first (and maybe only one).

What I have to do in order to give access for my user to mount everything I want.

regards
Rafal

jlinkels 11-04-2008 05:42 PM

There are various options I would try. First off, create an entry in fstab with the user option, but without the type specified.

Now since you specified user you should be able to mount it as a user, however you have not define the type yet.

Try:
-t autofs
-t vfat,ntfs (mount will try these in this order)
-t vfat (if you are sure it is vfat)
-t ntfs (likewise)

Reading thru man fstab I get the idea that other options are retrieved from fstab but that you are free to specify the type in the command.

jlinkels

jschiwal 11-04-2008 06:26 PM

To resolve the problem where the same drive may have a different device node the next time you boot or plug it in, use the uuid or label instead of the device.

Suppose that the partition to mount is /dev/sdb. Then run "udevinfo -q env -n /dev/sdb". There will be a line like:
FS_UUID=ABC123-123432
Copy the UUID= and the number after it and paste it in the fstab entry in place of /dev/sdb.

For fat32 partitions, to be able to mount them as root, you need the "user" or "users" option and UID= and GID= options as well. Then a regular user can mount and unmount the partition. You can use either your username or your uid number.

The mount command is normally an suid program. It checks the mount options in /etc/fstab to determine whether a regular user will be allowed to use the command or not.

RAFAL 11-05-2008 03:37 PM

Quote:

Originally Posted by jschiwal (Post 3331868)
Suppose that the partition to mount is /dev/sdb. Then run "udevinfo -q env -n /dev/sdb". There will be a line like:
FS_UUID=ABC123-123432
Copy the UUID= and the number after it and paste it in the fstab entry in place of /dev/sdb.

Hi
Thanks for advise.
I executed the command and added the line to /etc/fstab:

Code:

UUID=B06A38A66A386AEC /mnt/usb1  ntfs-3g    users,gid=users,locale=pl_PL.UTF-8 0 0

here the error I get:

Code:

rafal@linux-39sr:/mnt> mount /mnt/usb1
Error opening '/dev/sdb1': Brak dostępu
Failed to mount '/dev/sdb1': Brak dostępu
Please check '/dev/sdb1' and the ntfs-3g binary permissions,
and the mounting user ID. More explanation is provided at
http://ntfs-3g.org/support.html#unprivileged

"Brak dostępu" means "No access"
Only user 'root' have access to /dev/sdb1

Once I read I should add my user to group "disk' but it is not solution

So what can I do to get access to /dev/sda1.
chmod ?
I tested with "chmod 777" and afterwards get another error:

Code:

rafal@linux-39sr:/mnt> mount /mnt/usb1
ntfs-3g-mount: mount failed: Operacja niedozwolona
User doesn't have privilege to mount. For more information
please see: http://ntfs-3g.org/support.html#unprivileged

'Operacja niedozwolona" means "operation not permitted"

what will be clean solution here?

The reason why I need to mount device manually is that sometimes I'm using "Blackbox" as x-manager.

regards
Rafal

Shadow_7 11-05-2008 05:00 PM

modding /etc/fstab should be all you need to do.

Well, that and adding said user to the disk group.
And maybe chgrp the mount point.

/dev/uba1 /mnt/usb vfat user,noauto 0 0
/dev/sda1 /mnt/usb vfat user,noauto 0 0
/dev/sdf1 /mnt/usb vfat user,noauto 0 0

$ chgrp disk /mnt/usb

$ cat /etc/group | grep -i "disk"
disk:x:6:user

$ mount /mnt/usb

or

$ mount /dev/uba1
depending on which device or which usb port I use. Or if it's plugged in at boot time, versus inserted later. Check /proc/partitions to see what it registered as. (if it registered)

$ cat /proc/partitions

HTH

jschiwal 11-06-2008 02:57 AM

Adding a user to the disk group is a bad idea. That is the group owner of the raw devices as well. You want to grant access to one partiton, not all of them and not the raw devices (such as /dev/sdb) as well. Making a typo as a member of the disk group, you can wipe out any partition.

Read the web page that the error message points to. It gives solutions.
You can also use the ntfs filesystem. It might not work if the ntfs partition was formatted in vista and there are volume flags that aren't supported. Using these options, and the ntfs filesystem, I can mount it as a normal user:"rw,user,fmask=117,dmask=007,uid=jschiwal,gid=jschiwal"
However, due to unsupported features, it is mounted read-only.

onesixtyfourth 11-06-2008 03:18 AM

This may be over simplistic and not what you need but could you install and use pmount?

tothzp 11-06-2008 05:06 AM

Quote:

UUID=B06A38A66A386AEC /mnt/usb1 ntfs-3g users,gid=users,locale=pl_PL.UTF-8 0 0
Sorry but shouldn't the option be user instead of users ?

man mount says:

Quote:

(iii) Normally, only the superuser can mount file systems. However, when fstab contains the user option on a line, then anybody can mount the corresponding system.
Another solution would be to mount your disk via autofs. Then mounting is automatic and you can set an umask to give permission to others.

jschiwal 11-09-2008 02:19 AM

The "users" option is similar to the "user" option. Using "users" any user can umount it. Maybe "user" would be a better option. There is also the "owner" option. Even if a different user mounts a fat32 partition, the uid=, gid=, fmask= and dmask= options will determine whether that user can read or write.

Use fmask and dmask instead of simply umask. You don't want the files to have the "x" bit set. You need the directories to have the "x" bit set. The "x" bit has different uses for files & directories so you need to use fmask & dmask instead.


All times are GMT -5. The time now is 10:29 PM.