You are not logged in.

#1 2020-05-07 12:07:59

LtZerouk
Member
From: Switzerland
Registered: 2020-05-02
Posts: 13

[Solved]Ownership and permission when mounting disk

Hi,
I have some trouble understanding what option I need to specify in fstab to automatically mount my second ssd on startup, so that I can read, write and execute things without being root (partition is ext4). I tried this but it doesn't work:

# /dev/sda1
UUID=48dfd59a-d046-4401-a58b-39989434bf3a       /drive/SSD1     ext4            defaults,uid=1000,gid=985        0 0

Last edited by LtZerouk (2020-05-07 14:24:28)

Offline

#2 2020-05-07 12:16:08

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,771

Re: [Solved]Ownership and permission when mounting disk

On an ext4 file system the permissions are stored on the file system, chown the directory you want to be able to manipulate to your user. What you pass in on the mount command has little relevance.

Last edited by V1del (2020-05-07 12:17:15)

Offline

#3 2020-05-07 12:31:53

LtZerouk
Member
From: Switzerland
Registered: 2020-05-02
Posts: 13

Re: [Solved]Ownership and permission when mounting disk

I made that but as soon as I mount the drive the directory changes to root ownership. re- chown the directory then doesn't make anything. It keeps the ownership to root.
Or do I need to first create an directoy inside the drive and then change the ownership to me ? If yes, why is that so ? Why can't I change the ownership of the drive to me ?

Offline

#4 2020-05-07 12:51:24

LtZerouk
Member
From: Switzerland
Registered: 2020-05-02
Posts: 13

Re: [Solved]Ownership and permission when mounting disk

Wait. Just realized that after creating the folder in my new drive it changed ownership. Why does it change only once I create a folder in my drive?

Offline

#5 2020-05-07 12:57:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,556
Website

Re: [Solved]Ownership and permission when mounting disk

Please be specific.  Post commands and their results that led you to the statements above.

I suspect what you are seeing is the directory on the host system, /drive/SSD1, is owned by root.  This is independent of what is mounted there, then anything mounted under that mount point can have other ownership, but the enclosing directory is still owned by root.  If this is the case, you need to appropriately chown or chmod /drive/SSD1 before you mount the other drive.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2020-05-07 13:33:16

LtZerouk
Member
From: Switzerland
Registered: 2020-05-02
Posts: 13

Re: [Solved]Ownership and permission when mounting disk

What I did is create /drive/SSD1 (and also 2 other folder in /drive to mount 2 other drive) with mkdir then

sudo chown -R user:users /drive

and after verifying they belonged to me. Then formated my drive with

sudo mkfs.ext4 -L SSD1 /dev/sda1

and added the drive to the fstab file (with just the defaults options) (acctually for the 3 of them) and mounted my drives with

sudo mount -a

. At that point I tried to acces the drive to put  some files (photos, documents, etc.) by creating a folder (using dolphin) and the option to create something was geyed out. I checked the properties of my drive and showed it was owned by root. Tried to change it with

sudo chown user:users /drive/SSD1

and

sudo chown user:users /dev/sda1

. Also unmounted the drive and redid the last two command in case but as expected didn't work. When unmounted the mounting folder reverted back to be owned by me. Searched a bit on the forum, wiki and google but didn't really understand/find a solution and then tried what I told in the first post.
After that, reverted the fstab file to only defaults for the options and retried the chown in case I did something wrong in the first place and then I created a test folder like that

sudo mkdir /drive/SSD1/test
sudo chown user:users /drive/SSD1/test. 

As expected the folder was owned by me. At that point I posted reply #3.
A bit later for no particular reason, I checked back with Dolphin the properties of the drive and saw that now I own the drive.
Remade a test folder in my second drive I just mounted to test if this was what triggered the change, and it did.
Now I'm wondering why do I have to first create a folder in my drive to change the ownership of the drive (Note: there was the default lost+found folder in the drives and it changed ownership with the drive).
There's not really any output apart from the error when I tried to mount with the option like shown in post #1

Offline

#7 2020-05-07 14:09:44

seth
Member
Registered: 2012-09-03
Posts: 51,655

Re: [Solved]Ownership and permission when mounting disk

V1del wrote:

On an ext4 file system the permissions are stored on the file system

sudo chown -R user:users /drive

What you do to the unmounted path is irrelevant.

sudo mount -a
sudo chown user:users /drive/SSD1

This handed the root directory of the drive to your user.

sudo chown user:users /dev/sda1

This is between stupid and dangerous - a place where you don't want to be. Don't do that.

To repeat:

V1del wrote:

On an ext4 file system the permissions are stored on the file system

You have the same control over file ownership like you have on eg. the root or /home partition.
It is only for "filesystems" like FAT where the ownership/permissions must be controlled by mount process and iirc. for NTFS you can opt for that (though NTFS can manage file permissions)

Offline

#8 2020-05-07 14:24:06

LtZerouk
Member
From: Switzerland
Registered: 2020-05-02
Posts: 13

Re: [Solved]Ownership and permission when mounting disk

Ah now I get it. Made a quick google search for permission and ownership filesystem.Thanks.

Offline

#9 2020-05-07 14:25:40

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,556
Website

Re: [Solved]Ownership and permission when mounting disk

seth wrote:

What you do to the unmounted path is irrelevant.

Except that it was my suggestion to mod the unmounted path as the symptoms - initially - sounded like potentially not having read access to the containing folder.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB