Monday 9 May 2005

Mounting NTFS filesystem in Linux

NTFS or New Technology File System is Microsoft's proprietary filesystem used in Windows NT, Windows 2000 and Windows XP. It is a robust filesystem having many more features like encryption, robust security, support for quotas and so on which the FAT(32) filesystem lacks. If you are dual booting your machine between windows NT/2000/XP and Linux, and if you have a NTFS partition on your hard disk, then at some point of time, you might have a need to access the data on the NTFS partition from Linux. But since NTFS is proprietary, it is next to impossible to fully support it from Linux. Which means, there is no way to write data to an NTFS partition from Linux at this point of time. The good news is you can mount the NTFS volume as read only and access your data from Linux. Here I will explain how you can achieve this.
First gather some data about your kernel. Find out the type of kernel you are using.
# uname -r
2.6.5-1.358
This is needed because you need to install a module providing NTFS support to your kernel and you have to make sure the module you download have the same version number as your kernel for this to work.
Now visit linux-ntfs.sourceforge.net . I am using Fedora Core 2. So I will be explaining it with respect to Fedora. If you have a different RedHat version, then you have to visit the section on the website related to your version of Redhat. And if you are using any other distribution like debian, you can build your own module from the source provided on the website.
Now I downloaded the NTFS kernel module kernel-ntfs-2.6.5-1.358.i686.rpm from the website and installed it - logging in as root.
# rpm -ivh kernel-ntfs-2.6.5-1.358.i686.rpm
Preparing... ############################### [100%]
1:kernel-ntfs ############################### [100%]
There should be no errors, just #'s. If all goes well, you will get the message "The Linux NTFS rpm has been successfully installed".
Now execute the following command to see whether linux recognizes NTFS partition on your harddisk:
# fdisk -l /dev/hda
This gave the output on my machine as follows:
Disk /dev/hda: 10.2 GB, 10262568960 bytes
255 heads, 63 sectors/track, 1247 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 510 4096543+ 7 HPFS/NTFS <---o
/dev/hda2 511 523 104422+ 83 Linux
/dev/hda3 524 548 200812+ 82 Linux swap
/dev/hda4 549 1247 5614717+ f W95 Ext'd (LBA)
/dev/hda5 549 1122 4610623+ 8e Linux LVM
As you can see above, Linux recognizes the /dev/hda1 NTFS partition as HPFS/NTFS, which is what we want.
The last step is mounting your NTFS partition in linux. This is achieved by using the mount command as follows:
# mkdir /mnt/c_drive
# mount -t ntfs -r -o umask=0222 /dev/hda1 /mnt/c_drive
Also if you want to mount the NTFS partition automatically each time you boot Linux, append the following line in your /etc/fstab file.
#FILE: /etc/fstab
/dev/hda1 /mnt/c_drive ntfs ro,defaults,umask=0222 0 0
Now you are done. If you want to know more about NTFS, then read this very good NTFS FAQ .

No comments:

Post a Comment