Linux – What command does nemo use to mount drives

automountinglinux-mintmountnemo

I use Linux Mint Cinnamon. I'd like to know what command does nemo use to mount drives when you click on an unmounted drive on the explorer sidebar.

I am asking because I need to automount some partitions at startup. I tried several mount option, but none of them mounts exactly how nemo does. Using mount it mounts with either too many permissions, not enough permissions or with ownership problems.

I couldn't figure out what options / command nemo uses, that's why I'm asking.

enter image description here –> enter image description here

Best Answer

As far as I know (I haven't looked directly at the code for Nemo, but I've seen a lot of other file managers), it's using a call to the UDisks DBus API. You can (probably) replicate the call that Nemo does manually with the command:

udisksctl mount --block-device=/dev/whatever

Which should spit out the path that the device got mounted on (on most systems it will be under /run/media/$USER, with a name matching the volume label (or the volume UUID if it lacks a label).

You can also pass this command the argument --options= to give it custom mount options.

The equivalent to unmount is:

udisksctl unmount --block-device=/dev/whatever

The downside to that approach is that it only works inside a working DBus session, which means it won't work during system startup.

If by 'on startup' you mean 'when I log in', then, you could use the pam_mount PAM module, which would allow you to also mount the filesystem when you log into the console, and will additionally unmount it correctly when you log out. Documentation for that can be found here. This is actually what gets used by most distributions to handle encrypted home directories (at least, traditionally, most of them are slowly migrating to the VFS Crypto API, but that's rather off-topic).

If you instead mean 'when the system boots up' by 'on startup', then you are actually better off not trying to replicate the exact means that Nemo uses to mount the filesystem. A much better approach is to curate the mount options yourself so that it behaves exactly as you want.

You mentioned in the comments that it was a NTFS volume you're trying to mount. Your basic /etc/fstab line for that should look like this (based on info from the comments):

/dev/sda3     /mnt/user/Storage    ntfs-3g    rw,nosuid,nodev,allow_other    0 0

On top of that, you can add other options. Suggestions that aren't used by default by most automounting tools include:

  • windows_names: This will prevent you from creating files you can't access from WIndows because of naming restrictions. Normally, you're not likely to accidentally create such files (most people don't use the restricted characters, and the reserved names are not used most places either), but it provides a nice safety net just in case.
  • hide_dot_files: This will automatically mark files with filenames beginning with a . as hidden, improving consistency between Windows and Linux.
  • hide_hidden_files: This will exclude files with the hidden attribute from being listed in directory listings (even with ls -a). Similar argument to the above option, although I'm not as fond of it myself.
  • streams_interface=xattr: This exposes NTFS alternate data streams as extended attributes, allowing most backup tools to save and restore them correctly.
  • big_writes: This improves write performance for large writes pretty significantly, but has no effect on how the data looks on the partition.

Additionally, you may want to look into getting a user mapping file set up if you use this volume regularly on both WIndows and Linux. That will allow permissions set in one OS to behave correctly in the other. The NTFS-3G manual page (check here) has reasonably good documentation of how to do that in the 'User Mapping' section.

Related Question