Mounting Windows Partitions
From Gentoo Linux Wiki
If you are dual-booting your system with Windows, at some point you may want to share files between the two operating systems. Fortunately, the Linux kernel provides full read/write support for FAT32 and the older FAT filesystems. Full NTFS read-only support is natively available in the kernel as well, along with a small (almost useless) write support.
Full write support for NTFS is available using the ntfs3g userspace read-write driver. Install guide.
Many hardware flash drives (included in digital cameras, mp3 players, for example) format their partitions with the VFAT filesystem, and this guide will apply to those who want to access their data on those devices as well.
If you are interested in formatting your partitions to one of the FAT filesytems, mkfs.vfat and mkfs.msdos are available in the dosfstools package.
Mounting your Windows drives is simply a matter of reconfiguring your kernel with the right options.
Recommended reading before proceeding includes the documentation for the Linux-NTFS project, which provides the ntfsprogs user tools, and the MAN page for mount.
Contents |
[edit] Kernel Configuration
If you are using genkernel, chances are that DOS/VFAT/NTFS support is already included into your kernel, and are readily available as modules. You can load them, as root, respectively, with| Linux Kernel Configuration: File Systems |
File Systems ---> DOS/FAT/NT Filesystems ---> <M> MSDOS fs support <M> VFAT (Windows-95) fs support <M> NTFS file system support |
In the above example, all three options are selected as modules. In most cases, you'll never need MSDOS fs support, since that is for writing to very old FAT16/FAT32 file systems. Most general users would need to add VFAT (Windows-95) fs support to access their Windows system and/or flash devices, and NTFS file system support to access their Windows partitions.
Before exiting your kernel configuration, there is one more thing to add: Native language support. The kernel's Help sub-option describes the necessity well:
To get to NLS support, exit out of the DOS/FAT/NTFS sub-menu, and enter the sub-menu in File Systems for Native Language Support.
| Linux Kernel Configuration: Native Language Support |
Native Language Support --- Base native language support (iso8859-1) Default NLS Option <M> Codepage 437 (United States, Canada) <M> NLS ISO 8859-1 (Latin 1; Western European Languages) |
If you've already enabled one of the filesystem options in the other menu, the first option in this menu will be marked as included (--- Base native language support). The second line has a default NLS option. Don't change it unless you know you need to.
If you are going to use MS-DOS support (read/write to MS-DOS partitions, not VFAT), then you will have to either compile in or select one of the Codepage options as a module. Each codepage option has a country or region listed next to it, so choosing yours shouldn't be difficult. If you are only using VFAT and/or NTFS support, you can skip that option.
Users of VFAT and/or NTFS read/write support, will need to choose one of the NLS ISOs that are available. Again, choose the selection that most closely resembles your region or language. For English-speaking countries, the first option, NLS ISO 8859-1, is what you will need.
If you need to add support for files saved with Unicode characters, then NLS UTF8 is availabe as an option as well.
Save your settings, recompile your kernel (and reboot), or load the modules when finished.
[edit] Mounting Partitions
If you haven't yet, readBelow is a sample output:
| Code: fdisk -l |
Device Boot Start End Blocks Id System /dev/hda1 * x xxxx xxxx+ 7 HPFS/NTFS /dev/hda2 xxxx xxxx xxxx b W95 FAT32 |
In this example, the harddrive running Windows has its C:\ drive formatted as NTFS and its D:\ drive formatted as Windows 95 FAT32 (VFAT). And, from the Device column, we can see that they are listed as /dev/hda1 and /dev/hda2.
Now you should have everything you need to mount the filesystems.
[edit] Basics
Assuming you are root, create a directory to access your drive in /mnt. For this example, we'll use ntfs as the directory name for the NTFS drive.
Next, mount the partition using the mount command. When using mount, use the -t argument to specify the filesystem type (ntfs, in this case), then the device name (/dev/hda1 from the example) and the directory to access the drive (/mnt/ntfs):
If you were going to mount a FAT32 partition, the -t type would be vfat.
For MS-DOS partitions, the option would be msdos instead.
[edit] /etc/fstab
Now that you know how to mount a Windows or MS-DOS filesystem, you can add an entry to your /etc/fstab file, so that next time you can simplify the process.
The filesystem tabular file (fstab) entries should be one per line, with spaces or tabs between columns. The columns are in order of filesystem (or device), mountpoint, filesystem type, options, and dump / pass variables.
Open up the file with your favorite editor (as root), and add a new line at the end of the file.
First, put your filesystem's device. From our example above, if you wanted to mount your Windows C:\ drive formatted as NTFS with the default values (more options explained below), this is what you would add to your file:
/dev/hda1 /mnt/ntfs ntfs defaults 0 0
The defaults option will both mount the partition at every time at boot, and set it to read/write access for root only. If you also want to change this behavior, then go on reading.
[edit] Mount Options
The same options that are available with the mount program can be passed in fstab as well. Again, read[edit] ro: readonly filesystem
If you wanted it so you can only read data, and not write to the hard drive, change defaults to ro instead.
/dev/hda1 /mnt/ntfs ntfs ro 0 0
[edit] noauto: don't mount at boot
With that option /mnt/ntfs will always be mounted everytime you boot. If you didn't want it to automatically mount each time, but instead mount it manually, add noauto to the options. Options in the fstab file are comma separated, with no spaces between them.
/dev/hda1 /mnt/ntfs ntfs ro,noauto 0 0
[edit] user, users: let users mount and unmount
Taking a page from man mount (which explains it much better than we ever could),
"Normally, only the superuser can mount file systems. However, when fstab contains the user option on a line, then anybody can mount the corresponding system.
Thus, given a line in /etc/fstab
/dev/cdrom /mnt/cdrom iso9660 ro,user,noauto,unhide
any user can mount the iso9660 file system found on his CDROM using the command
$ mount /dev/cdrom
or
$ mount /mnt/cdrom
For more details, see fstab(5). Only the user that mounted a filesystem can unmount it again. If any user should be able to unmount, then use users instead of user in the fstab line."
In summary, add the user option to allow any user mount the partition, but that user will be the only one who can unmount it. Or add the users option to let any user mount or unmount that partition.
[edit] uid,gid: mount as (user,group)
On all three filesystems (MS-DOS, VFAT, NTFS), mount lets you pass the uid and gid options, which let you set the user and group IDs of who the files are shown to when the filesystem is mounted.
To find out the values for uid and gid, run$ id larry uid=1000(larry) gid=100(users)
So if you wanted everything owned as larry:users on /mnt/ntfs, this is what you would use in /etc/fstab:
/dev/hda1 /mnt/ntfs ntfs uid=1000,gid=100 0 0
Without any options, mount will default to user 0 and group 0, or root.
[edit] umask: octal file permissions
You can change permissions using the parameter umask. But be aware that it must be the bitmask of permissions that are not present for the mountpoint. It is an octal number, formed like this:
- character '0': Indicates that this is an octal number, not decimal.
- first digit: owner user permissions
- second digit: owner group permissions
- third digit: world permissions (every other user on the system)
The modes are as follows (the first column is the mode octal number):
M | R W X ------------- 0 | * * * 1 | * * - 2 | * - * 3 | * - - 4 | - * * 5 | - * - 6 | - - * 7 | - - -
Note: These octal number codes differ from the octal number codes used by chmod.
For example, if you want everybody to be able to read, write, and execute every file in your /mnt/c, you should specify the mask 0000:
/dev/hda1 /mnt/vfat vfat umask=0000 0 0
If you want only users from group 610 to be able to read, write, and execute:
/dev/hda1 /mnt/vfat vfat gid=610,umask=0707 0 0
If you want only users from group 610 to be able to read, and execute (not write):
/dev/hda1 /mnt/vfat vfat gid=610,umask=0727 0 0
To create a simple and full access to a partition for all users you need for instance:
/dev/hda2 /mnt/WINXP ntfs auto,umask=0000 0 0 /dev/hda7 /mnt/WINME vfat auto,umask=0000 0 0 /dev/hdb5 /mnt/EXT ext3 defaults,users 0 0
[edit] utf8: Unicode support
You may also add "utf8" option, if you can't see some files with international characters in filenames.
/dev/hda1 /mnt/vfat vfat ro,utf8 0 0 /dev/hda2 /mnt/ntfs ntfs ro,utf8 0 0
[edit] Troubleshooting
If after changing permittion options in /etc/fstab you mount partition and permissions did not change, check if this partition is already mounted to another directory. Unmount the partition first, since you cannot mount the same partition to different directories with different options at the same time.
