NTFS: Difference between revisions
Category:Filesystem. Sentence at the beginning. |
→Troubleshooting: adds section on dirty flag |
||
| (9 intermediate revisions by 5 users not shown) | |||
| Line 1: | Line 1: | ||
New Technology File System (NTFS) is a proprietary journaling file system developed by Microsoft. It is still in use by modern Windows | New Technology File System (NTFS) is a proprietary journaling [[Filesystems|file system]] developed by Microsoft. It is still in use by modern Windows systems, although NTFS has not evolved since the release of version 3.1 in 2001. | ||
== Mount NTFS filesystem on boot == | == Mount NTFS filesystem on boot == | ||
Using [[nixos-generate-config]] to automatically generate Nix config is the recommended way to setup filesystems. | |||
1. Run {{ic|lsblk}} to list device names. | |||
nixos-generate-config | {{code| | ||
</ | sd... | ||
└─sdX | |||
}} | |||
2. Mount the device using [https://man7.org/linux/man-pages/man8/mount.8.html {{ic|mount}}], where {{ic|/dev/sdX}} replaced with your device name and {{ic|/mnt/sdX}} replaced with an existing folder path to mount your drive. | |||
{{code|<nowiki>mount /dev/sdX /mnt/sdX -t ntfs3 -o uid=$UID</nowiki>}} | |||
3. Run {{ic|nixos-generate-config --dir .}} to generate hardware configuration. This will <strong>automatically</strong> add all currently mounted devices to {{ic|hardware-configuration.nix}}. | |||
{{file|/etc/nixos/hardware-configuration.nix|diff|3= | |||
+ boot.supportedFilesystems = [ "ntfs" ]; | |||
+ fileSystems."/mnt/sdX" = { | |||
+ device = "/dev/disk/by-uuid/F258FB9E58FB5FB1"; | |||
+ fsType = "ntfs3"; | |||
+ }; | |||
}} | |||
4. Add {{ic|<nowiki>"uid=$UID"</nowiki>}} to {{nixos:option|fileSystems.*.options|fileSystems.<name>.options}} to get write access, where {{ic|<nowiki>$UID</nowiki>}} <strong>replaced with your UID</strong>: | |||
{{file|/etc/nixos/configuration.nix|nix|3= | |||
fileSystems = | |||
let | |||
ntfs-drives = [ | |||
"/mnt/sdX" | |||
]; | |||
in | |||
lib.genAttrs ntfs-drives (path: { | |||
options = [ | |||
"uid=$UID" # REPLACE "$UID" WITH YOUR ACTUAL UID! | |||
# "nofail" | |||
]; | |||
}); | |||
}} | |||
{{note|You may find your UID by running {{ic|echo $UID}}.}} | |||
{{aside|It is not recommended to manually edit {{ic|hardware-configuration.nix}}.}} | |||
5. {{evaluate}} | |||
== Troubleshooting == | == Troubleshooting == | ||
| Line 75: | Line 64: | ||
If you have shutdown Windows fully, and not used hibernation, it may be caused by the <em>fast startup</em> or <em>fast boot</em> feature of Windows. It has been reported that major Windows updates may reset this setting to <strong>on</strong>. | If you have shutdown Windows fully, and not used hibernation, it may be caused by the <em>fast startup</em> or <em>fast boot</em> feature of Windows. It has been reported that major Windows updates may reset this setting to <strong>on</strong>. | ||
[https://social.technet.microsoft.com/wiki/contents/articles/25908.fast-startup-how-to-disable-if-it-s-causing-problems.aspx This TechNet entry] explains how to disable fast startup. Additionally, [https://www.howtogeek.com/243901/the-pros-and-cons-of-windows-10s-fast-startup-mode/ this blog post on howtogeek.com] explains | [https://social.technet.microsoft.com/wiki/contents/articles/25908.fast-startup-how-to-disable-if-it-s-causing-problems.aspx This TechNet entry] explains how to disable fast startup. Additionally, [https://www.howtogeek.com/243901/the-pros-and-cons-of-windows-10s-fast-startup-mode/ this blog post on howtogeek.com] explains how the fast startup mode works, and how to disable it. | ||
=== Unable to mount ntfs3 with dirty volume === | |||
When attempting to mount an <code>NTFS</code> partition using the <code>ntfs3</code> filesystem driver via the {{nixos:package|ntfs3g}} package, the mount operation may fail: | |||
<syntaxhighlight lang="console"> | |||
# mount /dev/sda1 /mnt -t ntfs3 | |||
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error. | |||
dmesg(1) may have more information after failed mount system call. | |||
</syntaxhighlight> | |||
With the resulting dmesg output: | |||
<syntaxhighlight lang="console"> | |||
# dmesg | |||
... | |||
[168659.819978] ntfs3: sda1: It is recommened to use chkdsk. | |||
[168659.820833] ntfs3: sda1: volume is dirty and "force" flag is not set! | |||
</syntaxhighlight> | |||
This indicates that the NTFS volume has the “dirty” flag set. In this state, the <code>ntfs3</code> driver refuses to mount the filesystem. | |||
To clear the dirty flag, run <code>ntfsfix</code> on the affected partition: | |||
<syntaxhighlight lang="console"> | |||
# ntfsfix --clear-dirty /dev/sda1 | |||
</syntaxhighlight> | |||
If <code>ntfsfix</code> fails with an error <code>Windows is hibernated, refused to mount</code>, the partition can be mounted using <code>ntfs-3g</code> with the hibernation file removed: | |||
<syntaxhighlight lang="console"> | |||
# ntfs-3g -o remove_hiberfile /dev/sda1 /mnt | |||
</syntaxhighlight> | |||
[[Category:Filesystem]] | [[Category:Filesystem]] | ||
Latest revision as of 04:03, 2 January 2026
New Technology File System (NTFS) is a proprietary journaling file system developed by Microsoft. It is still in use by modern Windows systems, although NTFS has not evolved since the release of version 3.1 in 2001.
Mount NTFS filesystem on boot
Using nixos-generate-config to automatically generate Nix config is the recommended way to setup filesystems.
1. Run lsblk to list device names.
sd...
└─sdX2. Mount the device using mount, where /dev/sdX replaced with your device name and /mnt/sdX replaced with an existing folder path to mount your drive.
mount /dev/sdX /mnt/sdX -t ntfs3 -o uid=$UID3. Run nixos-generate-config --dir . to generate hardware configuration. This will automatically add all currently mounted devices to hardware-configuration.nix.
+ boot.supportedFilesystems = [ "ntfs" ];
+ fileSystems."/mnt/sdX" = {
+ device = "/dev/disk/by-uuid/F258FB9E58FB5FB1";
+ fsType = "ntfs3";
+ };
4. Add "uid=$UID" to fileSystems.<name>.options to get write access, where $UID replaced with your UID:
fileSystems =
let
ntfs-drives = [
"/mnt/sdX"
];
in
lib.genAttrs ntfs-drives (path: {
options = [
"uid=$UID" # REPLACE "$UID" WITH YOUR ACTUAL UID!
# "nofail"
];
});
echo $UID.hardware-configuration.nix.
5.
$ nixos-rebuild switch --sudo
Troubleshooting
Read-only file system
This is most likely caused by Windows not marking the disk as "clean" and unmounted.
To verify:
journalctl -b0 | grep -i "The disk contains an unclean file system"
It should return a similar message to what follows:
The disk contains an unclean file system (0,0). Metadata kept in Windows cache, refused to mount. Falling back to read-only mount because the NTFS partition is in an unsafe state. Please resume and shutdown Windows fully (no hibernation or fast restarting.)
If you have shutdown Windows fully, and not used hibernation, it may be caused by the fast startup or fast boot feature of Windows. It has been reported that major Windows updates may reset this setting to on.
This TechNet entry explains how to disable fast startup. Additionally, this blog post on howtogeek.com explains how the fast startup mode works, and how to disable it.
Unable to mount ntfs3 with dirty volume
When attempting to mount an NTFS partition using the ntfs3 filesystem driver via the ntfs3g package, the mount operation may fail:
# mount /dev/sda1 /mnt -t ntfs3
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.
dmesg(1) may have more information after failed mount system call.
With the resulting dmesg output:
# dmesg
...
[168659.819978] ntfs3: sda1: It is recommened to use chkdsk.
[168659.820833] ntfs3: sda1: volume is dirty and "force" flag is not set!
This indicates that the NTFS volume has the “dirty” flag set. In this state, the ntfs3 driver refuses to mount the filesystem.
To clear the dirty flag, run ntfsfix on the affected partition:
# ntfsfix --clear-dirty /dev/sda1
If ntfsfix fails with an error Windows is hibernated, refused to mount, the partition can be mounted using ntfs-3g with the hibernation file removed:
# ntfs-3g -o remove_hiberfile /dev/sda1 /mnt