Fedora Server - External Hard Drive is mounted as root

Hello!

So first, as a normal user, I created a folder in the home directory. Then, I mounted my external hard drive to that folder (via the web dashboard). As soon as I mounted the drive, the permissions changed to root. And thus I can’t write and modify anything.

So far, I added an entry to /etc/fstab, which borked the whole OS somehow, since this put it in “emergency mode”.
Then I tried to change the permissions and ownership with “chmod” and “chown” command, but I always get “Operation denied” as a result.
On the web dashboard, I put “user” and/or “users” as mount options. But it did not help either.

Is there anything else I can do?

You first need to change the permissions on the mount point and the device mounted there. Then it should work. Do the following from the command line.

  1. sudo mount <device> /path/to/mountpoint

  2. sudo chown -R <your user:your group> /path/to/mountpoint
    If the device is not mounted when this command is run then ownership will revert to root when it is mounted.

  3. ls -ld /path/to/mountpoint

  4. ls -l /path/to/mountpoint
    Steps 3 & 4 are to confirm the chown properly worked.

  5. sudo umount /path/to/mountpoint
    this is to enable the test of the next step

  6. sudo mount -a
    This is to test the entry made in /etc/fstab and verify it will properly mount the device. Note that after doing step 2 you should need NO special options in the /etc/fstab entry. I use only defaults as the option on a device I mount as noted above. The fstab line should read something like UUID=xxxxxxx-xxxx-xxxx-xxxxxxxx /path/to/mountpoint ext4 defaults 0 0 with the UUID the actual UUID of the file system on that device and the filesystem type (field 3) the actual type of file system you are using. If you are using btrfs then the options (field 4) should be adjusted for that type file system.

  7. ls -l /path/to/mountpoint
    This is to confirm that the chown done in step 2 above remains active and that it is ready for use at the next reboot.

You must confirm the entry in fstab works properly (step 6) before you reboot to avoid a hang when rebooting.

1 Like

Thanks for the reply.

Unfortunately, I can’t get past point 2.
Executing this commands gives me the “Operation not permitted” error.

Did step 1 finish properly?
Make sure the device is not entered in /etc/fstab when you first start this process, since that might interfere.
The mount command should tell you if it is mounted and where.

Also note that the device cannot be mounted somewhere else when doing this. You may need to use the umount command before starting since fedora automatically mounts most external devices (especially usb connected) at /run/media/USER/DEVICE. The command would be sudo umount /run/media/USER/DEVICE if it is mounted there.

Yes, step 1 finished properly. I can view and read the contents of the drive.

I unmounted the drive, deleted the entry in /etc/fstab, restarted the server and made sure, that there is no entry after rebooting. Then repeated step 1. Step 2 gave me the same result.
Also checked /run/media/, but It’s empty. No user or device folder. Maybe it’s because I am using Server Edition.

Server edition does not have the media tools by default so it should not have the default mounting that is common in Workstation.

You said you can read the content of the drive with it mounted.
What is the output of ls -lZd /path/to/mount
Is it mounted under your home directory?
Is SELinux in enforcing or permissive mode? getenforce will give the current status.
What is the output of ls -lZ /path/to/mount
What is the output of mount | grep /path/to/mount

The output of the ls commands should tell you the ownership of the device and files. The selinux context if in enforcing mode may be what is preventing changes to ownership. Please post the ‘ls’ output so we can see what is happening there.

It is possible to temporarily disable enforcing for selinux with sudo setenforce 0 and then try the chown command to confirm if it is selinux blocking the command from functioning. If that works then the context for the device can be appropriately changed after it is mounted under /home/USER with the command sudo restorecon -r /home . A reboot after the restorecon command finishes, or the command sudo setenforce 1 will restore enforcing mode for selinux if needed.

drwxr-xr-x. 13 root root system_u:object_r:dosfs_t:s0 1048576 26. Sep 20:05 /home/cappeloblu/Elements/

drwxr-xr-x. 2 root root system_u:object_r:dosfs_t:s0 1048576 19. Jul 2018 ‘$RECYCLE.BIN’
drwxr-xr-x. 14 root root system_u:object_r:dosfs_t:s0 1048576 19. Jul 2018 Folder01
drwxr-xr-x. 3 root root system_u:object_r:dosfs_t:s0 1048576 19. Jul 2018 Folder02
drwxr-xr-x. 7 root root system_u:object_r:dosfs_t:s0 1048576 19. Jul 2018 Folder03
drwxr-xr-x. 9 root root system_u:object_r:dosfs_t:s0 1048576 25. Feb 2018 Folder04
drwxr-xr-x. 5 root root system_u:object_r:dosfs_t:s0 1048576 19. Jul 2018 ‘System Volume Information’

Didn’t give me any output.

Enforcing

Tried setting “setenforce 0” (Permissive), but still getting “Operation not permitted”.

Maybe the file system is the problem?

I tried another external hard drive with a ntfs file system. It has 777 permission out of the box. So no problems here.
To try it, I formatted it to both xfs and ext4. With xfs and ext4 file system defaults to 775 again.

That might indicate the problem.
What is the file system on that device? It seems it may be FAT, which would prevent ownership changes, though options in the mount from fstab could set ownership and group for your user and using a mask there would set permissions. Nothing else I am aware of can change the ownership nor permissions when mounting a vfat or ntfs file system.

If you are intending to use it as a commonly mounted file system and want to access it from both linux and windows the preferred file system is usually ntfs for larger devices though fat32 can be used for smaller devices as that is the default for many flash drives. If accessing it from linux only, then ext4 would be suggested. For an ext4 file system the steps I gave above will normally work. For ntfs or fat file systems they will probably not work.

Please provide the output of lsblk -f as well (you can limit that to only the device of concern if you wish)