ntfs.txt 20 KB

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