Linux systems often mount external NTFS drives with default options that may limit file permissions or performance. By configuring your system to automatically apply specific mount options for NTFS partitions connected over USB, you can improve file access, enable write support, and avoid manual remounting every time you plug in a drive.
Using Udev Rules and Systemd Mount Units
Step 1: Identify your NTFS partition’s UUID. Plug in your NTFS USB drive and run the following command to list all available partitions and their UUIDs:
lsblk -o NAME,UUID,FSTYPE,MOUNTPOINT
This output displays device names, UUIDs, file system types, and mount points. Note the UUID of the NTFS partition you want to configure.
Step 2: Create a mount point directory. Choose a location to mount your NTFS partition, such as /media/usb-ntfs
. Create the directory if it doesn’t exist:
sudo mkdir -p /media/usb-ntfs
Step 3: Create a systemd mount unit file. Systemd mount units allow precise control over how and when partitions are mounted. Create a file named /etc/systemd/system/media-usb\x2dntfs.mount
. The filename must reflect the mount point path, with dashes replacing slashes and \x2d
representing hyphens.
Paste the following content, adjusting the UUID and mount options as needed:
[Unit]
Description=Mount NTFS USB drive automatically
[Mount]
What=UUID=your-ntfs-uuid-here
Where=/media/usb-ntfs
Type=ntfs-3g
Options=uid=1000,gid=1000,umask=022,windows_names
[Install]
WantedBy=multi-user.target
Replace your-ntfs-uuid-here
with the UUID from Step 1. The Options
line sets the owner (uid/gid), permissions (umask), and enforces Windows-compatible filenames.
Step 4: Reload the systemd daemon and enable the mount unit so it will mount automatically at boot or when the drive is attached:
sudo systemctl daemon-reload
sudo systemctl enable --now media-usb\x2dntfs.mount
The NTFS partition will now mount automatically with your specified options whenever it is connected and detected by the system.
Using Udev Rules with Custom Mount Scripts
Step 1: Write a custom mount script. Create a script such as /usr/local/bin/auto-mount-ntfs.sh
that will handle mounting with your preferred options. Example:
#!/bin/bash
mount -t ntfs-3g -o uid=1000,gid=1000,umask=022,windows_names $1 /media/usb-ntfs
Make the script executable:
sudo chmod +x /usr/local/bin/auto-mount-ntfs.sh
Step 2: Create a udev rule to trigger the script when an NTFS partition is connected over USB. Add a new rule file at /etc/udev/rules.d/99-ntfs-automount.rules
:
KERNEL=="sd*[0-9]", SUBSYSTEMS=="usb", ENV{ID_FS_TYPE}=="ntfs", ACTION=="add", RUN+="/usr/local/bin/auto-mount-ntfs.sh %N"
This rule matches USB devices with NTFS file systems and runs your script whenever a new partition is added.
Step 3: Reload udev rules to apply the changes:
sudo udevadm control --reload-rules
sudo udevadm trigger
Now, when you plug in an NTFS-formatted USB drive, your script will mount it automatically with the specified options.
Using Fstab for Static Devices
If you always use the same external drive, you can add an entry to /etc/fstab
to mount it automatically with your preferred options. This method is less flexible for devices that change frequently but works well for dedicated drives.
Step 1: Open /etc/fstab
in a text editor with root privileges and add a line similar to:
UUID=your-ntfs-uuid-here /media/usb-ntfs ntfs-3g uid=1000,gid=1000,umask=022,windows_names 0 0
Replace your-ntfs-uuid-here
with your device’s UUID. Save the file and mount all filesystems with:
sudo mount -a
This approach will mount the NTFS partition at boot or when the device is connected, but only if the UUID matches.
Automating NTFS partition mounting with custom options streamlines file access and ensures consistent behavior with every USB connection. Adjust these methods as needed for your workflow, and remember to update device UUIDs if you swap drives.
Member discussion