Solving permission problems when using external EXT4 hard disk with multiple linux installs
I have an external hard drive and since I only use Ubuntu and Fedora I decide to format my hard drive to ext4 everything is fine.
The problem is when I mount the drive I need to change the permission so I can read and write.
What kind of permission should I use? adm my user name?
Solution 1:
The simplest solution is to make sure your Ubuntu & Fedora user accounts have the same user id (UID).
I think Fedora starts user accounts at 500 by default, while Debian & Ubuntu start them at 1000, so it's very likely that in one OS you are user number 500 and in the other you are user number 1000. The file system uses this UID number to keep track of permissions, so if you make sure they have the same UID, they will be considered the same user, and no permission issues will happen.
I think the best you can do is make them both UID = 1000, so change the UID in the Fedora system, then make sure all files on the external disk and in the user's $HOME in the Fedora install are owned by UID 1000. After that you should have no permission problems anymore.
Solution 2:
Lame though it may be of me, I'm going to have to answer the question with another question. If all we're talking about is for one OS, then it would be either
sudo chown -R (user name) /dev/(device name)
(ubuntu)
or just
chown -R (user name) /dev/(device name)
fedora - no sudo
, just run the command from root.
The noodle scratcher part, and the part I don't have any good answers for, is how to make it so you don't have to manually retype when you go back and forth between distros. I'd almost be tempted to add the line to my ~/.bashrc
, but there's probably a better way I don't know or haven't thought of yet.
Solution 3:
In /etc/fstab you could put uid=1000 (in Ubuntu -- it's 500 in Fedora) for the drive to be owned by your user (assuming you're the first user, yada yada yada... if not, your user's uid from id
) and umask=000 if you wanted all users to have access (or 077 for just the one specified by uid= -- it's a mask, so you put the opposite of what you'd chmod as)
For more info on using /etc/fstab: http://ubuntulinuxtipstricks.blogspot.com/2008/02/fun-with-etcfstab.html
Solution 4:
Unfortunately Linux kernel enforces POSIX permission on ext2/ext3/ext4 FS.
You may workaround POSIX permission with shared group. I ask corresponding question: https://unix.stackexchange.com/questions/273144/predefined-group-ids-across-linux-distros/ but after all I made own research.
I discover that sys group share id 3 on Debian, Ubuntu, RedHat, Fedora, CentOS, Suse, FreeBSD, OpenBSD, NetBSD, MacOSX, Solaris.
With such discover in mind one solution may look like:
$ sudo chgrp -R sys /mnt/data/dir
$ sudo chgmod -R g+s /mnt/data/dir
$ sudo fsetacl -R -m g:sys:rwx /mnt/data/dir
$ sudo fsetacl -R -d -m g:sys:rwx /mnt/data/dir
and flavor of this (whenever you on Linux/FreeBSD/MacOSX/Solaris):
$ sudo adduser user sys
See also:
- https://unix.stackexchange.com/questions/126213/external-hard-drive-permissions-ext4/
- How could I mount an ext4 partition and have write permission?
- https://serverfault.com/questions/306344/sharing-an-ext3-ext4-partition-on-external-drive/