Mounting an NTFS Partition for Use in Mandriva
Linux workstations are often configured as multiple operating system booting machines. This means that the machine will often have separate partitions with various operating systems allowing the user to boot into Linux or Windows (or another operating system). I'm currently running a dual boot workstation with three logical partitions. I have one partition for Mandriva, one for Windows XP and one 'data' partition. The idea was to use this data partition so that both operating systems had access to the files stored there. I set up the partition during the Windows XP install so it's formatted NTFS. This makes it a native partition for Windows and makes it easier for the Mandriva installation to identify.
The partition works quite nicely under Windows. I've set this partition to serve as the location for the 'My Documents'. To do this simply right click on the 'My Documents' folder on the desktop, then select the 'Target' tab. Once you've don this you can click the 'Move...' button to change the location of your 'My Documents'. In my case I set the location to be 'D:\Documents' which is a folder on the D drive (the NTFS partition I'm using for data).
Setting up access from the Mandriva installation was a little tricky. By default Mandriva will locate and mount NTFS partitions. This meant that when I logged into Mandriva I could easily see the Windows partitions under /mnt/win_c and /mnt/win_d. This worked quite well for a little while, but I soon noticed some interesting behavior. The win_d partition was the one I wanted to use to store my data, but I couldn't write to the drive. In fact, when I looked at the permissions on the drive I discovered why:
[justin@workstation ~]$ ls -lh /mnt total 15K drwxr-xr-x 2 root root 1.0K Jul 11 18:32 cdrw/ drwxr-xr-x 2 root root 1.0K May 2 13:29 disk/ drwxr-xr-x 2 root root 1.0K May 2 13:29 mandriva-linux-2007-spring-free-dvd-i586/ dr-xr-xr-x 1 root root 8.0K Jul 11 21:19 win_c/ dr-xr-xr-x 1 root root 8.0K Jul 11 21:19 win_d/
As you can see the partition is mounted as a 'read-only' partition, and it's owned by root. This meant I could read and copy data off of the drive just fine, but I couldn't actually put new data on the partition. I'd set the size of this drive to take up the most room on my hard disk so not being able to write data there would prove problematic.
As a side note you can see I have the full installation DVD mounted as a drive. This is actually the ISO image of the installation DVD that I downloaded to my Windows partition. I have a rather new Intel nx6125 motherboard and the drivers aren't quite up to speed on most linux installations at this point. The CD drive would work to boot up the installer, but the installer wouldn't be able to actually see the CD once it was up and running (on any distribution). This meant the installer would boot then basically report it couldn't find the install media (crazy but true). To complete the install I actually had to download a boot CD then install from the ISO on the hard disk. Once the install was complete though I just mounted the ISO permanently so if I want to install any new software I don't have to fiddle with changing disks in the drive, but I digress.
So, I have a drive that is mounted as read only and is owned by root. What I needed was a drive that could be read and written to by my user account 'justin' and was owned by that account. To get the drive to mount the way I wanted all I had to do was unmount it and remount it with the proper permissions. First I needed to identify the actual device (the listing in the /dev directory that conformed to the mapping):
[justin@workstation ~]$ mount /dev/sda7 on / type ext3 (rw) none on /proc type proc (rw) /dev/sda1 on /mnt/win_c type ntfs (ro,umask=0022,nls=utf8) /dev/sda5 on /mnt/win_d type ntfs (ro,umask=0022,nls=utf8) none on /media/floppy type supermount (rw,sync,dev=/dev/fd0,fs=ext2:vfat,--) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
I can see that the drive actually mounted from /dev/sda5. Now I needed to figure out what the uid of my user account was and the gid of the group account so I could use that to remount the drive properly:
[justin@workstation ~]$ sudo cat /etc/passwd | grep justin justin:x:500:500:Justin C. Klein Keane:/home/justin:/bin/bash [justin@workstation ~]$ sudo cat /etc/group | grep justin justin:x:500:
Finally I can unmount the drive and remount it with the proper permissions using the 'mount' and 'umount' commands:
[justin@workstation ~]$ sudo umount /mnt/win_d [justin@workstation ~]$ sudo mount -t ntfs -w -o uid=500,gid=500,umask=0007 /dev/sda5 /mnt/win_d
Check to see if the mount actually worked and you can read and write the filesystem. For me this didn't happen at first:
[justin@workstation ~]$ ls -lh /mnt total 15K drwxr-xr-x 2 root root 1.0K Jul 11 18:32 cdrw/ drwxr-xr-x 2 root root 1.0K May 2 13:29 disk/ drwxr-xr-x 2 root root 1.0K May 2 13:29 mandriva-linux-2007-spring-free-dvd-i586/ dr-xr-xr-x 1 root root 8.0K Jul 11 21:19 win_c/ dr-xr-xr-x 1 justin justin 8.0K Jul 11 21:19 win_d/
It turns out that the NTFS driver in my kernel didn't support mounting NTFS as a read/write filesystem (bummer). In order to do this you'll need the following packages installed:
fuse-2.6.3-1mdv2007.1.i586 libfuse2-2.6.3-1mdv2007.1.i586 libntfs-3g0-1.0-2mdv2007.1.i586 ntfs-3g-1.0-2mdv2007.1.i586 ntfs-config-0.5.5-2mdv2007.1.i586
Once these are installed you should be able to mount the drive in read/write mode. Go ahead and give it a shot again, un-mounting and remounting the drive like so:
[justin@workstation ~]$ sudo umount /mnt/win_d [justin@workstation ~]$ sudo mount -t ntfs-3g -o rw,uid=500,gid=500,umask=022 /dev/sda5 /mnt/win_d WARNING: Deficient FUSE kernel module detected. Some driver features are not available (swap file on NTFS, boot from NTFS by LILO), and unmount is not safe unless it's made sure the ntfs-3g process naturally terminates after calling 'umount'. The safe FUSE kernel driver is included in the official Linux kernels since version 2.6.20-rc1, or in the FUSE 2.6.0 or later software packages, except the faulty FUSE version 2.6.2. Please see the next page for more help: http://www.ntfs-3g.org/support.html#fuse26
Whoops, looks like I have to install the FUSE kernel modules:
[justin@workstation ~]$ sudo urpmi fuse-kernel-2.6.17-13mdv To satisfy dependencies, the following package is going to be installed: dkms-minimal-2.0.16-1.1mdv2007.1.noarch fuse-kernel-2.6.17-13mdv-2.6.3-1mdv2007.1.i586 Proceed with the installation of the 2 packages? (0 MB) (Y/n) Y
Regardless of the warning, the drive has mounted!
[justin@workstation ~]$ ls -lh /mnt/win_d total 1.7M drwxr-xr-x 1 justin justin 8.0K Jun 27 17:10 Documents/ drwxr-xr-x 1 justin justin 0 Feb 11 08:39 RECYCLER/ drwxr-xr-x 1 justin justin 4.0K Feb 11 00:49 System Volume Information/
Note that if you keep getting this warning it means your kernel is out of date. You can install new kernels pretty easily. First use the Mandriva Control Center or urpmi to update your kernel. Test it out and when you're sure you like it update your /boot/grub/menu.lst file to set the new kernel as your default. You can check your kernel version using the following command:
[justin@workstation ~]$ uname -r 2.6.17-14mdv
In this case I've got an older kernel and need to upgrade to one newer than 2.6.20. There are several differnt 'types' of kernel in Mandriva. I eventually chose to use kernel-linus-18.104.22.168-1mdv-1-1mdv2007.1.i586 to get ntfs-3g support working. If you're confused about the various kernels available for Mandriva check out their website at http://wiki.mandriva.com/en/Docs/Howto/Mandriva_Kernels.
Now I'd like a more permanent solution to the mounting problem. At system boot time the behavior of drive mounting is controlled by the file /etc/fstab. To make our partition mount in a read/write mode all we have to do is edit the /etc/fstab file so it looks something like:
[justin@workstation ~]$ cat /etc/fstab /dev/sda7 / ext3 defaults 1 1 /dev/sda1 /mnt/win_c ntfs umask=0022,nls=utf8,ro 0 0 /dev/sda5 /mnt/win_d ntfs-3g rw,uid=500,gid=500,umask=0007 0 0 /dev/hda /media/cdrom auto umask=0022,users,iocharset=utf8,noauto,ro,exec 0 0 none /media/floppy supermount dev=/dev/fd0,fs=ext2:vfat,--,umask=0022,iocharset=utf8,sync 0 0 /mnt/win_c/mandriva-linux-2007-spring-free-dvd-i586.iso /mnt/mandriva-linux-2007-spring-free-dvd-i586 iso9660 noauto,loop 0 0 none /proc proc defaults 0 0 /dev/sda6 swap swap defaults 0 0
Now whenever I reboot the filesystem will be mounted in such a way as to allow me to read as well as write to the drive:
[justin@workstation ~]$ ls -lh /mnt total 15K drwxr-xr-x 2 root root 1.0K Jul 11 18:32 cdrw/ drwxr-xr-x 2 root root 1.0K May 2 13:29 disk/ drwxr-xr-x 2 root root 1.0K May 2 13:29 mandriva-linux-2007-spring-free-dvd-i586/ dr-xr-xr-x 1 root root 8.0K Jul 11 21:19 win_c/ drwxrwx--- 1 justin justin 4.0K Jul 10 19:25 win_d/
Once this is all set up you shouldn't have to worry about it any more. It's sort of a hassle getting this far, but it's a one time investment of time, and certainly worth it if you plan to use a setup where you can share data between operating systems.