NTFS

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page NTFS and the translation is 10% complete.
Outdated translations are marked like this.
Nicht zu verwechseln mit NFS.


NTFS (New Technology File System) ist ein proprietäres Festplatten Dateisystem von Microsoft für Windows und Windows-based Betriebssystemen.

Es gibt zwei wesentliche Methoden um NTFS Support auf Linux zu erreichen. Linux Kernel 5.15 stellt den neuen NTFSv3 Treiber mit vollen NTFS Support inklusive Kompression Fähigkeiten bereit. Auch existiert ein FUSE Dateisystem Treiber genannt NTFS-3G - ein langsamerer aber stabilere und bewährte Lösung.

Installation

Kernel

Before Linux kernel 5.15, the mainlined old NTFS kernel driver had very limited functional support for NTFS. The kernel configuration information defines support as "partial, but safe". The old driver could overwrite existing files but is not capable of file or directory creation, deletion, or renaming. As of Linux 5.15 the old NTFS code was replaced by new Paragon's in-kernel NTFS driver named "NTFSv3". This driver is more fully featured and supports full read/write and compression capabilities.

Most NTFS users will want to enable the FUSE-powered NTFS-3G implementation for systems running pre-5.15 kernels.

Native Unterstützung

On Linux 5.15 and later following kernel options must be enabled for new NTFSv3 driver:

KERNEL Enabling new NTFSv3 driver with optional support for reading Windows compressed files (lxz/xpress) (CONFIG_NTFS3_FS, CONFIG_NTFS3_LZX_XPRESS)
File systems  --->
    DOS/FAT/NT Filesystems  --->
        <*> NTFS Read-Write file system support Search for <code>CONFIG_NTFS3_FS</code> to find this item.
        <*> activate support of external compressions lzx/xpress Search for <code>CONFIG_NTFS3_LZX_XPRESS</code> to find this item.

NTFS-3G (FUSE-Implementierung)

The following kernel options must be enabled for NTFS read/write capabilities over FUSE in Linux before 5.15:

KERNEL Enabling NTFS over FUSE using NTFS-3G (CONFIG_FUSE_FS)
File systems  --->
    <*> FUSE (Filesystem in Userspace) support Search for <code>CONFIG_FUSE_FS</code> to find this item.

The sys-fs/ntfs3g package is also required (see the emerge section below).

Emerge

NTFS-3G

Wichtig
The following package is only necessary when using NTFS-3G. It is not required for native support!

Because NTFS-3G is a FUSE-based filesystem, it requires user space utilities. FUSE is short for Filesystem in Userspace, which has certain disadvantages compared to a filesystem driver in kernelspace, namely less performance.

If you experience "read only filesystem" errors, it may be necessary to enable the suid USE flag.

USE flags for sys-fs/ntfs3g Open source read-write NTFS driver that runs under FUSE

+fuse Enable ntfs-3g FUSE driver
+mount-ntfs Install mount.ntfs symlink
+ntfsprogs Enable ntfsprogs
acl Add support for Access Control Lists
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
ntfsdecrypt Build and install the ntfsdecrypt application.
static-libs Build static versions of dynamic libraries as well
suid Enable setuid root program(s)
xattr Add support for extended attributes (filesystem-stored metadata)

After reviewing USE flags and making adjustments as necessary, install the FUSE user space tools. This will enable the manipulation of NTFS filesystems:

root #emerge --ask sys-fs/ntfs3g

Usage

Creation

Warnung
The mkfs.ntfs command irreversibly destroys the contents of the partition it is told to format. Be sure to select the right partition before running this command!

To create an NTFS filesystem on the /dev/sda1 partition (needs ntfsprogs USE flag):

root #mkfs.ntfs /dev/sdyX

Please replace /dev/sdyX with the actual partition you want to format.

Mount

There are several ways to mount a NTFS filesystem:

Native support

Using the native NTFS3 driver that is included in Linux kernel 5.15 and newer:

root #mount -t ntfs3 /dev/device /path/to/mountpoint
Hinweis
Running mount /dev/device /path/to/mountpoint may fail even when the ntfs3 driver is loaded. One reason could be that the line ntfs3 is not present in /etc/filesystems, which may be the desired preset. In this case simply ensure the command is executed with -t ntfs3.

FUSE (NTFS-3G)

Using the read/write capable driver provided by the ntfs3g package:

root #mount -t ntfs-3g /dev/device /path/to/mountpoint

BitLocker

Linux dm-crypt has native support for BitLocker and BitLocker to Go, except for very old variants (such as Windows Vista). While cryptsetup can read the BitLocker header bitlk, the main requirement is that the Linux kernel must have support for the encryption algorithm in use.

Tipp
For further details on dm-crypt, refer to the corresponding manpages: cryptsetup (8), crypttab (5)

To use a Windows filesystem that is BitLocker encrypted on Linux, the first step is to get the BitLocker recovery key for that volume in Microsoft Windows. Example for such a recovery key:

DATEI 00112233-4455-6677-8899-AABBCCDDEEFF.keyBitLocker recovery key for specific volume UUID
001122-334455-667788-990011-223344-556677-890123-456789
Tipp
Consult Microsoft's support infrastructure on how to get the unique BitLocker recovery key. At the time of this writing, the following support webpage describes the process for Windows 10 and 11: Find your BitLocker recovery key.

On Linux, cryptsetup can automatically decrypt volumes that are configured in /etc/crypttab. When using a systemd profile, see sys-fs/cryptsetup configuration for a persistent configuration (i.e. automatic BitLocker decryption on start-up).

First, store the recovery key in a file. A convenient place to store encryption keys could be e.g. /etc/cryptsetup-keys.d. If the Windows' BitLocker volume ID was, as in the above example, 00112233-4455-6677-8899-AABBCCDDEEFF, you may want to create /etc/cryptsetup-keys.d/00112233-4455-6677-8899-AABBCCDDEEFF.key.

root #mkdir /etc/cryptsetup-keys.d
root #echo 001122-334455-667788-990011-223344-556677-890123-456789 > /etc/cryptsetup-keys.d/00112233-4455-6677-8899-AABBCCDDEEFF.key
Warnung
{{{1}}}

Next, find the BitLocker partition identification. This can be anything supported by Linux, such as any UUID or LABEL. The following example uses the partition UUID, identified with gdisk (alternatively parted may be used) and lsblk:

root #gdisk -l /dev/nvme0n1
root #lsblk -o +PARTUUID

In the above example we can see that the Windows partition is partition number 3, /dev/nvme0n1p3, and that its partition UUID or PARTUUID is 00112233-aabb-4455-ccdd-66778899eeff. Note that this partition UUID is different from the volume UUID given by BitLocker on Windows.

Then, reference the recovery key file, which stores the key in plain text format, in /etc/crypttab:

DATEI /etc/crypttabcrypttab configuration
windows_bitlk  PARTUUID=00112233-aabb-4455-ccdd-66778899eeff  /etc/cryptsetup-keys.d/00112233-4455-6677-8899-AABBCCDDEEFF.key  bitlk,discard,nofail
Hinweis
It will also work to use the device path, e.g. /dev/nvme0n1p3, directly, instead of the partition UUID, e.g. PARTUUID=00112233-aabb-4455-ccdd-66778899eeff, but with the disadvantage that updating the various configuration files is required with certain modifications to the system configuration, like changing device numbers: nvme0n1 may become nvme1n1 when SSDs are moved or an SSD is added. Also, you may choose a different name for the the mapper device, in the example windows_bitlk, as well as the name for the file containing the BitLocker recovery key, e.g. instead of the BitLocker UUID assigned by Windows you might want to name the file specific to its purpose, like Windows-BitLocker-volume.key or Additional-Data-Volume-BitLocker.key. Make sure to change the designations in the examples to those actually used on your system.

For /etc/crypttab, you may add/remove options to your linking. E.g. the nofail option prevents a systemd startup error in case the BitLocker volume is unavailable for some reason. Without it the system boot-up will, in the case that BitLocker decryption fails, halt, giving access only to a systemd rescue shell.

To automatically mount a BitLocker encrypted NTFS partition, /etc/fstab must be configured as well. The NTFS partition must refer to its decrypted cryptsetup name, e.g. /dev/mapper/windows_bitlk. An example could be:

DATEI /etc/fstabfstab NTFS BitLocker example
/dev/mapper/windows_bitlk  /mnt/windows  ntfs3  noatime,discard,sys_immutable,showmeta,acl,hidden,hide_dot_files,nofail  0 0

As in /etc/crypttab, in /etc/fstab the nofail option again prevents errors in case the BitLocker decryption failed for some reason or when the NTFS partition happens to be dirty, i.e. to prevent filesystem corruption the NTFS partition would not be mounted, but at the same time the startup with systemd will not fail.

After the next reboot the Windows NTFS partition should be both decrypted and mounted. The BitLocker volume can, however, also be decrypted on a running system, without a reboot:

root #cryptsetup open --type bitlk --allow-discards --key-file /etc/cryptsetup-keys.d/00112233-4455-6677-8899-AABBCCDDEEFF.key /dev/nvme0n1p3 windows_bitlk
root #mount /mnt/windows

Thereafter every operation on the NTFS partition may be started as with any regular (unencrypted) volume:

root #umount /mnt/windows
root #ntfsfix -n /dev/mapper/windows_bitlk

Troubleshooting

NTFS-3G

Force mount NTFS partition after Windows was hibernated

NTFS file systems controlled by Windows may be hibernated instead of cleanly shutdown in order to save on system start times. When this occurs it will not be possible to mount the NTFS partition unless the hiberfil.sys file is removed. The following command can be used to force-mount a hibernated partition, which will result in the hiberfile being removed; all data in the file will be lost. Windows will have to perform a clean boot in order to resume operation:

root #mount -t ntfs-3g -o remove_hiberfile /path/to/device /path/to/mountpoint

On the Windows system, in order to prevent unclean shutdowns from Windows it is possible to run powercfg /h off from an Administrator command prompt. This will disable hibernation which will most likely increase boot times when booting Windows, but has the benefit of cleanly unmounting the drive.

Tipp
{{{1}}}

ntfsfix

Occasionally it is necessary to fix an NTFS formatted partition from a Linux system. ntfsfix is the tool for the job:

root #ntfsfix /dev/nvme0n1p3

See also

External resources

References