xref: /OK3568_Linux_fs/kernel/Documentation/filesystems/ntfs.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun================================
4*4882a593SmuzhiyunThe Linux NTFS filesystem driver
5*4882a593Smuzhiyun================================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun.. Table of contents
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun   - Overview
11*4882a593Smuzhiyun   - Web site
12*4882a593Smuzhiyun   - Features
13*4882a593Smuzhiyun   - Supported mount options
14*4882a593Smuzhiyun   - Known bugs and (mis-)features
15*4882a593Smuzhiyun   - Using NTFS volume and stripe sets
16*4882a593Smuzhiyun     - The Device-Mapper driver
17*4882a593Smuzhiyun     - The Software RAID / MD driver
18*4882a593Smuzhiyun     - Limitations when using the MD driver
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunOverview
22*4882a593Smuzhiyun========
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunLinux-NTFS comes with a number of user-space programs known as ntfsprogs.
25*4882a593SmuzhiyunThese include mkntfs, a full-featured ntfs filesystem format utility,
26*4882a593Smuzhiyunntfsundelete used for recovering files that were unintentionally deleted
27*4882a593Smuzhiyunfrom an NTFS volume and ntfsresize which is used to resize an NTFS partition.
28*4882a593SmuzhiyunSee the web site for more information.
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunTo mount an NTFS 1.2/3.x (Windows NT4/2000/XP/2003) volume, use the file
31*4882a593Smuzhiyunsystem type 'ntfs'.  The driver currently supports read-only mode (with no
32*4882a593Smuzhiyunfault-tolerance, encryption or journalling) and very limited, but safe, write
33*4882a593Smuzhiyunsupport.
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunFor fault tolerance and raid support (i.e. volume and stripe sets), you can
36*4882a593Smuzhiyunuse the kernel's Software RAID / MD driver.  See section "Using Software RAID
37*4882a593Smuzhiyunwith NTFS" for details.
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunWeb site
41*4882a593Smuzhiyun========
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunThere is plenty of additional information on the linux-ntfs web site
44*4882a593Smuzhiyunat http://www.linux-ntfs.org/
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunThe web site has a lot of additional information, such as a comprehensive
47*4882a593SmuzhiyunFAQ, documentation on the NTFS on-disk format, information on the Linux-NTFS
48*4882a593Smuzhiyunuserspace utilities, etc.
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunFeatures
52*4882a593Smuzhiyun========
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun- This is a complete rewrite of the NTFS driver that used to be in the 2.4 and
55*4882a593Smuzhiyun  earlier kernels.  This new driver implements NTFS read support and is
56*4882a593Smuzhiyun  functionally equivalent to the old ntfs driver and it also implements limited
57*4882a593Smuzhiyun  write support.  The biggest limitation at present is that files/directories
58*4882a593Smuzhiyun  cannot be created or deleted.  See below for the list of write features that
59*4882a593Smuzhiyun  are so far supported.  Another limitation is that writing to compressed files
60*4882a593Smuzhiyun  is not implemented at all.  Also, neither read nor write access to encrypted
61*4882a593Smuzhiyun  files is so far implemented.
62*4882a593Smuzhiyun- The new driver has full support for sparse files on NTFS 3.x volumes which
63*4882a593Smuzhiyun  the old driver isn't happy with.
64*4882a593Smuzhiyun- The new driver supports execution of binaries due to mmap() now being
65*4882a593Smuzhiyun  supported.
66*4882a593Smuzhiyun- The new driver supports loopback mounting of files on NTFS which is used by
67*4882a593Smuzhiyun  some Linux distributions to enable the user to run Linux from an NTFS
68*4882a593Smuzhiyun  partition by creating a large file while in Windows and then loopback
69*4882a593Smuzhiyun  mounting the file while in Linux and creating a Linux filesystem on it that
70*4882a593Smuzhiyun  is used to install Linux on it.
71*4882a593Smuzhiyun- A comparison of the two drivers using::
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun	time find . -type f -exec md5sum "{}" \;
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun  run three times in sequence with each driver (after a reboot) on a 1.4GiB
76*4882a593Smuzhiyun  NTFS partition, showed the new driver to be 20% faster in total time elapsed
77*4882a593Smuzhiyun  (from 9:43 minutes on average down to 7:53).  The time spent in user space
78*4882a593Smuzhiyun  was unchanged but the time spent in the kernel was decreased by a factor of
79*4882a593Smuzhiyun  2.5 (from 85 CPU seconds down to 33).
80*4882a593Smuzhiyun- The driver does not support short file names in general.  For backwards
81*4882a593Smuzhiyun  compatibility, we implement access to files using their short file names if
82*4882a593Smuzhiyun  they exist.  The driver will not create short file names however, and a
83*4882a593Smuzhiyun  rename will discard any existing short file name.
84*4882a593Smuzhiyun- The new driver supports exporting of mounted NTFS volumes via NFS.
85*4882a593Smuzhiyun- The new driver supports async io (aio).
86*4882a593Smuzhiyun- The new driver supports fsync(2), fdatasync(2), and msync(2).
87*4882a593Smuzhiyun- The new driver supports readv(2) and writev(2).
88*4882a593Smuzhiyun- The new driver supports access time updates (including mtime and ctime).
89*4882a593Smuzhiyun- The new driver supports truncate(2) and open(2) with O_TRUNC.  But at present
90*4882a593Smuzhiyun  only very limited support for highly fragmented files, i.e. ones which have
91*4882a593Smuzhiyun  their data attribute split across multiple extents, is included.  Another
92*4882a593Smuzhiyun  limitation is that at present truncate(2) will never create sparse files,
93*4882a593Smuzhiyun  since to mark a file sparse we need to modify the directory entry for the
94*4882a593Smuzhiyun  file and we do not implement directory modifications yet.
95*4882a593Smuzhiyun- The new driver supports write(2) which can both overwrite existing data and
96*4882a593Smuzhiyun  extend the file size so that you can write beyond the existing data.  Also,
97*4882a593Smuzhiyun  writing into sparse regions is supported and the holes are filled in with
98*4882a593Smuzhiyun  clusters.  But at present only limited support for highly fragmented files,
99*4882a593Smuzhiyun  i.e. ones which have their data attribute split across multiple extents, is
100*4882a593Smuzhiyun  included.  Another limitation is that write(2) will never create sparse
101*4882a593Smuzhiyun  files, since to mark a file sparse we need to modify the directory entry for
102*4882a593Smuzhiyun  the file and we do not implement directory modifications yet.
103*4882a593Smuzhiyun
104*4882a593SmuzhiyunSupported mount options
105*4882a593Smuzhiyun=======================
106*4882a593Smuzhiyun
107*4882a593SmuzhiyunIn addition to the generic mount options described by the manual page for the
108*4882a593Smuzhiyunmount command (man 8 mount, also see man 5 fstab), the NTFS driver supports the
109*4882a593Smuzhiyunfollowing mount options:
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun======================= =======================================================
112*4882a593Smuzhiyuniocharset=name		Deprecated option.  Still supported but please use
113*4882a593Smuzhiyun			nls=name in the future.  See description for nls=name.
114*4882a593Smuzhiyun
115*4882a593Smuzhiyunnls=name		Character set to use when returning file names.
116*4882a593Smuzhiyun			Unlike VFAT, NTFS suppresses names that contain
117*4882a593Smuzhiyun			unconvertible characters.  Note that most character
118*4882a593Smuzhiyun			sets contain insufficient characters to represent all
119*4882a593Smuzhiyun			possible Unicode characters that can exist on NTFS.
120*4882a593Smuzhiyun			To be sure you are not missing any files, you are
121*4882a593Smuzhiyun			advised to use nls=utf8 which is capable of
122*4882a593Smuzhiyun			representing all Unicode characters.
123*4882a593Smuzhiyun
124*4882a593Smuzhiyunutf8=<bool>		Option no longer supported.  Currently mapped to
125*4882a593Smuzhiyun			nls=utf8 but please use nls=utf8 in the future and
126*4882a593Smuzhiyun			make sure utf8 is compiled either as module or into
127*4882a593Smuzhiyun			the kernel.  See description for nls=name.
128*4882a593Smuzhiyun
129*4882a593Smuzhiyunuid=
130*4882a593Smuzhiyungid=
131*4882a593Smuzhiyunumask=			Provide default owner, group, and access mode mask.
132*4882a593Smuzhiyun			These options work as documented in mount(8).  By
133*4882a593Smuzhiyun			default, the files/directories are owned by root and
134*4882a593Smuzhiyun			he/she has read and write permissions, as well as
135*4882a593Smuzhiyun			browse permission for directories.  No one else has any
136*4882a593Smuzhiyun			access permissions.  I.e. the mode on all files is by
137*4882a593Smuzhiyun			default rw------- and for directories rwx------, a
138*4882a593Smuzhiyun			consequence of the default fmask=0177 and dmask=0077.
139*4882a593Smuzhiyun			Using a umask of zero will grant all permissions to
140*4882a593Smuzhiyun			everyone, i.e. all files and directories will have mode
141*4882a593Smuzhiyun			rwxrwxrwx.
142*4882a593Smuzhiyun
143*4882a593Smuzhiyunfmask=
144*4882a593Smuzhiyundmask=			Instead of specifying umask which applies both to
145*4882a593Smuzhiyun			files and directories, fmask applies only to files and
146*4882a593Smuzhiyun			dmask only to directories.
147*4882a593Smuzhiyun
148*4882a593Smuzhiyunsloppy=<BOOL>		If sloppy is specified, ignore unknown mount options.
149*4882a593Smuzhiyun			Otherwise the default behaviour is to abort mount if
150*4882a593Smuzhiyun			any unknown options are found.
151*4882a593Smuzhiyun
152*4882a593Smuzhiyunshow_sys_files=<BOOL>	If show_sys_files is specified, show the system files
153*4882a593Smuzhiyun			in directory listings.  Otherwise the default behaviour
154*4882a593Smuzhiyun			is to hide the system files.
155*4882a593Smuzhiyun			Note that even when show_sys_files is specified, "$MFT"
156*4882a593Smuzhiyun			will not be visible due to bugs/mis-features in glibc.
157*4882a593Smuzhiyun			Further, note that irrespective of show_sys_files, all
158*4882a593Smuzhiyun			files are accessible by name, i.e. you can always do
159*4882a593Smuzhiyun			"ls -l \$UpCase" for example to specifically show the
160*4882a593Smuzhiyun			system file containing the Unicode upcase table.
161*4882a593Smuzhiyun
162*4882a593Smuzhiyuncase_sensitive=<BOOL>	If case_sensitive is specified, treat all file names as
163*4882a593Smuzhiyun			case sensitive and create file names in the POSIX
164*4882a593Smuzhiyun			namespace.  Otherwise the default behaviour is to treat
165*4882a593Smuzhiyun			file names as case insensitive and to create file names
166*4882a593Smuzhiyun			in the WIN32/LONG name space.  Note, the Linux NTFS
167*4882a593Smuzhiyun			driver will never create short file names and will
168*4882a593Smuzhiyun			remove them on rename/delete of the corresponding long
169*4882a593Smuzhiyun			file name.
170*4882a593Smuzhiyun			Note that files remain accessible via their short file
171*4882a593Smuzhiyun			name, if it exists.  If case_sensitive, you will need
172*4882a593Smuzhiyun			to provide the correct case of the short file name.
173*4882a593Smuzhiyun
174*4882a593Smuzhiyundisable_sparse=<BOOL>	If disable_sparse is specified, creation of sparse
175*4882a593Smuzhiyun			regions, i.e. holes, inside files is disabled for the
176*4882a593Smuzhiyun			volume (for the duration of this mount only).  By
177*4882a593Smuzhiyun			default, creation of sparse regions is enabled, which
178*4882a593Smuzhiyun			is consistent with the behaviour of traditional Unix
179*4882a593Smuzhiyun			filesystems.
180*4882a593Smuzhiyun
181*4882a593Smuzhiyunerrors=opt		What to do when critical filesystem errors are found.
182*4882a593Smuzhiyun			Following values can be used for "opt":
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun			  ========  =========================================
185*4882a593Smuzhiyun			  continue  DEFAULT, try to clean-up as much as
186*4882a593Smuzhiyun				    possible, e.g. marking a corrupt inode as
187*4882a593Smuzhiyun				    bad so it is no longer accessed, and then
188*4882a593Smuzhiyun				    continue.
189*4882a593Smuzhiyun			  recover   At present only supported is recovery of
190*4882a593Smuzhiyun				    the boot sector from the backup copy.
191*4882a593Smuzhiyun				    If read-only mount, the recovery is done
192*4882a593Smuzhiyun				    in memory only and not written to disk.
193*4882a593Smuzhiyun			  ========  =========================================
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun			Note that the options are additive, i.e. specifying::
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun			   errors=continue,errors=recover
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun			means the driver will attempt to recover and if that
200*4882a593Smuzhiyun			fails it will clean-up as much as possible and
201*4882a593Smuzhiyun			continue.
202*4882a593Smuzhiyun
203*4882a593Smuzhiyunmft_zone_multiplier=	Set the MFT zone multiplier for the volume (this
204*4882a593Smuzhiyun			setting is not persistent across mounts and can be
205*4882a593Smuzhiyun			changed from mount to mount but cannot be changed on
206*4882a593Smuzhiyun			remount).  Values of 1 to 4 are allowed, 1 being the
207*4882a593Smuzhiyun			default.  The MFT zone multiplier determines how much
208*4882a593Smuzhiyun			space is reserved for the MFT on the volume.  If all
209*4882a593Smuzhiyun			other space is used up, then the MFT zone will be
210*4882a593Smuzhiyun			shrunk dynamically, so this has no impact on the
211*4882a593Smuzhiyun			amount of free space.  However, it can have an impact
212*4882a593Smuzhiyun			on performance by affecting fragmentation of the MFT.
213*4882a593Smuzhiyun			In general use the default.  If you have a lot of small
214*4882a593Smuzhiyun			files then use a higher value.  The values have the
215*4882a593Smuzhiyun			following meaning:
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun			      =====	    =================================
218*4882a593Smuzhiyun			      Value	     MFT zone size (% of volume size)
219*4882a593Smuzhiyun			      =====	    =================================
220*4882a593Smuzhiyun				1		12.5%
221*4882a593Smuzhiyun				2		25%
222*4882a593Smuzhiyun				3		37.5%
223*4882a593Smuzhiyun				4		50%
224*4882a593Smuzhiyun			      =====	    =================================
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun			Note this option is irrelevant for read-only mounts.
227*4882a593Smuzhiyun======================= =======================================================
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun
230*4882a593SmuzhiyunKnown bugs and (mis-)features
231*4882a593Smuzhiyun=============================
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun- The link count on each directory inode entry is set to 1, due to Linux not
234*4882a593Smuzhiyun  supporting directory hard links.  This may well confuse some user space
235*4882a593Smuzhiyun  applications, since the directory names will have the same inode numbers.
236*4882a593Smuzhiyun  This also speeds up ntfs_read_inode() immensely.  And we haven't found any
237*4882a593Smuzhiyun  problems with this approach so far.  If you find a problem with this, please
238*4882a593Smuzhiyun  let us know.
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun
241*4882a593SmuzhiyunPlease send bug reports/comments/feedback/abuse to the Linux-NTFS development
242*4882a593Smuzhiyunlist at sourceforge: linux-ntfs-dev@lists.sourceforge.net
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun
245*4882a593SmuzhiyunUsing NTFS volume and stripe sets
246*4882a593Smuzhiyun=================================
247*4882a593Smuzhiyun
248*4882a593SmuzhiyunFor support of volume and stripe sets, you can either use the kernel's
249*4882a593SmuzhiyunDevice-Mapper driver or the kernel's Software RAID / MD driver.  The former is
250*4882a593Smuzhiyunthe recommended one to use for linear raid.  But the latter is required for
251*4882a593Smuzhiyunraid level 5.  For striping and mirroring, either driver should work fine.
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun
254*4882a593SmuzhiyunThe Device-Mapper driver
255*4882a593Smuzhiyun------------------------
256*4882a593Smuzhiyun
257*4882a593SmuzhiyunYou will need to create a table of the components of the volume/stripe set and
258*4882a593Smuzhiyunhow they fit together and load this into the kernel using the dmsetup utility
259*4882a593Smuzhiyun(see man 8 dmsetup).
260*4882a593Smuzhiyun
261*4882a593SmuzhiyunLinear volume sets, i.e. linear raid, has been tested and works fine.  Even
262*4882a593Smuzhiyunthough untested, there is no reason why stripe sets, i.e. raid level 0, and
263*4882a593Smuzhiyunmirrors, i.e. raid level 1 should not work, too.  Stripes with parity, i.e.
264*4882a593Smuzhiyunraid level 5, unfortunately cannot work yet because the current version of the
265*4882a593SmuzhiyunDevice-Mapper driver does not support raid level 5.  You may be able to use the
266*4882a593SmuzhiyunSoftware RAID / MD driver for raid level 5, see the next section for details.
267*4882a593Smuzhiyun
268*4882a593SmuzhiyunTo create the table describing your volume you will need to know each of its
269*4882a593Smuzhiyuncomponents and their sizes in sectors, i.e. multiples of 512-byte blocks.
270*4882a593Smuzhiyun
271*4882a593SmuzhiyunFor NT4 fault tolerant volumes you can obtain the sizes using fdisk.  So for
272*4882a593Smuzhiyunexample if one of your partitions is /dev/hda2 you would do::
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun    $ fdisk -ul /dev/hda
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun    Disk /dev/hda: 81.9 GB, 81964302336 bytes
277*4882a593Smuzhiyun    255 heads, 63 sectors/track, 9964 cylinders, total 160086528 sectors
278*4882a593Smuzhiyun    Units = sectors of 1 * 512 = 512 bytes
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun	Device Boot      Start         End      Blocks   Id  System
281*4882a593Smuzhiyun	/dev/hda1   *          63     4209029     2104483+  83  Linux
282*4882a593Smuzhiyun	/dev/hda2         4209030    37768814    16779892+  86  NTFS
283*4882a593Smuzhiyun	/dev/hda3        37768815    46170809     4200997+  83  Linux
284*4882a593Smuzhiyun
285*4882a593SmuzhiyunAnd you would know that /dev/hda2 has a size of 37768814 - 4209030 + 1 =
286*4882a593Smuzhiyun33559785 sectors.
287*4882a593Smuzhiyun
288*4882a593SmuzhiyunFor Win2k and later dynamic disks, you can for example use the ldminfo utility
289*4882a593Smuzhiyunwhich is part of the Linux LDM tools (the latest version at the time of
290*4882a593Smuzhiyunwriting is linux-ldm-0.0.8.tar.bz2).  You can download it from:
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun	http://www.linux-ntfs.org/
293*4882a593Smuzhiyun
294*4882a593SmuzhiyunSimply extract the downloaded archive (tar xvjf linux-ldm-0.0.8.tar.bz2), go
295*4882a593Smuzhiyuninto it (cd linux-ldm-0.0.8) and change to the test directory (cd test).  You
296*4882a593Smuzhiyunwill find the precompiled (i386) ldminfo utility there.  NOTE: You will not be
297*4882a593Smuzhiyunable to compile this yourself easily so use the binary version!
298*4882a593Smuzhiyun
299*4882a593SmuzhiyunThen you would use ldminfo in dump mode to obtain the necessary information::
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun    $ ./ldminfo --dump /dev/hda
302*4882a593Smuzhiyun
303*4882a593SmuzhiyunThis would dump the LDM database found on /dev/hda which describes all of your
304*4882a593Smuzhiyundynamic disks and all the volumes on them.  At the bottom you will see the
305*4882a593SmuzhiyunVOLUME DEFINITIONS section which is all you really need.  You may need to look
306*4882a593Smuzhiyunfurther above to determine which of the disks in the volume definitions is
307*4882a593Smuzhiyunwhich device in Linux.  Hint: Run ldminfo on each of your dynamic disks and
308*4882a593Smuzhiyunlook at the Disk Id close to the top of the output for each (the PRIVATE HEADER
309*4882a593Smuzhiyunsection).  You can then find these Disk Ids in the VBLK DATABASE section in the
310*4882a593Smuzhiyun<Disk> components where you will get the LDM Name for the disk that is found in
311*4882a593Smuzhiyunthe VOLUME DEFINITIONS section.
312*4882a593Smuzhiyun
313*4882a593SmuzhiyunNote you will also need to enable the LDM driver in the Linux kernel.  If your
314*4882a593Smuzhiyundistribution did not enable it, you will need to recompile the kernel with it
315*4882a593Smuzhiyunenabled.  This will create the LDM partitions on each device at boot time.  You
316*4882a593Smuzhiyunwould then use those devices (for /dev/hda they would be /dev/hda1, 2, 3, etc)
317*4882a593Smuzhiyunin the Device-Mapper table.
318*4882a593Smuzhiyun
319*4882a593SmuzhiyunYou can also bypass using the LDM driver by using the main device (e.g.
320*4882a593Smuzhiyun/dev/hda) and then using the offsets of the LDM partitions into this device as
321*4882a593Smuzhiyunthe "Start sector of device" when creating the table.  Once again ldminfo would
322*4882a593Smuzhiyungive you the correct information to do this.
323*4882a593Smuzhiyun
324*4882a593SmuzhiyunAssuming you know all your devices and their sizes things are easy.
325*4882a593Smuzhiyun
326*4882a593SmuzhiyunFor a linear raid the table would look like this (note all values are in
327*4882a593Smuzhiyun512-byte sectors)::
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun    # Offset into	Size of this	Raid type	Device		Start sector
330*4882a593Smuzhiyun    # volume	device						of device
331*4882a593Smuzhiyun    0		1028161		linear		/dev/hda1	0
332*4882a593Smuzhiyun    1028161		3903762		linear		/dev/hdb2	0
333*4882a593Smuzhiyun    4931923		2103211		linear		/dev/hdc1	0
334*4882a593Smuzhiyun
335*4882a593SmuzhiyunFor a striped volume, i.e. raid level 0, you will need to know the chunk size
336*4882a593Smuzhiyunyou used when creating the volume.  Windows uses 64kiB as the default, so it
337*4882a593Smuzhiyunwill probably be this unless you changes the defaults when creating the array.
338*4882a593Smuzhiyun
339*4882a593SmuzhiyunFor a raid level 0 the table would look like this (note all values are in
340*4882a593Smuzhiyun512-byte sectors)::
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun    # Offset   Size	    Raid     Number   Chunk  1st        Start	2nd	  Start
343*4882a593Smuzhiyun    # into     of the   type     of	      size   Device	in	Device	  in
344*4882a593Smuzhiyun    # volume   volume	     stripes			device		  device
345*4882a593Smuzhiyun    0	   2056320  striped  2	      128    /dev/hda1	0	/dev/hdb1 0
346*4882a593Smuzhiyun
347*4882a593SmuzhiyunIf there are more than two devices, just add each of them to the end of the
348*4882a593Smuzhiyunline.
349*4882a593Smuzhiyun
350*4882a593SmuzhiyunFinally, for a mirrored volume, i.e. raid level 1, the table would look like
351*4882a593Smuzhiyunthis (note all values are in 512-byte sectors)::
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun    # Ofs Size   Raid   Log  Number Region Should Number Source  Start Target Start
354*4882a593Smuzhiyun    # in  of the type   type of log size   sync?  of     Device  in    Device in
355*4882a593Smuzhiyun    # vol volume		 params		     mirrors	     Device	  Device
356*4882a593Smuzhiyun    0    2056320 mirror core 2	16     nosync 2	   /dev/hda1 0   /dev/hdb1 0
357*4882a593Smuzhiyun
358*4882a593SmuzhiyunIf you are mirroring to multiple devices you can specify further targets at the
359*4882a593Smuzhiyunend of the line.
360*4882a593Smuzhiyun
361*4882a593SmuzhiyunNote the "Should sync?" parameter "nosync" means that the two mirrors are
362*4882a593Smuzhiyunalready in sync which will be the case on a clean shutdown of Windows.  If the
363*4882a593Smuzhiyunmirrors are not clean, you can specify the "sync" option instead of "nosync"
364*4882a593Smuzhiyunand the Device-Mapper driver will then copy the entirety of the "Source Device"
365*4882a593Smuzhiyunto the "Target Device" or if you specified multiple target devices to all of
366*4882a593Smuzhiyunthem.
367*4882a593Smuzhiyun
368*4882a593SmuzhiyunOnce you have your table, save it in a file somewhere (e.g. /etc/ntfsvolume1),
369*4882a593Smuzhiyunand hand it over to dmsetup to work with, like so::
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun    $ dmsetup create myvolume1 /etc/ntfsvolume1
372*4882a593Smuzhiyun
373*4882a593SmuzhiyunYou can obviously replace "myvolume1" with whatever name you like.
374*4882a593Smuzhiyun
375*4882a593SmuzhiyunIf it all worked, you will now have the device /dev/device-mapper/myvolume1
376*4882a593Smuzhiyunwhich you can then just use as an argument to the mount command as usual to
377*4882a593Smuzhiyunmount the ntfs volume.  For example::
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun    $ mount -t ntfs -o ro /dev/device-mapper/myvolume1 /mnt/myvol1
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun(You need to create the directory /mnt/myvol1 first and of course you can use
382*4882a593Smuzhiyunanything you like instead of /mnt/myvol1 as long as it is an existing
383*4882a593Smuzhiyundirectory.)
384*4882a593Smuzhiyun
385*4882a593SmuzhiyunIt is advisable to do the mount read-only to see if the volume has been setup
386*4882a593Smuzhiyuncorrectly to avoid the possibility of causing damage to the data on the ntfs
387*4882a593Smuzhiyunvolume.
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun
390*4882a593SmuzhiyunThe Software RAID / MD driver
391*4882a593Smuzhiyun-----------------------------
392*4882a593Smuzhiyun
393*4882a593SmuzhiyunAn alternative to using the Device-Mapper driver is to use the kernel's
394*4882a593SmuzhiyunSoftware RAID / MD driver.  For which you need to set up your /etc/raidtab
395*4882a593Smuzhiyunappropriately (see man 5 raidtab).
396*4882a593Smuzhiyun
397*4882a593SmuzhiyunLinear volume sets, i.e. linear raid, as well as stripe sets, i.e. raid level
398*4882a593Smuzhiyun0, have been tested and work fine (though see section "Limitations when using
399*4882a593Smuzhiyunthe MD driver with NTFS volumes" especially if you want to use linear raid).
400*4882a593SmuzhiyunEven though untested, there is no reason why mirrors, i.e. raid level 1, and
401*4882a593Smuzhiyunstripes with parity, i.e. raid level 5, should not work, too.
402*4882a593Smuzhiyun
403*4882a593SmuzhiyunYou have to use the "persistent-superblock 0" option for each raid-disk in the
404*4882a593SmuzhiyunNTFS volume/stripe you are configuring in /etc/raidtab as the persistent
405*4882a593Smuzhiyunsuperblock used by the MD driver would damage the NTFS volume.
406*4882a593Smuzhiyun
407*4882a593SmuzhiyunWindows by default uses a stripe chunk size of 64k, so you probably want the
408*4882a593Smuzhiyun"chunk-size 64k" option for each raid-disk, too.
409*4882a593Smuzhiyun
410*4882a593SmuzhiyunFor example, if you have a stripe set consisting of two partitions /dev/hda5
411*4882a593Smuzhiyunand /dev/hdb1 your /etc/raidtab would look like this::
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun    raiddev /dev/md0
414*4882a593Smuzhiyun	    raid-level	0
415*4882a593Smuzhiyun	    nr-raid-disks	2
416*4882a593Smuzhiyun	    nr-spare-disks	0
417*4882a593Smuzhiyun	    persistent-superblock	0
418*4882a593Smuzhiyun	    chunk-size	64k
419*4882a593Smuzhiyun	    device		/dev/hda5
420*4882a593Smuzhiyun	    raid-disk	0
421*4882a593Smuzhiyun	    device		/dev/hdb1
422*4882a593Smuzhiyun	    raid-disk	1
423*4882a593Smuzhiyun
424*4882a593SmuzhiyunFor linear raid, just change the raid-level above to "raid-level linear", for
425*4882a593Smuzhiyunmirrors, change it to "raid-level 1", and for stripe sets with parity, change
426*4882a593Smuzhiyunit to "raid-level 5".
427*4882a593Smuzhiyun
428*4882a593SmuzhiyunNote for stripe sets with parity you will also need to tell the MD driver
429*4882a593Smuzhiyunwhich parity algorithm to use by specifying the option "parity-algorithm
430*4882a593Smuzhiyunwhich", where you need to replace "which" with the name of the algorithm to
431*4882a593Smuzhiyunuse (see man 5 raidtab for available algorithms) and you will have to try the
432*4882a593Smuzhiyundifferent available algorithms until you find one that works.  Make sure you
433*4882a593Smuzhiyunare working read-only when playing with this as you may damage your data
434*4882a593Smuzhiyunotherwise.  If you find which algorithm works please let us know (email the
435*4882a593Smuzhiyunlinux-ntfs developers list linux-ntfs-dev@lists.sourceforge.net or drop in on
436*4882a593SmuzhiyunIRC in channel #ntfs on the irc.freenode.net network) so we can update this
437*4882a593Smuzhiyundocumentation.
438*4882a593Smuzhiyun
439*4882a593SmuzhiyunOnce the raidtab is setup, run for example raid0run -a to start all devices or
440*4882a593Smuzhiyunraid0run /dev/md0 to start a particular md device, in this case /dev/md0.
441*4882a593Smuzhiyun
442*4882a593SmuzhiyunThen just use the mount command as usual to mount the ntfs volume using for
443*4882a593Smuzhiyunexample::
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun    mount -t ntfs -o ro /dev/md0 /mnt/myntfsvolume
446*4882a593Smuzhiyun
447*4882a593SmuzhiyunIt is advisable to do the mount read-only to see if the md volume has been
448*4882a593Smuzhiyunsetup correctly to avoid the possibility of causing damage to the data on the
449*4882a593Smuzhiyunntfs volume.
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun
452*4882a593SmuzhiyunLimitations when using the Software RAID / MD driver
453*4882a593Smuzhiyun-----------------------------------------------------
454*4882a593Smuzhiyun
455*4882a593SmuzhiyunUsing the md driver will not work properly if any of your NTFS partitions have
456*4882a593Smuzhiyunan odd number of sectors.  This is especially important for linear raid as all
457*4882a593Smuzhiyundata after the first partition with an odd number of sectors will be offset by
458*4882a593Smuzhiyunone or more sectors so if you mount such a partition with write support you
459*4882a593Smuzhiyunwill cause massive damage to the data on the volume which will only become
460*4882a593Smuzhiyunapparent when you try to use the volume again under Windows.
461*4882a593Smuzhiyun
462*4882a593SmuzhiyunSo when using linear raid, make sure that all your partitions have an even
463*4882a593Smuzhiyunnumber of sectors BEFORE attempting to use it.  You have been warned!
464*4882a593Smuzhiyun
465*4882a593SmuzhiyunEven better is to simply use the Device-Mapper for linear raid and then you do
466*4882a593Smuzhiyunnot have this problem with odd numbers of sectors.
467