LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   User auto mount USB stick (with ext3 partition) (https://www.linuxquestions.org/questions/linux-hardware-18/user-auto-mount-usb-stick-with-ext3-partition-681160/)

tonyfreeman 11-04-2008 05:47 PM

User auto mount USB stick (with ext3 partition)
 
I have a USB stick that has an ext3 partition. When I place the stick into the the USB port the system recognizes the stick and automatically mounts the drive ... but I do not have access to write to it! I can read and navigate the drive but not write to it.

When I put a USB stick with a vfat32 partition in, the system mounts it AND there is enough permission for me to read, write and execute from this newly mounted drive.

How can I re-configure the system to mount the ext3 USB drive so that a common user can have read,write,execute?

I've been looking at /etc/hal and /etc/udev with no luck! What am I missing? Please help!

-- Tony

jschiwal 11-04-2008 06:09 PM

If you use the ext2 or ext3 filesystems, you use chown, chgrp and chmod. Mount the filesystem first and then change the ownership and permissions of the filesystem. If you are the only one using it, the apply the same permissions as your home directory. If you want any regular user to read and write to it, use the same permissions that the /tmp directory uses: E.G. chmod ugo=rwxt </mount/point>.

Since this is a USB stick, you might want to use ext2 instead. A journaled filesystem will increase the number of writes to the device. A flash device has a limited number of writes. Also mount it with the noatime option to prevent updating the access timestamps.

tonyfreeman 11-04-2008 07:16 PM

tried chmod et al
 
Thanks for the reply, but I have tried doing just that.

When the machine auto mounts the drive, it mounts it to a newly created directory in the /media/ directory. If the ext3 label on the USB stick is 'memorex' then the system automatically creates a /media/memorex directory ... it then removes that directory when the USB stick is unmounted. I have several USB sticks with different ext3 labels.

It would be nice if I could tell the system to auto mount these things with enough permissions for the user to actually use the device.

-- Tony

jschiwal 11-06-2008 03:08 AM

Firstly, if the filesystem is mounted, you will be changing the permissions on the filesystem and not the mountpoint. Even if it were mounted on /mnt/memorex, after unmounting the /mnt/memorex mount point would return to root ownership. After mounting it would indicate the user who owns the filesystem. If more than one person will use it, then create a group and make the users members of that group. Use chgrp on the filesystem "chgrp -R memorexusers /media/memorex"; "chmod -R g+rwx /media/memorex". Another option is to allow permissions to "others" if you want anyone to be able to use it.

Also keep in mind that users and groups are aliases for integer numbers (UID & GID). If you use this pendrive on another computer and your user number is 500 on one computer, the user with a UID of 500 will be able to access it on a different computer.

The automounting system will change options during mounting but won't chown the files and directories in an ext3 partition.

tonyfreeman 11-08-2008 09:01 AM

Auto Mount ext3 USB with enough permission for user to rwx
 
Thanks but ...

Somehow the system is AUTOMATICALLY creating the mount point in /media/ and mounting the device when it is plugged in. After the device is unmounted the mount point is removed as well. I use the GNOME desktop.

The only static directories in /media/ are: cdrom0 and floppy0 with cdrom and floppy sym links.

I have a 12 gig USB disk with two partitions. One is vfat32 (2 gigs) and the other is ext3 (10 gigs). When I plug this into the machine ... somehow via udev or hal or some other daemon I don't know about yet ... there is an automatic creation of a directory in /media/ that is the same as the partition label on the file system.

The ext3 label on my USB disk is 'memorex'. The label on the vfat side is 'fat32'. The system AUTOMATICALLY creates the /media/memorex directory and /media/fat32 directory and mounts the partitions.

Here is what the system looks like permission wise after things are AUTOMATICALLY done by the system:

Code:

lrwxrwxrwx 1 root root      6 2008-11-03 22:02 cdrom -> cdrom0
drwxr-xr-x 2 root root    4096 2008-11-03 22:02 cdrom0
drwxr-xr-x 2 tony  200    8192 1969-12-31 19:00 fat32
lrwxrwxrwx 1 root root      7 2008-11-03 22:02 floppy -> floppy0
drwxr-xr-x 2 root root    4096 2008-11-03 22:02 floppy0
drwxr-xr-x 3 root  200    4096 2008-11-04 23:05 memorex

See how the system mounted the vfat partition with my user credential! Why did the system not do the same for the ext3 partition (memorex)?

See the GID of 200 ... I would add a group with the ID of 200 and then assign myself to that group but it would not do any good due to the permissions being assigned.

This is what the /media/ directory looks like after I unmount (by clicking on the desktop icon in GNOME and selecting "Unmount Volumn":

Code:

lrwxrwxrwx 1 root root      6 2008-11-03 22:02 cdrom -> cdrom0
drwxr-xr-x 2 root root    4096 2008-11-03 22:02 cdrom0
lrwxrwxrwx 1 root root      7 2008-11-03 22:02 floppy -> floppy0
drwxr-xr-x 2 root root    4096 2008-11-03 22:02 floppy0

I would like to configure whatever daemon is running (hal, udev, etc) to mount the ext3 partition with the user credential so that I don't have to 'fix' things as root if I need to use a friend's USB stick with ext3 file system and unique label.

I've been doing a lot of research with udev ... but I cannot figure out where the file permission stuff is coming into play. I'll keep trying but if anyone should know any more information, please respond!

-- Tony

jschiwal 11-09-2008 02:12 AM

Udev, Hal, dbus and the desktop work together. Hal identifies the hardware. Udev creates the device nodes and its rules determine the permissions of the device. Hal communicates with the desktop via dbus that an external device is plugged in. Some distro's also use PolicyKit to determine if the user is allowed to mount the device. It makes distinctions between a local and remote user for example. Besides a device node such as /dev/sdb2, udevd also creates symbolic links to these devices such as /dev/disk/by-label/memorex.

What I still don't think you are getting is that for an ext3 partition, the ownership, group ownership and permissions are contained on the filesystem. They will show up on the mount point when the filesystem is mounted. For a fat32 filesystem, which is very common for pen drives and external hard drives, the permissions are determined when a device is mounted, so this can be done during the auto mounting process.

For an ext3 partition, use chmod and chown to change the ownership. Do this when it is mounted. If you need to, mount it manually on /mnt and then run:
sudo chown -R tony:tony /mnt/memorex
chmod ug=rwx /mnt/memorex

If you already have files and directories in the filesystem, you can change them as well.
find /mnt/memorex -type d -exec chmod ug=rwx '{}' \;
After changing the ownership and permissions on the mounted filesystem, the next time you connect the device, you should see your username as the owner.

On my distro, if you create an entry in /etc/fstab to mount an external drive, then udev/hal won't mount it on /media.

/media/floppy & /media/cdrom are different from an external usb device because the devices are always present but the media isn't. The format of the media may change as well. A dvd drive may contain a cdrom, a dvd or an audio cd, or blank media. An audio CD doesn't contain a filesystem. Neither does blank media. If HAL tells the desktop environment (KDE or Gnome) that blank media is detected, the desktop may present you with the option to run burning software such as k3b.


All times are GMT -5. The time now is 09:12 PM.