2

In for example Thunar I can just click on an external USB drive to mount it under /run/media/$USER/[something]. The fact that the mount point is created dynamically is a great side effect. But for any drives which are on the SATA bus I'm told

mount: only root can do that

or

Not authorized to perform operation.

How do I configure internal drives to work like USB drives in this respect?

l0b0
  • 50,672
  • 41
  • 197
  • 360

3 Answers3

4

I found a workaround for mounting devices as a user. A static line in /etc/fstab permits to mount/umount without being root :

/dev/sdc1 /mnt/sdc1 auto defaults,user,rw,utf8,noauto,umask=000 0 2

If /dev/sdc1 device & /mnt/sdc1 directory both exist, running either mount /dev/sdc1 or mount /mnt/sdc1 will mount the device on the directory.

Note that this workaround is valid for any GNU/Linux distribution.

Adding the following to the /etc/nixos/configuration.nix will generate the above /etc/fstab-line for NixOS :

  fileSystems."/mnt/sdc1" = {
    device = "/dev/sdc1";
    fsType = "auto";
    options = [ "defaults" "user" "rw" "utf8" "noauto" "umask=000" ];
  };
ppom
  • 56
  • 1
  • 1
    One caveat to this is that the mount directory (`/mnt/sdc1` in this case) needs to be owned by the user in question. – l0b0 Nov 17 '21 at 10:08
3

I don't think you can mount internal devices as a normal user in Linux.

I had a similar problem, wanting to make an internal disk available to a normal user in NixOS. The answer How to auto mount / permanently mount external devices on NixOS explains how to do auto mounting by mounting manually as a superuser, and running nixos-generate-config and nixos-rebuild switch.

Then using chown user:group /my-mount-point I was able to permanently configure the disk to be available to my user. Hope it helps.

Mix
  • 31
  • 3
1

The accepted answer didn't succeed for me. It still asked for root password at login to mount.
But building on it, changing the options to the ones I had working in my manjaro system made it work.
Added this to my /etc/nixos/configuration.nix file:

  fileSystems."/mnt/DataDisk" = {
    device = "/dev/disk/by-label/DataDisk";
    fsType = "auto";
    options = [ "nosuid" "nodev" "nofail" "x-gvfs-show"];
  };

device = "/dev/disk/by-label/DataDisk" finds the disk with the label DataDisk fileSystems."/mnt/DataDisk" will create the folders /mnt & /mnt/DataDisk if they don't exist and mount it there

Then ran sudo nixos-rebuild switch

Yeshey
  • 11
  • 1