Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I just bought a nice little 120MB USB External 2.5" HDD. It came formatted as NTFS, so I repartitioned it and formatted it as ext3.
When I plug it in, it spins up, is recognised and mounted, and I can open it as /media/sda1
The problem is that o:g and permissions for /media/sda1 are root:root and 755, so I cannot write to it unless I change the permissions (every time I mount it).
When I plug in my usb memory stick (which is currently formatted as vfat), it is mounted as /media/sdb1, but its o:g and permissions are tredegar:tredegar 700, so I can do as I please with it.
I thought that all this was managed by udev but grep 755 /etc/udev/rules.d/* returns nothing.
So my question is: Why is the HDD getting different permissions and where should I look to change this?
The difference in permissions is due to the fs more than the device. Look in /etc/fstab for the line that defines it and set the permissions there with gid and umask options. You can also use chown and chmod if you want to change only certain files/directories.
Thanks for the suggestions, but /etc/fstab has nothing referring to /dev/sd?? (yes, I did plug it in, and it was mounted when I checked fstab) and I do not want to make an entry there as the USB HDD will not always be /dev/sda1 - this depends on what else I have plugged in.
The USB HDD is being mounted dynamically by some script somewhere (called by udev or hal I suspect), but I cannot find it.
Once the HDD is mounted, I can change the permissions for /media/whateveritis, but this is a pain, and the memory stick is mounted with the correct permissions, and I am puzzled by why these two devices are being treated differently.
Memory sticks and other flash memory cards use a FAT filesystem. FAT didn't have a permissions system like NTFS and EXT. Since your using EXT3 your best option will probably be to change file/directory ownership and permissions with chown and chmod. Something like
You only have to do this once, or whenever you need to change some permissions because the changes will remain between mounts as they're part of the filesystem. The editing of fstab and using umask options is better suited for when mounting FAT devices.
No, sorry, but this does not help.
The device nodes /dev/sda and /dev/sda1 are created on-the-fly when the HDD is plugged in. They are given o:g of root:plugdev and permissions of 660. These nodes disappear when the HDD is unplugged. This is all well & good & proper.
Something is creating the mountpoint /media/sda1 and is giving it o:g of root:root and permissions of 755. /dev/sda1 is then mounted at /media/sda1. Something is deleting this mountpoint when the HDD is unplugged. Again, all well and good & proper.
But I cannot, as a regular user, write to the disk at all, without changing the permissions on /media/sda1 because they are wrong (only root can write to the drive).
What I need to find out is what is allocating ownership and permissions to the mountpoint /media/sda1. It is the mountpoint that is being given the wrong permissions. As I said in my OP, I thought that this was handled by udev, but it seems it is not. So what is handling this, and why is the USB flash stick handled differently?
Fingers faster than the brain. That's supposed to be /mnt/sda1/* or /media/sda1/*
Quote:
It is the mountpoint that is being given the wrong permissions. As I said in my OP, I thought that this was handled by udev, but it seems it is not.
It's the HAL and DBUS stuff that creates the /media directories and automounts the device. udev determines the names and permissions of the device nodes, not the mountpoints. It's correct for the /media/sda1 directory to be root:root with 755 permissions. In your OP you mentioned your external disk is formatted as EXT3. Unlike vfat, it doesn't inherit the permissions of the mountpoint because each individual file and directory can have it's own ownership and permissions. As the above-corrected commands indicate, /media/sda1/* will tell the command to change the ownership or permissions of everything under the /media/sda1 directory, which means everything that's on the mounted disk.
Thanks for your suggestions.
To complicate matters, today (after a reboot) it is working properly:
I plugged in the USB HDD, and it was mounted at /media/sda1 with o:g of root:root and permissions of 777 (yesterday it was 700), so I can use it.
I wish I understood how all this is being handled, as I have not changed any udev.rules, only read through them.
At some stage yesterday, I did chmod 777 /media/sda1, which enabled me to access the drive, but I did not expect this to survive a reboot or unplugging of the device, as /media/sda1 is created only when the HDD is plugged in, and removed when it is unplugged. Curioser & curioser, but now it is working.
An update: Maybe I am just being too impatient
If I monitor the directory /media/ when I plug in the HDD it first appears as /media/sda1 o:g root:root perms 755. A few seconds later, if I refresh my file browser view, it has changed to perms of 777. So I just have to wait a little longer for HAL, dbus and udev sort themselves all out, which thet do, eventually.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.