External USB hard drive always mounting as root?

Q I have set up a small server running Debian Etch, mainly to use as a fileserver but also eventually for some web-based stuff. I have a USB hard drive that I want to use as shared storage via Samba. My problem is that no matter what I do the drive is always mounting as root. If I set the mount point permissions to 777, user=guest and group=users and then mount it as a normal user, the permissions stay the same but user and group both revert to root. So I still can't write to the drive. If I mount as user root I have no problems accessing locally but in either situation Samba then won't let me write either. Someone suggested this was maybe a udev issue and that I needed to play with that so that the permissions are altered when it mounts. I'm not up on udev so don't know where to start. The drive is sda with partitions sda1 and sda2.

A Udev only handles creation of the device node (/dev/sda1 or whatever) not the mounting, so this is unlikely to be at fault. It is possible that udev is creating the node with restrictive permissions, but this would only stop users mounting the device (not root) it wouldn't affect the mounted filesystem. The user mount option doesn't take the name of a user, it simply allows any user to mount that filesystem, nor does it affect the permissions of the filesystem. The solution to your problem depends on the type of filesystem you are using.

If this is a Linux-type filesystem that supports user permissions, setting the ownership and permissions of the mount point should suffice, but you have to do this after the filesystem has been mounted, otherwise you only affect the mount point, not the mounted filesystem. In Windows filesystems, particularly FAT32, you can add the option umask=002 to /etc/fstab to make all files user and group readable and writeable. Then use the uid and gid options to set ownership of all files in the filesystem. You can use numeric values here or user and group names, eg:

/dev/sda1 /mnt/somewhere vfat umask=002,uid=guest,gid=users 0 0

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar