LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   USB ext3 HDD permissions problem (https://www.linuxquestions.org/questions/linux-software-2/usb-ext3-hdd-permissions-problem-565607/)

tredegar 06-30-2007 09:07 AM

USB ext3 HDD permissions problem
 
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?

I'm running kubuntu 6.06.1, kernel 2.6.15-28-386.

Any ideas?

dracolich 06-30-2007 09:48 AM

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.

rednuht 06-30-2007 09:55 AM

/etc/fstab
add user i.e.
Code:

/dev/sda1              /media/sda1      auto            noauto,user    0 0

tredegar 06-30-2007 10:21 AM

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.

dracolich 06-30-2007 11:24 AM

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

sudo /sbin/chown -R tredegar:users /dev/sda1/*
sudo /sbin/chmod -R 755 /dev/sda1/*

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.

tredegar 06-30-2007 12:02 PM

Quote:

sudo /sbin/chown -R tredegar:users /dev/sda1/*
sudo /sbin/chmod -R 755 /dev/sda1/*
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?

dracolich 06-30-2007 02:57 PM

Quote:

sudo /sbin/chown -R tredegar:users /dev/sda1/*
sudo /sbin/chmod -R 755 /dev/sda1/*
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.

tredegar 07-01-2007 06:35 AM

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.

tredegar 07-01-2007 07:09 AM

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.


All times are GMT -5. The time now is 01:33 AM.