NTFS-3G
From Gentoo Linux Wiki
| Installation • Kernel & Hardware • Networks • Portage • Software • System • X Server • Gaming • Non-x86 • Emulators • Misc |
Contents |
[edit] Introduction
The ntfs-3g driver is an open source, GPL licensed, Linux NTFS driver which was implemented by the Linux-NTFS project using FUSE. It provides full read-write access to NTFS, but currently lacks support for encrypted and compressed files and POSIX attributes. The driver is quite stable and the performance is comparable with other native Linux filesystems (sometimes even better). It was reported to run on x86, amd64 and arm CPU's, and no major errors or data loss have been yet reported, although there are some known issues.
For more information you can visit the ntfs-3g home page.
[edit] Installation
The driver ebuild depends on sys-fs/fuse (portage will install it automatically as a dependency of the ntfs3g ebuild). Furthermore, it depends on the version of the fuse kernel module. Basically, just ensure that the "File Systems -> Filesystem in Userspace support" option is set as MODULE in your kernel configuration. If it's enabled or disabled, set to build as a module, compile, install and modprobe it.
Then emerge it:
# emerge -av sys-fs/ntfs3g
The fuse kernel module must be prepared for loading into the kernel (the ntfs-3g driver will load it automatically if needed).
# update-modules
[edit] Usage examples
Replace /dev/hda1 with your NTFS volume and /mnt/windows with your mountpoint.
[edit] Mount a volume manually
Full access to all users, permission free (if suid USE-flag is set):
# ntfs-3g /dev/hda1 /mnt/windows
[edit] Mount at boot
You can combine the options provided in the following examples into one single line of /etc/fstab
Make sure that if you mount /usr on an own partition, the mount line for ntfs-3g has to be after the mount line for /usr, otherwise it won't load because the ntfs-3g files are stored in there.
Modify /etc/fstab:
# echo "/dev/hda1 /mnt/windows ntfs-3g 0 0" >> /etc/fstab
Locale support (in the following examples the en_US.utf8 locale is used, replace with yours):
Modify /etc/fstab:
# echo "/dev/hda1 /mnt/windows ntfs-3g locale=en_US.utf8 0 0" >> /etc/fstab
Access for non Root-Users(make ntfs partitions mountable for a normal user, unmountable for everyone else):
Set the suid flag for the ntfs-3g binary and then re-emerge it:
# echo sys-fs/ntfs3g suid>> /etc/portage/package.use # emerge sys-fs/ntfs3g -1
Modify /etc/fstab:
/dev/hda1 /mnt/windows ntfs-3g users 0 0
To make a user/group own everything on the ntfs drive:
Modify /etc/fstab:
/dev/hda1 /mnt/windows ntfs-3g users,uid=THE_ID_OF_THE_OWNER,gid=THE_ID_OF_THE_GROUP 0 0
A User's ID and GID can be found with:
$ id username
If you don't want the drive to be automounted at boot:
/dev/hda1 /mnt/windows ntfs-3g noauto 0 0
One single line doing all these things:
/dev/hda1 /mnt/windows ntfs-3g users,locale=en_US.utf8,uid=THE_ID_OF_THE_OWNER,gid=THE_ID_OF_THE_GROUP,noauto 0 0
Also, if you've given the partition a label (by giving it a "volume name" from Windows or a "label" using ntfslabel from sys-fs/ntfsprogs), you can mount the partition by it's label in /etc/fstab:
LABEL=Windows-XP /mnt/windows ntfs-3g users,locale=en_US.utf8,uid=THE_ID_OF_THE_OWNER,gid=THE_ID_OF_THE_GROUP,noauto 0 0
Now you can mount the drive as a normal user:
$ mount /mnt/windows
For more detailed options and explanations see this document and the manual page:
$ man ntfs-3g
[edit] Use ntfs-3g instead of kernel's read-only ntfs driver for AutoMounting
If you would like to always use ntfs-3g (especially with automounting in KDE) there are several ways to do this. Here they are in order of when they were added to this wiki, take your pick.
[edit] Create pseudo mount.ntfs binary
- overwriting the original mount.ntfs
- if mount is called with "-i" option this method doesn't work
- there could be problems with the kernel ntfs module
As root do:
# ln -s /bin/ntfs-3g /sbin/mount.ntfs
Now when a NTFS filesystem is found, mount will use load ntfs-3g's "mounter".
[edit] Modify HAL 10-ntfs-policy.fdi (hal-0.5.9.1 or later)
After upgrading to hal-0.5.9.1 the functionality from the /usr/share/hal/scripts has been moved to binary files in /usr/libexec/hal-storage-mount/unmount/eject.
Theoretically you should be able to supply options in 10-ntfs-policy.fdi by adding volume.mount.extra_options keys, however on my system, they simply got ignored when I tried to mount devices in thunar. Since I need the locale, uid, gid,... options, I had to get the old scripts from 0.5.7.1 and copy them to /usr/libexec. Doing this is not difficult:
ebuild /usr/portage/sys-apps/hal/hal-0.5.7.1-r5.ebuild install cd /var/tmp/portage/sys-apps/hal-0.5.7.1-r5/image/usr/share/hal/scripts. cp hal-system-storage-mount hal-system-storage-unmount /usr/libexec
Be sure you don't overwrite already existing files in /usr/libexec (they shouldn't be there in 0.5.9.1). Now follow the above description to alter /usr/libexec/hal-system-storage-mount. Use the following /etc/hal/fdi/policy/10-ntfs-policy.fdi which uses the old scripts:
<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
<device>
<match key="volume.fstype" string="ntfs">
<match key="@block.storage_device:storage.hotpluggable" bool="true">
<merge key="volume.fstype" type="string">ntfs-3g</merge>
<merge key="volume.policy.mount_filesystem" type="string">ntfs-3g</merge>
<merge key="org.freedesktop.Hal.Device.Volume.method_execpaths" type="strlist">hal-storage-mount</merge>
<append key="org.freedesktop.Hal.Device.Volume.method_execpaths" type="strlist">hal-storage-unmount</append>
<append key="org.freedesktop.Hal.Device.Volume.method_execpaths" type="strlist">hal-storage-eject</append>
</match>
</match>
</device>
</deviceinfo>
Of course, this hack could break a few things, but negative effects should be quite limited to ntfs-3g. At least, doing it this way will not break your ntfs-3g configuration each time you rebuild or upgrade hal.
If someone could get it to work with extra_options configuration without this hack, that would be great, though.
[edit] Adding /sbin/mount.ntfs is more easier (hal-0.5.9.1 or later)
Just adding a mount.ntfs file makes the mount use ntfs-3g rather than the kernel ntfs
You can also make youself a nice little script to pass extra options to the mount command when mounting an NTFS fs. (i actually like the force command ;) ) /sbin/mount.ntfs.sh
#!/bin/bash ntfs-3g "$@" -o locale=el_GR.utf8,force
Dont forget to make it excecutable:
chmod +x /sbin/mount.ntfs.sh
Now just linking it to mount.ntfs does the trick
ln -s /sbin/mount.ntfs.sh /sbin/mount.ntfs
[edit] Getting rid of "mount: unknown filesystem type 'ntfs'"
All of the above was NOT necessary for me at all. If you are getting this error in KDE you can solve it easily by upgrading to util-linux-2.13-r2. You will need to add it to /etc/portage/package.keywords. (You will still need to have the /sbin link to mount.ntfs in place as described above.)
Tip: You can easily test if your hal configuration is working by doing "pmount-hal /dev/yourdevice" from the command-line without having to reconnect your device each time.
[edit] Enabling a user to mount an NTFS filesystem
When using ntfs-3g, just adding a "users" to the fstab probably won't work out, due to a privilege problem with mount / ntfs-3g.
[edit] ntfs-3g with suid bit
In order to be able to mount the disk the ntfs-3g excecutable has to be marked setuid-root and also the user has to have rights both on the disk as well on the mountpoint.
So first check out whether the /etc/fstab file is correct
/dev/<volume> /<mountpoint> auto users,defaults 0 0
After that setuid-root ntfs-3g
chmod u+s /bin/ntfs-3g
Then add the user to the "disk" group (which all volumes belong to)
gpasswd -a <user> disk
Last but not least make the mountpoint belong to the group disk too
chown :disk /<mountpoint>
[edit] ntfs-3g via sudo
Create entries for your NTFS partitions in your /etc/fstab:
/dev/volume /mnt/mountpoint ntfs-3g user,noauto 0 0
Then try to mount it as a user:
mount /mnt/mountpoint # Error opening '/dev/volume': Permission denied # Failed to mount '/dev/volume': Permission denied # Please check '/dev/volume' and the ntfs-3g binary permissions, # and the mounting user ID. More explanation is provided at # http://ntfs-3g.org/support.html#unprivileged
The ntfs-3g FAQ suggests giving the ntfs-3g binary the suid bit and give users access rights to /dev/volume. This works, but it allows users to do more than just mount the volume. It is also cumbersome to set up permissions for NTFS volumes only. So instead of handing out suid bits and tons of permissions for all users, we're going to restrict that service to mounting and umounting with root permissions only, using sudo.
Emerge sudo and then use visudo to add the following entries to /etc/sudoers
%users ALL=/bin/mount /mnt/mountpoint %users ALL=/bin/umount /mnt/mountpoint
Now try to mount it as a user:
sudo mount /mnt/mountpoint # sudo will ask you for your password here ls /mnt/mountpoint sudo umount /mnt/mountpoint
This method is not as comfortable as a working user option in fstab, as you always have to use sudo and specify the full path to the mountpoint. Sudo will also ask the user for his password. However it is currently the only way to make mount work with the settings you specified in your fstab, without giving the user general read-write access on the whole device / partition, or worse, all of your disks.
[edit] Kernel upgrade issues
If your driver stops working after you have upgraded your kernel then you should reinstall fuse. Install module-rebuild, and run it every time you recompile your kernel.
once:
# emerge sys-kernel/module-rebuild
every time after recompiling:
# module-rebuild rebuild # update-modules
[edit] Disclaimer
The author of this document isn't responsible for any damage or loss of data that the software could cause, use at your own risk.
