NTFS-3G

From SlackWiki
Jump to navigation Jump to search


NTFS-3G is a fully functional NTFS writer/reader built as a userspace filesystem, thanks to the magic of FUSE. For another way to get read/write support of NTFS filesystem, see Captive NTFS.

Please note that the following instructions are made in such a way that it should be easy to create a SlackBuild script or make a package.


Installing FUSE

Since NTFS-3G is not implemented as a kernel module, it has to find ways to communicate with the kernel and make its services as a filesytem available to any other process. To do this, it uses a library called FUSE (which stands for Filesystem in Userspace).

Slackware 11.0's 2.6.17.13 kernel already has FUSE support compiled, but the version which comes with this kernel lacks a few features (such as proper block devices handling) and that seems to annoy NTFS-3G, so we'll begin by installing a newer FUSE.

If you have FUSE already installed, please check that it is at least 2.6.0 with this command:


  $ sudo /sbin/modprobe fuse
  $ dmesg | grep fuse
  kernel: fuse init (API version 7.8)
  kernel: fuse distribution version: 2.6.0

If it doesn't print the distribution version line then you have a version older than 2.6.

Getting FUSE to work

You have to make sure that the version of FUSE you're downloading is ≥ 2.6.0 and ≠ 2.6.2, unless you like annoying warnings and malfunctioning filesystems.

I prefer to do my building in a /tmp folder, so I'll start with this:

  mkdir  /tmp/fusebuild
  cd /tmp/fusebuild

First, you have to get the most recent version (at the time of writing, 2.6.3):

  wget http://superb-west.dl.sourceforge.net/sourceforge/fuse/fuse-2.6.3.tar.gz

(There are several other mirrors. You can go to SF.net's download page to find another mirror.)

Then you can extract the source.

  tar zxf fuse-2.6.3.tar.gz
  cd fuse-2.6.3

Before compiling, you have to make sure that your kernel sources and .config matches your running kernel. If you've build your own kernel (and haven't touched the source since then) then you should be fine. Otherwise, if you're running Slack's binary kernels, you'll have to install the kernel source. Usually, that's enough. Should you have some other kernel-related trouble, check out the FUSE homepage.

Now, you can compile your fuse library/tools/module

  # You might want to change the CFLAGS or the --with-kernel path
  # Also, take note of the --exec-prefix=/ this allows you to have
  # /usr mounted later (or even as an NTFS partition, but why would
  # you want that?) and still mount NTFS drives. You may as well
  # remove it, and everything will get in /usr/*
  CFLAGS="-O2 -march=i486 -mtune=i686" ./configure \
  --enable-kernel-module \
  --with-kernel=/lib/modules/$(uname -r)/build \
  --enable-lib \
  --enable-util \
  --enable-example \
  --localstatedir=/var \
  --sysconfdir=/etc \
  --prefix=/usr \
  --exec-prefix=/ \
  --program-prefix= \
  --profram-suffix= \
  i486-slackware-linux
  
  make
  
  # Do the following steps as root:
  make install
  
  # This is only necesary if you didn't change/remove
  # the --exec-prefix option at configure time.
  mv /lib/pkgconfig/* /usr/lib/pkgconfig/
  rmdir /lib/pkgconfig
  
  cat > /etc/udev/rules.d/99-fuse.rules <<_EOF_
  KERNEL=="fuse", MODE="0666"
  _EOF_
  
  # Note that fuse will also put some stuff in /etc/init.d, let's
  # put it where it belongs.
  mv /etc/init.d/fuse /etc/rc.d/rc.fuse
  rmdir /etc/init.d
  
  # You might also want to add this at the bottom of
  # /etc/rc.d/rc.modules:
  # [ -x /etc/rc.d/rc.fuse ] && /etc/rc.d/rc.fuse start


If you're making a slackbuild or building a package, instead issue:

  mkdir -p /tmp/tmproot
  make install DESTDIR=/tmp/tmproot
  
  # Also prepend /tmp/tmproot to the paths references which come after
  # that. You may have to actually create some of those paths.
  

To make sure that everything is working so far, let's run a simple test (as root):

  cd example
  mkdir /tmp/mntpoint
  
  # Run this as root.
  ./hello /tmp/mntpoint & #you can add a "-d" flag if you want to see what's goinng on.
  
  ls -l /tmp/mntpoint
  # You should see something like this:
  # total 0
  # -r--r--r--   1 root root 13 Jan  1 1970 hello
  
  cat /tmp/mntpoint/hello
  # It should print the famous "Hello, World!".
  # If it did, then FUSE is working as it  should.
  
  # Run this also as root.
  fusermount -u /tmp/mntpoint
  
  rmdir /tmp/mntpoint
  cd ..

If everything is fine so-far, you can delete the cruft left behind:

  cd
  rm -rf /tmp/fusebuild


Installing NTFS-3G

Now you should be ready to install NTFS-3G. Again, let's begin by making a build directory:

  mkdir /tmp/ntfs-3gbuild
  cd /tmp/ntfs-3gbuild

Getting the greatest & latest

Then we can get the latest NTFS-3G. Note that there are usually two or three releases per month, so make sure to check the homepage to get the latest version.

  wget http://www.ntfs-3g.org/ntfs-3g-0.20070207-RC1.tgz

Configuring and compiling

Compiling NTFS-3G is actually quite easy, it is one of those programs were compiling "just works".

First, you have to untar the source:

 tar zxf ntfs-3g-0.20070207-RC1.tgz
 cd ntfs-3g-0.20070207-RC1

Next, let's configure the sources:

 CFLAGS="-O2 -march=i486 -mtune=i686" ./configure \
 --prefix=/usr \
 --exec-prefix= \
 --program-prefix= \
 --program-suffix= \
 i486-slackware-linux

That usually works without problems, unless you are missing libfuse. If so, you must see the above steps on configuring FUSE.

Now compile and install.

 make
 
 make install
 
 # If you're making a package or a slackbuild, you will have to issue the next trick to avoid some st*pid error:
 #
 # make install LDCONFIG=/bin/true DESTDIR=$YOUR_ROOT_DIR
 #
 # also, you'll have to make sure that the mount.ntfs-3g.8 symlink points to the right (maybe gzipped) ntfs-3g.8 file.

And that's pretty much it.

Mounting with NTFS-3G

So, how to mount something? NTFS makes mounting NTFS filesystems as easy as with other filesystems:

 root@damned-02# mount -t ntfs-3g /dev/sda1 /mnt/pendrive

If you fail to see some files which you know are there, you should try using the locale option, specially if that partition is used by a non-english Windos.

For example:

For some reason I don't know, My WinXP in Spanish uses en_US for character encoding (not even en_US.utf8), to see my files with "special" chars (mostly á, é, í, ó, ú and ñ) I have to use:
 root@damned-02# mount -t ntfs-3g -o locale=en_US /dev/sda1 /mnt/pendrive

The only way I know to find the right locale is to do some trial and error. If when you mount without locale, it shows all your files, then your correct locale is the one printed by

 echo $LANG

To see which locales you have support for (there are 342 in Slack 11.0), type

 locale -a | less

Using /etc/fstab

You can use /etc/fstab to mount ntfs partitions at boot time. For example, my laptop's fstab looks like this:

   /dev/hda1        swap             swap        defaults         0   0
   /dev/hda3        /                jfs         defaults         1   1
   /dev/hda4        /home            jfs         noatime          1   2
   /dev/hda2        /mnt/win         ntfs-3g     dmask=0007,fmask=0117,gid=6,locale=en_US  1   0
   /dev/cdrom       /mnt/cdrom       auto        noauto,group,ro  0   0
   devpts           /dev/pts         devpts      gid=5,mode=620   0   0
   proc             /proc            proc        defaults         0   0

This gives read/write access to anyone in the disk group (gid=6) to the NTFS partition at hda2 mounted in /mnt/win.

Note, though, that "mount" reports the filesystem as "fuseblk" (unless you have a version of fuse < 2.6 which won't allow you to mount block devices anyway).

Allowing users

NTFS-3G can let users other than root mount NTFS filesystems, but you'll have to set the suid flag in /bin/ntfs-3g. This applies even when using fstab with the users option.

So for this to work:

  /dev/sda1        /mnt/pendrive   ntfs-3g     noauto,users       0   0

You have to do (as root):

  # chmod 4755 /bin/ntfs-3g

RTFMs

If you have any problems or doubts:

If you find any error in this tutorial, don't forget this is a wiki and don't hesitate fixing or updating or improving or ...