07/12/2007

HowTo automount external ntfs-formatted USB hard drives with write permissions for normal users AND the correct locale...

To automount your hard drive with write permissions, first backup your fstab.

su
cp /etc/fstab /etc/fstab.bak

Then plug in your drive and give it write permissions in ntfs-config. This puts and entry in fstab, which effectively prevents HAL from automounting the drive. So you need to replace the new fstab with your backup. Then unmount your drive.

cp /etc/fstab.bak /etc/fstab
umount /dev/sdXY

If you now try to mount your drive in Konqueror with right-click --> Mount, it should give you an error message. Now edit your /etc/PolicyKit/PolicyKit.conf and put in any users or UIDs who need to be able to mount the drive.
<config version="0.1">
<match action="hal-storage-mount-removable-*">
<match user="taaris|1001">
<return result="yes">
</return>
</match></match>

Then reload the settings.

polkit-reload-config

If you now plug in your drive or mount it in Konqueror, it should be mounted with read/write permission for everyone.


To mount it (and everything else you mount with ntfs-3g as well) with the correct locale, you need to replace /sbin/mount.ntfs-3g with a small bash script.

su
mv /sbin/mount.ntfs-3g /sbin/mount.ntfs-3g.bak
touch /sbin/mount.ntfs-3g
echo '#!/bin/bash
/bin/ntfs-3g -o locale=de_DE.UTF-8 $1 $2' > /sbin/mount.ntfs-3g
chmod +x /sbin/mount.ntfs-3g

Sources (info, not code!) can be found here and here.

4 comments:

DaWuzzzz said...

Just one little annotation... by echoing as taaris suggests, you echo into the destination of the symlink and overwrite your ntfs-3g binary.
Better do:
rm /sbin/mount.ntfs-3g
and create a new file with vi filling in her nice script.

taaris said...

Changed "cp" to "mv" so that people don't accidentally end up echoing into symlinks....

avocadohead said...

On my system it's /usr/bin/ntfs-3g so change that in mount.ntfs-3g if necessary

Ingo Müller said...

The following version of the script allows spaces in the label of partions and passes other options to ntfs-3g (via the $4):

#!/bin/bash
/bin/ntfs-3g $1 "$2" -o locale=en_US.UTF-8,$4 #put your own locale here