NTFS: Difference between revisions

From NixOS Wiki
imported>XBLACKICEx
No edit summary
imported from old wiki
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
== Enable NTFS support ==
New Technology File System (NTFS) is a proprietary journaling file system developed by Microsoft. It is still in use by modern Windows system, although NTFS didnt evolve since the release of version 3.1 in 2001.
 
== Enable NTFS support at boot ==
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
boot.supportedFilesystems = [ "ntfs3" ];
boot.supportedFilesystems = [ "ntfs" ];
</syntaxHighlight>
</syntaxHighlight>


Line 7: Line 9:


=== Enable write mode ===
=== Enable write mode ===
<syntaxHighlight lang=nix>
<syntaxhighlight lang="nixos">
   fileSystems."/path/to/mount/to" =
   fileSystems."/path/to/mount/to" =
     { device = "/path/to/the/device";
     { device = "/path/to/the/device";
       fsType = "ntfs";  
       fsType = "ntfs-3g";  
       options = [ "rw" "uid=theUidOfYourUser"];
       options = [ "rw" "uid=theUidOfYourUser"];
     };
     };
</syntaxhighlight>
== Mount NTFS filesystem ==
<syntaxHighlight lang=sh>
# mount /dev/sdeX /mnt -t ntfs3
</syntaxHighlight>
</syntaxHighlight>
== Mount NTFS filesystem on boot ==
# Add NTFS support to ''/etc/nixos/configuration.nix'' (see [[#Enable NTFS support at boot]] above)
#Run the following commands<syntaxhighlight lang="bash">
# Apply new config on next boot
sudo nixos-rebuild boot
# Reboot your system
reboot
# Mount the hard drive. Replace X & /mnt/folder as needed
mount /dev/sdX /mnt/folder -t ntfs3
# Generate /etc/nixos/hardware-configuration.nix
nixos-generate-config
</syntaxhighlight>
# Edit ''/etc/nixos/hardware-configuration.nix''<syntaxhighlight lang="diff">
  # /etc/nixos/hardware-configuration.nix
  # Your /dev/disk/by/uuid/... and /mnt/folder will have different names!
  fileSystems."/mnt/folder" =
      { device = "/dev/disk/by-uuid/7997ef90-6333-4c60-b137-d5cf2423e91b";
-      fsType = "ntfs3";
+      fsType = "ntfs-3g";
+      options = [ "rw" "uid=UID"];
      };
</syntaxhighlight>''Note: you can quickly find your UID by running '''echo $UID'''''
#Run '''nixos-rebuild switch'''
#Done!


== Troubleshooting ==
== Troubleshooting ==
Line 39: Line 75:
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 what is the fast startup mode, and how to disable it.
[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.
 
[[Category:Filesystem]]

Latest revision as of 08:34, 27 September 2024

New Technology File System (NTFS) is a proprietary journaling file system developed by Microsoft. It is still in use by modern Windows system, although NTFS didnt evolve since the release of version 3.1 in 2001.

Enable NTFS support at boot

boot.supportedFilesystems = [ "ntfs" ];

NixOS uses NTFS-3G for NTFS support.

Enable write mode

  fileSystems."/path/to/mount/to" =
    { device = "/path/to/the/device";
      fsType = "ntfs-3g"; 
      options = [ "rw" "uid=theUidOfYourUser"];
    };

Mount NTFS filesystem

# mount /dev/sdeX /mnt -t ntfs3

Mount NTFS filesystem on boot

  1. Add NTFS support to /etc/nixos/configuration.nix (see #Enable NTFS support at boot above)
  2. Run the following commands
    # Apply new config on next boot
    sudo nixos-rebuild boot
    # Reboot your system
    reboot
    
    # Mount the hard drive. Replace X & /mnt/folder as needed
    mount /dev/sdX /mnt/folder -t ntfs3
    
    # Generate /etc/nixos/hardware-configuration.nix
    nixos-generate-config
    
  3. Edit /etc/nixos/hardware-configuration.nix
      # /etc/nixos/hardware-configuration.nix
    
      # Your /dev/disk/by/uuid/... and /mnt/folder will have different names!
      fileSystems."/mnt/folder" =
          { device = "/dev/disk/by-uuid/7997ef90-6333-4c60-b137-d5cf2423e91b";
    -       fsType = "ntfs3";
    +       fsType = "ntfs-3g";
    +       options = [ "rw" "uid=UID"];
          };
    
    Note: you can quickly find your UID by running echo $UID
  4. Run nixos-rebuild switch
  5. Done!

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.