Format an NTFS Drive in Linux
Here's how to format an NTFS Drive in Linux.
Use case
You have a new HDD or SSD, and you want to be able to share it amongst some Linux, Windows or MacOs hosts.
You might choose to format it with the NTFS filesystem. It is probably one of the better options for cross-platform support.
To make this happen, in the end, we'll want a hard drive with a partition with a filesystem mounted to our computer.
See the disks
First, plug in your new disk. To see the disks, run:
lsblk
You'll see a device like /dev/sda
(HDD) or /dev/nvme0n1
(SSD). Make note of the appropriate device name.
Create a partition
If it's a new disk, it won't have a partition. If it had, lsblk
would show it as /dev/sda1
or something like that.
To create a new partition, start the parted
utility with sudo parted /dev/sda
, then these commands:
parted
mklabel gpt
unit TB
mkpart primary 0.00TB 4.00TB
mklabel gpt
will designate the layout of the partition table as GPT or "Guid Partition Table".
mkpart
will create a single primary partition of 4TB. Adjust this to your disk size. Note that this works, no problem, with disks over 2TB in size (you'd have a problem in the case of FAT32, for instance).
Format the partition as NTFS
Now it's time to format the partition. There's a linux-compatible NTFS implementation called ntfs-3g
. It uses FUSE, "file system in user space", to allow creating new filesystems without editing the kernel. To install:
sudo apt install ntfs-3g
To format, run:
sudo mkntfs --fast --label MyCoolNewDisk /dev/sda1
Note that we created a volume label for easy identification when it's mounted later. And we're targeting the partition we just made previously (ie, /dev/sda1
).
Mount the NTFS partition
Now you want to mount the partition to your system's filesystem so that you can run file operations on it, like copy over some files. To mount:
sudo mkdir /mnt/drv
sudo mount -t ntfs /dev/sda1 /mnt/drv
Check space available
As you go, see what kind of space you have left:
df -BG
-BG
prints the block sizes in gigabytes.
This is how I format NTFS drives. Do you do anything differently?
Read disk on Windows computer
Formatting this way works fine, and it's easily readable from a Linux computer. But when I try to mount the drive on a Windows computer, it's not recognized. If I pull up the Disk Management utility, the disk is there, it has a partition, but there are no volumes.
But by now I have data on the disk, so I don't want to reformat it. What can I do? According to this Unix Stackexchange article, there's a way.
The reason it's not recognized and mounted to a drive letter on Windows is that its partition table type isn't recognized by Windows, so it's ignored.
Connec the disk to a Linux computer, and run:
lsblk
Once you know the disk device identifier (eg, /dev/sda
), run:
sudo fdisk /dev/sda
This will enter into the interactive fdisk prompt. There, type p
to see the partition table:
Command (m for help): p
Disk /dev/sda: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: ASM1156
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: D50042E8-8944-4887-B899-E6A6B4207CDF
Device Start End Sectors Size Type
/dev/sda1 2048 7814035455 7814033408 3.6T Linux filesystem
Note the "Type: Linux filesystem". We want to change this partition type. Press t
to change it, then L
to list all the potential partition types:
Command (m for help): t
Selected partition 1
Partition type or alias (type L to list all):
...
11 Microsoft basic data EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
...
Which one do we we want? Looking at the wikipedia for "Microsoft basic data partition", that's probably the one we want because it encompasses NTFS:
Microsoft operating systems, when using basic disk partitioned with GUID Partition Table (GPT) layout, a basic data partition (BDP) is any partition identified with Globally Unique Identifier (GUID) of EBD0A0A2-B9E5-4433-87C0-68B6B72699C7.
We press 11
to select it, then w
to write the changes to disk:
Command (m for help): w
The partition table has been altered!
After it's written, we can see the difference with p
:
Command (m for help): p
Disk /dev/sda: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: ASM1156
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: D50042E8-8944-4887-B899-E6A6B4207CDF
Device Start End Sectors Size Type
/dev/sda1 2048 7814035455 7814033408 3.6T Microsoft basic data
Looks good. Unmount from Linux, plug that thing into Windows.
When I first did this, I was disappointed because it didn't show up for quite some time, but then, almost magically, it showed up and was assigned a drive letter, and I could see it in Windows Explorer. I'm not sure the reason for the delay, but the solution to change the partition type worked.