Non-auto ownership of HDD's

Okay, because I change HDD’s often chown has become the bane of my existence. Any time a new hdd or reuse of an older that needs scrubbing or re-partitioning, ownership and permissions default to root. Is there a way to at least to have the system ask or have a flag for usergroup assignment?

i can see the utility of it being in root already but needing an option to tell it ether what the default is or give me the option. any clues other than having to use chown for every. single. hard. drive.

Insanity is doing the same thing expecting different results.
Madness is doing the same thing getting the same results knowing there has to be a better way.

https://superuser.com/questions/320415/mount-device-with-specific-user-rights

while neat it pretty much does the same as chown however it cuts somethings down as long as i dont reformat any of the drives ever or change uuids. (which i sometimes do).

So i suppose i should clarify even further. When the System see’s a new drive and i have started the process towards mounting (because it needs to be formatted or because i just need to mount a newly partitioned drive).
is there a way for one of the following options:

  1. Set default ownership and permissions for new drives
  2. Be given the option during first mount after partition

What i am not looking for is to repeat the instructions over and over and over, for. every. single. drive. every. single. time. something. needs. to. change.
after awhile of doing that process over and over you start to pray that the joker comes out of nowhere and shows you the disappearing pencil trick.

AFAIK an unknown partition works the same way as an USB drive : it is not mounted by default, and can be mounted by any user afterwards to /run/media/{user}/{label}, that directory being created on the fly and granted ownership to the user.
If you want it mounted at boot, you need to define it in fstab/systemd as well as its mount point. It is mounted by root, so you do need to take ownership of the directory used as mount point. But then, if you change the associated partition, you may only need to update its UUID in fstab/systemd so it mounts to the same point, keeping the previous ownership.

So currently, i fail to see how you need to reset ownership every time…

For USB-devices this is automatically done. But if you want to partition it, maybe you could use gparted.

everyone is making the assumption somehow that the same HDD is being used…

So where not talking 2 or 3 drives…

okay, will deal this this first, i never said auto mount, i was talking about auto/default ownership of drive too root not user. So the issue isnt the rest its the fact that ANY harddrive that gets pluged in starts as owned by root before mount or by anyother means… THAT NEEDS TO STOP! or Grant POLICY to KEEP IT FROM HAPPENING.

Just checking : how do you mount your partitions?

well first it has to be formatted/partitioned, otherwise root wont let it mount especailly if it is blank or unknown space. then it can be mounted from any three locations terminal, Hard Disk Icon (greyed out and visable at this point), gparted, however root still has control. Then i chown (while thats not the only way, for repeate drives the link Tomek provided works well half of the time, assuming i dont make more work for myself based on need.).

Which command do you use?

Can you be more specific?

  1. sudo man mount /dev/sdxN -path
  2. Open up “Home” folder and on the left you should see under devices Hard disk drives.

x is for standard drive lettering, N for numbers.

Did you thought about writing script? This script should have at least those tasks:

  1. list all partitions (for example with ls /dev/sd[a-z][0-9]
  2. test if partition is mounted
  3. if not then mount to your desired location (standardized names should be ok for example ~/mounts/sdxN - directory should be created if not exist)
  4. chmod/chown on mounted partitions

Alright.

First a reminder about permissions. Even if, depending on the way used, superuser privileges are required to mount a partition, what makes a user (un)able to write in a mounted partition is the permissions and ownership of the mount point. Once you set the ownership of a mount point, it will stay that way no matter which partition you mount there. So, even if you redo a partition, if you wish to mount the new partition to the same mount point, not only you can, but you’ll also keep its permissions.

AFAIK the mount command does not create the mount point if it does not exist, so you need to create it beforehand. If you need to reset the permissions every time, it means you either also define new mount points every time, or you choose an ephemeral mount point (such as in /tmp for instance). Furthermore, if you create that mount point in a system directory (outside /home/{user}), you do need superuser privileges for that, and thus the directory is automatically owned by root. You can very well create a mount point in your home folder, in which case your current user will automatically gain ownership.

When mounting a partition through Thunar (your file manager), it should mount it to a folder in /run/media as i explained previously, so you should have ownership on it this way.

Gparted does require superuser privileges to run. I am not familiar with it mounting partitions to not-pre-defined points, but if it creates the points on the fly, it will obviously do so as root, thus giving it ownership.

You didn’t specify how you (regularly) partition your drives. In the case the result is overall still the same – like always the same number for the same uses – you can very well create mount points you can reuse even if you change those partitions. Know that the ways to automount a partition also allow to simply associate a partition to a mount point without automounting. This way, you are not required to reset everything each time you want to mount one, and can simply edit the configuration when you change a partition.

1 Like

Embarasingly; I thought about it, then realised i could only vaguely understand what i was reading. Then realised there are other aspects that all i can do is say huh? ie i paniced

largely irrelevent… okay context over the last week my computer has had 300 HDD’s go through it (5 at a time). Now if the drives wouldnt automatically have there ownership and permissions set to root, that would save me alot of time.

Again, the ownership and permissions are on the mount point, not the drive. I don’t know your use case, but if you always mount your drives to the same 5 mount points, which you gave ownership to your user, you shouldn’t have trouble.

1 Like

just in case im not being super duper clear: pre chown, pre doing anything to it

again the moment the drive is plugged in and the system detects it (and no im not talking hotswapping, normal proceedures just incase someone asks), permissions and ownership goes to root, reguardless of mounted state.

Please detail.
I think we’re not talking about the same thing.

1 Like

thats really direct there really isnt anything else reguarding a hard drive that i could be referencing in reguards to Ownership and Permissions that are set/given to group(user) known as root. Im going to take a 30 minute break, because i almost broke the rules.

The thing is : drives and partitions have no ownership or permissions in Linux. Files, and by extension folders, have.
So it would really enlighten us to know what you mean by ownership/permissions for a drive.

2 Likes