Thursday, December 23, 2010

Mounting ntfs partitions

Ubuntu is capable of reading and writing files stored on Windows formatted partitions. These partitions are normally formatted with NTFS, but are sometimes formatted with FAT32. You will also see FAT16 on other devices.

To check what your partition is formatted as you can run from terminal:
sudo fdisk -l

Output must be something like:
flaca@anneke:~$ sudo fdisk -l

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x61553235

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         914     7340032    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2             914       23036   177689854    7  HPFS/NTFS
/dev/sda3           23036       38914   127539201    5  Extended
/dev/sda5           38264       38914     5222400   82  Linux swap / Solaris
/dev/sda6           23036       26683    29295616   83  Linux
/dev/sda7           26683       38263    93018112   83  Linux

Partition table entries are not in disk order
flaca@anneke:~$


The ntfs-3g driver is used in linux to read and write NTFS partitions.

NTFS (New Technology File System) is a file system developed by Microsoft and used by Windows computers (Windows 2000 and later). Until 2007, linux was not able to write to this type of filesystem, it could only read from it. The stable ntfs-3g driver now allows linux systems to read and write NTFS formatted partitions.

The ntfs-3g packages comes pre-installed in currently supported versions of Ubuntu and most NTFS devices should work out of the box without further configuration.

Manual Configuration

First you need to find the device location of the NTFS partition(s) you want to mount. In terminal, run:
sudo fdisk -l | grep NTFS | awk '{print $1}'

Example:
flaca@anneke:~$ sudo fdisk -l | grep NTFS | awk '{print $1}'
/dev/sda1
/dev/sda2
flaca@anneke:~$



The name of each partition should be something like /dev/hdxn or /dev/sdxn, where x is an alphabetical letter (ranges from a to z) and n is a number (e.g. /dev/hda1).

If the drive is internal, you will now need to edit your file systems table configuration file, /etc/fstab. If the drive is an external USB or firewire drive, hal should automount it. Now, be sure to save a backup of fstab first, then open the file for editing:
sudo cp -p /etc/fstab /etc/fstab.orig
sudo vi /etc/fstab


Find the line that matches the device location you just found and change it to the following. If there is no entry yet, add a new line like the following:
<your partition> /media/<mount point> ntfs-3g defaults,user,locale=en_US.utf8 0 0
Example:
/dev/sda2    /media/windows    ntfs-3g    defaults,user,locale=en_US.utf8 0 0


NOTE: If it displays your NTFS partition with a UUID, you can check the relevant device location by running one of the following commands. It is OK (and even advisable) to keep the UUID setup if that is what already exists.
sudo blkid
ls -l /dev/disk/by-uuid/


Replace <your partition> with the name of the partition you identified earlier. Replace <mount point> with the location you would like the partition to be mounted at, so you have something like /media/windows or /media/documents for that column.

Note: you can also change your locale option (ex: locale=fr_FR.utf8). Execute locale -a in a terminal to know which ones are supported on your system.

Save and close the file. You will now need to create the mount point for each NTFS partition before you can actually mount them:
sudo mkdir -p /media/<mount point>

Now remount each partition with
sudo umount <your partition>
sudo mount /media/<mount point>


If you want to revert to your previous configuration, run:
sudo cp -p /etc/fstab.orig /etc/fstab
sudo umount /media/<mount point>


Known Issues
The present limitations of this driver are:

  • Writing files encrypted or compressed at the filesystem level (does not include .zip, .gz, .rar files since they are compressed on the file, not the file system level)
  • Changing NTFS file ownership and access rights

Custom Kernel
It is unknown if this issue still exists. Please remove this line if you can confirm that it does.
If you compiled your own kernel, you probably will not have fuse installed. You can get the source with
sudo apt-get install fuse-source

and have a look at /usr/share/doc/fuse-source/README.Debian for instructions on how to compile it.