0

I encountered an issue with a disk drive which I already posted on. (For the curious: Issue with device after formatting)

In short, one of my disks stopped allowing me to copy files by drag and drop using Dolphin (Debian), and allowed me only if I was doing it from the terminal using sudo.

I researched about my issue and noticed something:

  • This has already happened to me with another disk drive.

  • That disk drive and this one were erased with dd if=/dev/zero of=/dev/sdX where sdX is the drive in question

  • It did not happen with other disk drives which were not erased with dd but only formatted (with mkfs) and/or partitioned (e.g. gpt partition created with multiple primary partitions).

  • In that disk and this one, the owner was changed to root, and no longer user.

So my questions are:

  • Why did this happen with fully erased disks and not with formatted or partitioned disks?

  • How do permissions work exactly? Are they written into the disks? Or is ownership written into the disk?

  • Is it possible to change the owner of the disk so that the change is persistent across Linux distributions?

Edit: I tried to format the disk with exfat. Drap and drop with Dolphin works and the ownership is changed to user. I tried to format the disk with ext4. Drag and drop does not work anymore. The ownership was changed to root. I tried to change the ownership of the disk drive to the current user. The command line exited without issue (terminal: sudo chown ...: /dev/sdX -R -w). However, when using it with Dolphin, drag and drop does not work. Dolphin still lists ownership as root. If manually mounted from terminal, the directory created for mounting will only show ownership as root (even though the directory was created without requiring sudo). If automatically mounted from Dolphin, it will also only show ownership as root. Mount point name changes between two automatic mountings by Dolphin.

I should also add that I did format other drives with ext* filesystems. There are no issues with them (even with ext4) as long as I did not run dd if=... of=... on them (to erase them completely).

Can you explain to me what is going on?

Why does it seemingly show that ext* format automatically makes root the owner and the exfat format not? Both commands were run using mkfs.

Edit: Forgot to write that I use Debian.

3
  • You can control ownership and permissions for each directory and file with chown and chmod with Linux file systems. But with Microsoft file systems in Linux, ownership and permissions are set when mounting the file system and applies to all directories and files in it. So with an ext4 file system you can set the ownership and or permissions of the top directory of the file system to fit your purpose, or you can create subdirectories with ownership and or permissions to fit your purposes.
    – sudodus
    Jul 18, 2021 at 18:21
  • Thank you for your explanation. However, it does not explain why after running the command chown to change ownership, Dolphin would still not let me drag and drop. (I edited my post for clarity.) Why?
    – Atome
    Jul 18, 2021 at 18:23
  • Please run ls -l "ell ess space minus ell" to show files and directories involved in your copying and edit the original question to show the result. Indent each lone of the output by 4 spaces to render it as code, and it will help me and others to help you.
    – sudodus
    Jul 18, 2021 at 18:31

1 Answer 1

1

When a drive (or partition, or other block device, or a disk image file, etc) is formatted, the top-level directory of the filesystem is owned by the user running the mkfs command.

Usually, that is root unless you're formatting a disk image file (or a block device you happen to have RW perms on) as a non-root uid.

If you want to change the ownership, mount it and then chown the mounted directory. This will change the ownership of that top-level directory in the formatted fs itself, so the ownership change will persist after unmounting. For example (as root):

mkfs.ext4 /dev/sdaX
mount /dev/sdaX /mnt
chown user:group /mnt

This has to be done while the fs is mounted, otherwise it will only change the owner of the mount-point itself (i.e. the directory in the parent filesystem), and this will be over-ridden by the owner in the mounted filesystem when you mount it.

For example, /mnt is just a directory in / until you mount another filesystem on it. It has whatever ownership and perms that are set for it in the / fs. When you mount another fs on /mnt, it now has whatever ownership and permissions are set for the top-level directory of that filesystem.

FAT is not a unix filesystem and does not support unix ownership or permissions. When you mount a FAT filesystem, you specify the ownership and permissions of all files in the fs when you mount it (default is the uid & gid of the the mounting process).


Note that mkfs for some filesystems allow you to specify the owner when formatting but, because each such fs has its own method of doing that, it's generally easier just to chown it after mounting it for the first time (as shown above), and not have to remember a minor convenience feature of a rarely-used tool. e.g. mkfs.ext4 does this with an extended option (-E):

mkfs.ext4 -E root_owner=uid:gid /dev/sdaX

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.