Wednesday, September 1, 2010

Mounting an external harddisk with NTFS file system as normal user under Linux using ntfs-3g

On my computer at work running an openSUSE 11.2 64bit installation, I'm using an external harddrive to copy data between my Linux and Windows machines. For several reasons it's formatted with NTFS so that I have to use ntfs-3g under linux for having read and write access. And because it's annoying to always become root for mounting the drive I did the steps described below. It's maybe not the most perfect way but it's working and this is what matters to me.

Let's say I have an external harddisk on /dev/sdb1 and the label of this disk is "EXTERNAL". Then I will find it with ls like this:
me@linux:~> ls -hal /dev/disk/by-label/
insgesamt 0
drwxr-xr-x 2 root root  80  1. Sep 14:38 .
drwxr-xr-x 6 root root 120  1. Sep 16:21 ..
lrwxrwxrwx 1 root root  10  1. Sep 14:38 EXTERNAL -> ../../sdb1
me@linux:~>
Because this label is unique on my machine I can use the label for mounting the harddisk with the fstab file. If I want to mount it to /home/me/usb (assuming my username is me) I put following code as root into /etc/fstab
/dev/disk/by-label/EXTERNAL       /home/me/usb  ntfs-3g noauto,uid=1000,gid=users,umask=022,locale=de_DE.UTF-8   0       0  
which means
  • /dev/disk/by-label/EXTERNAL is the device to be mounted
  • /home/me/usb is the mount point where it should be accessible
  • ntfs-3g is the file system driver to be used
  • the mount options are: noauto (no automatic mount on boot time), uid=1000 (my user id), gid=users (the group which should be used, one can also write his gid like gid=100 which is normally the users gid), umask=022 (gives permissions like 755 or u=rwx,g=rx,o=rx) and the local charset to be used (I'm german so I use the german one obviously)
  • 0 (default settings - don't ask me)
  • 0 (default settings - don't ask me).
Each of this six items has to be tab separated. Then I add myself as root to the group disk in the /etc/group file so that the entry looks like:
disk:x:6:me
I do so because the /dev/sdb1 belongs to the group disk. Otherwise I couldn't get it to work. Maybe someone knows a better trick. Just let me know.

Finallly I set the suid flag on ntfs-3g and ntfs-3g.probe with
me@linux:~> sudo chmod 4755 $(which ntfs-3g)
me@linux:~> sudo chmod 4755 $(which ntfs-3g.probe)
so that I can mount the external harddisk also as normal user and don't have to become root everytime.

I recommend reading the man pages of mount and ntfs-3g before you start messing around. You should definitly know what you're doing especially if you're editing the /etc/fstab file. So be careful.

cheers

No comments: