0

I need to mount an external hard drive, always with some given file permissions on files and directories. I know how to do this once but I do not know how to make these changes permanent so that these permissions stay the same. I do not want to mount the drive manually all the time.

1

To mount any partition automatically and permanently, it has to be included in the configuration file /etc/fstab.

  • The tool Disks that comes with Ubuntu allows to achieve this using a graphical user interface, See this post on how it works: Is there a program to mount all of my drives automatically?

  • An alternative - classical - approach is to edit the configuration file /etc/fstab yourself, and add a line that tells the system how and where to mount the partition.

    1. Determine the unique identifier of your disk. This is easiest with the command lsblk -f. You may recognize your ntfs partition because it has "ntfs" as file system type in the column FSTYPE. If not mounted, nothing will be listed under MOUNTPOINT. Take note of the UUID in the similarly named column, because it will be the first entry in the line you will add to /etc/fstab.
    2. Decide on a mount point, i.e., a folder where your partition will be mounted, and where you will see the folders on that partition once it is mounted. As an example, I will assume you will mount it in a folder "windows" under /mnt. Now create that folder: sudo mkdir -p /mnt/windows
    3. Open the configuration file /etc/fstab as administrator for editing in a text editor. For example, I use nano. sudo nano /etc/fstab Add the following line:

UUID=<UUID_you_found_in_step_1> /mnt/windows ntfs auto,dmask=007,fmask=117,utf8 0 0

This line presents 6 entries, separated by whitespace. 1) The partition you want to mount identified by its UUID; 2) the mount point, i.e. where you will mount it; 3) the file system type; 4) the mount options and 5) and 6) numbers both set to 0 (whether the system should be 'dumped' and whether the system should be checked on startup - the latter you will do regularly in MS Windows). Options set file and folder permissions for the entire drive, and indicate strange characters should be utf8 encoded.

  1. You can also set owners through fstab options (uid=...,gid=...), but I find it easier to set owners by setting these to the mount point. As such, if you are to be owner and group of the partition, you can set this with the command:

sudo chown $USER:$USER /mnt/windows

$USER will be replaced by the currently logged in user with root permissions (that will be you). You can substitute another login to give the partition to another user.

  1. Check whether all is good with the command sudo mount -a. If there is no output, all is good, and you will see the contents of your partition navigating to the root directory, then mnt and then windows.

Your Answer

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