Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
user write to mounted USB disk
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 980

PostPosted: Wed Mar 12, 2014 1:45 am    Post subject: user write to mounted USB disk Reply with quote

My user can mount a USB disk but I can't write to it. I'm in the plugdev and usb groups. What am I missing?
Back to top
View user's profile Send private message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 305
Location: Cape Town, South Africa

PostPosted: Wed Mar 12, 2014 7:39 am    Post subject: Reply with quote

Assuming it's a vfat or ntfs file system, look at the mount options for the file system being mounted (man mount.<fstype>, or just man mount). You will need to pass mount the options to set default permissions on the file system, because the underlying file system itself doesn't use POSIX permissions. For ntfs the specific options are uid, gid and umask. For (v)fat llok at uid, gid, dmask and fmask. Note that the masks are umask, so they are the inversion of the bits you actually want.

As an example

Code:
$ mount -t vfat -o uid=1,gid=<plugdev uid>,dmask=0002,fmask=0113 /dev/sdb1 /mnt/usbdrv

_________________
Adopt an unanswered post today
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 980

PostPosted: Wed Mar 12, 2014 11:09 am    Post subject: Reply with quote

It's actually ext4 without journaling.
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 980

PostPosted: Wed Mar 12, 2014 8:54 pm    Post subject: Reply with quote

Is NTFS the right choice for a removable device like a USB stick or USB SSD?
Back to top
View user's profile Send private message
Anon-E-moose
Advocate
Advocate


Joined: 23 May 2008
Posts: 3690
Location: Dallas area

PostPosted: Wed Mar 12, 2014 8:57 pm    Post subject: Reply with quote

I think that most usb sticks come preformatted with fat/vfat.

As to what you want to format it with, it depends on what you want to use it for.

Edit to add: for portability between linux and windows I leave it as some version of fat.
If I want it strictly for linux then some versions of ext is fine.
_________________
Asus m5a99fx, FX 8320 - nouveau & radeon, oss4
Acer laptop E5-575, i3-7100u - i965, alsa
---both---
4.14.62 kernel, profile 17.0 (no-pie) amd64-no-multilib
gcc 7.3.0, eudev, openrc, openbox, palemoon
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 980

PostPosted: Thu Mar 13, 2014 12:22 am    Post subject: Reply with quote

The problem I'm running into is moving the USB stick between my and my wife's laptop. It's formatted with ext4 and I'm running into permissions problems.

EDIT: Is that the expected behavior? I would think whoever mounts the USB stick is meant to have access to its contents but that's not what I'm finding at all.
Back to top
View user's profile Send private message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 305
Location: Cape Town, South Africa

PostPosted: Thu Mar 13, 2014 8:20 am    Post subject: Reply with quote

A lot depends on how you are mounting it. If you are mounting it from a GUI utility, or it's mounted automatically on insertion, then ownership of the file system could be set to something other than root. But if it's mounted automatically, who is the mounter. If it's mounted via a GUI utility, is it meant to be mounted for only that user to use? What about other users? What I'm trying to get at here, is that it's a complicated problem. The standard, as in what the mount command does at the command line when executed as root, is always to have the device and file system root owned unless otherwise specified.

Then your other questions, which I'll deal with before continuing, because my comments lead on to what comes next.

ext4 is a good choice if you are not ever going to use the stick on windows or even mac. Windows can't read extX systems without 3rd party drivers, so for compatibility I find extX a bad choice for USB sticks. Regarding FAT vs NTFS, FAT is the only file system that is both readable and writeable on windows, mac, and linux. NTFS is rw on windows and linux, but mac doesn't like it. That said, FAT has some distinct disadvantages on larger drives (8Gb and up). Firstly, you lose a lot of space to the file allocation table. NTFS you lose less space. Secondly, I've found that FAT on USB sticks is much slower than NTFS. I think this has to do with NTFS having a write buffer, so the *actual* write speed isn't different, but for copying lots of small files, NTFS doesn't have to sync between files... I'm kinda guessing here, and this problem may have long since been fixed in windows. I don't use windows on a day to day basis, so I'm not sure. Some testing might be in order.

Finally, we get to your specific problem. When you mount a file system it is expected to conform to a POSIX permission scheme, or at least, it's going to be treated as if it does. Obviously, NTFS and FAT don't have the same permissions structure. When the permissions structures don't match, the kernel looks at what permissions are there that match the POSIX ones. In the case of FAT/NTFS this is none. For the missing permissions, it assumes no permission has been granted, again, unless otherwise specified. This works well for a flash drive being moved around between machines. Files and directories under NTFS don't have owners or groups, and only have a read-only setting that matches POSIX, which is treat as owner-write permission. So if you write a file as bob on linux-machine-1 and move the drive to linux-machine-2, where you log in as bob, but your UID is different, it doesn't matter, because your file isn't owned by bob. It isn't owned by anyone on the file system, but the kernel on both machines treats the files as owned but root, group root, readable, and possibly writeable by root. Of course, with some mount options, you can change this to be owner=bob, group=users, rw-rw----

But if the files ystem is ext4, and you create file on it on linux-machine-1 as bob (uid=1000), group users (gid=100), permission rw-r----- then move the drive to linux-machine-2 and mount the drive, then the file you created is still going to be owned by UID=1000, group=100, and will have the same permissions. But on the other machine, UID=1000 might not be bob. It might not even exist. Which means bob on the second machine can't read his 'own' file, because his UID is now 1005 or something. There are ways around this, using setgid and posix acls, which I can go into if you want, but they're complex to implement after there's already stuff on the drive.

The thing you need to do, is check the permissions on the device itself, the root directory of the file system after it's mounted, and compare permissions and ownership of file created on the linux machine and the windows machine. There's you'll see clues as to what's getting mangled.
_________________
Adopt an unanswered post today
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 980

PostPosted: Thu Mar 13, 2014 1:27 pm    Post subject: Reply with quote

I'm actually not dealing with any Windows or Mac machines. 100% Gentoo. :) If I want the USB stick to be used across multiple Gentoo machines, I should make sure its root directory is readable and writable by everyone?
Back to top
View user's profile Send private message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 305
Location: Cape Town, South Africa

PostPosted: Thu Mar 13, 2014 2:03 pm    Post subject: Reply with quote

Okay, then the thing to do is to USE set gid and acls

First, add "acl" to your USE flags in your /etc/portage/make.conf, and then do the following, changing <whatever> and <wherever> to your device node and mount point appropriately

Code:
# update everything to use acls
$ emerge -uNDav @world

# install the acl utliities
$ emerge -u1 sys-apps/acl

# mount your usb drive turning acls on the file system on
$ mount -t ext4 -o acl /dev/sd<whatever> /mnt/<wherever>

#Modify the permissions on the root of the file system
#   we have to be 'inside' the mounted file system to change the root of the FS,
#   instead of being outside (in /mnt for example) where we are making temporary modifications to the mount point dir
$ cd /mnt/<whereever>
$ chown . root:plugdev
$ chmod g+s .

$ for d in `find . -type d`; do chmod g+s $d; setfacl -d -m u::rwx,g::rwx,o::rx; done
$ cd ..
$ chown -R root:plugdev <whereever>
$ chmod -R g+rwX <wherever>


After this, anyone in the plugdev group will be able to read and write any file or directory on the drive by default. It works like this. Setting setgid on a directory means that any file of directory newly created within that directory will inherit the group of the parent directory. It does nothing to permissions though, which is where ACLs come in. With ACLs we can set default permissions on things, in a similar way. If we set default permissions on a directory, then anything created inside that directory will get the parent directory's default permissions by default. This way, using setgid we can make newly created files and directories have the plugdev group by default, and using default ACLs, make give group read and write permissions to the newly created object, thus giving anyone in the plugdev group the ability to read and write existing files/directories and to create new files/directories that are readable and writeable by everyone else in the plugdev group without hassle. Note that user ownership of the files still works the same way as normal, but it no longer stops plugdev users from working with the files.
_________________
Adopt an unanswered post today
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 980

PostPosted: Thu Mar 13, 2014 2:12 pm    Post subject: Reply with quote

Wouldn't it be easier to just set permissions for everyone to read and write the root of the USB stick?
Back to top
View user's profile Send private message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 305
Location: Cape Town, South Africa

PostPosted: Thu Mar 13, 2014 2:28 pm    Post subject: Reply with quote

Those permissions won't carry to subdirectories if any, nor to newly created files, even in the root directory. Subdirectories when created are created according to a users umask by default, and with ownership according to the user and the user's primary gid.
_________________
Adopt an unanswered post today
Back to top
View user's profile Send private message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 305
Location: Cape Town, South Africa

PostPosted: Thu Mar 13, 2014 2:36 pm    Post subject: Reply with quote

Oh, I forgot to mention. The long rigmarole above only needs to be done once. After that just mount the device with -o acl, and it'll 'just work'... hopefully ;)
_________________
Adopt an unanswered post today
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 980

PostPosted: Thu Mar 13, 2014 3:42 pm    Post subject: Reply with quote

Thank you sirlark. Although it saddens me, I'll probably just use NTFS. I'd rather not deal with the extra ACL layer. Is there a Linux filesystem that would work this way without ACLs?
Back to top
View user's profile Send private message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 305
Location: Cape Town, South Africa

PostPosted: Thu Mar 13, 2014 4:35 pm    Post subject: Reply with quote

If by 'linuux filesytem' you mean 'using POSIX permisions', then no, sorry. That's kind of the cause of the problem. If you just generally mean a filesysttem linux can use, then FAT or NTFS are tthe answer. maybe BTRFS can do fancy things, but I don't know off hand.
_________________
Adopt an unanswered post today
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum