In the Linux world, Filesystems are used for managing data stored on the storage devices. A Filesystem maintains a map to locate each file placed in the storage device. A Linux Filesystem, therefore, shows how to locate files and directories contained within it. Linux system uses Virtual Directory structure, which contains file paths from all the storage devices installed on the system consolidated into a single directory structure.
Mounting a Filesystem refers to the process of adding a formatted drive partition into the virtual directory on a Linux system. Mounting a Filesystem can be done either manually or automatically at boot time by Linux System.
Unmounting a Filesystem is the process of removing a mounted device from the virtual directory on a Linux System.
Several Filesystems types exist. Linux Filesystems have the ability to create a Filesystem across multiple devices. Filesystem types include btrfs, ext3, ext4, reisersfs, ecryptfs, and swap. The default Filesystem for Linux Systems is ext4.
With that brief background, we will now turn our attention to How to mount and unmount NTFS Filesystem on Rocky Linux 9.
NTFS (New Technology File System) is the default Windows technology for storing, organizing, and finding files on the storage device. In this article we will answer the question How a Linux system is able to access the data on a formatted device using NTFS which is a Windows Technology.
To be able to mount an NTFS Filesystem on Rocky Linux, you need the following
Requirements for Mounting NTFS Filesystem
To mount NTFS on Rocky Linux 9, ensure you have the following:
- A Linux system
- An NTFS formatted hard drive.
To be able to mount an NTFS filesystem on Rocky Linux carry out the steps below.
Step 1: update your Linux System
This is the best practice before any installation.
sudo dnf -y update
Step 2: Enable EPEL repository
EPEL has packages that ensure NTFS is accessible in Linux systems. Once the extra packages are installed in your Rocky Linux, you will be able to access the storage device formatted using NTFS. The latest EPEL release is release 9.
To download and install the packages in your Linux System:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
To verify the installation:
yum repolist | grep epel
Command output :
pel Extra Packages for Enterprise Linux 9 - x86_64
epel-cisco-openh264 Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64
Step 3: Install NTFS-3G package
This is the package that enables support for the NTFS filesystem in Linux System. Referred to as the driver in Windows Technology.
To install the package after EPEL installation, execute the command:
sudo dnf -y install ntfs-3g
Step 4: Enable NTFS support in Linux
To ensure writing to NTFS partition in Linux, install ntfsprogs package
sudo dnf install ntfsprogs -y
Connecting your device formatted using NTFS Filesystem in your Linux system, you should be able to access the data on the device.
That’s it, congratulations. This has saved you from contacting your local data recovery guy.
Step 5: How to manually mount a Filesystem
To manually mount the device, use the mount command.
The command syntax looks like this:
mount -f [FILESYSTEM TYPE] device mount point
Using -f option specifies the filesystem type of the device. Using mount command with no option displays all currently mounted devices in the system. Mount command is used for temporary mounting of a device in the virtual memory. Once the system reboots , you have to manually mount your device again. This method cannot be used to mount internal disks but its ideal for removable devices.
To mount your device using ext4:
1) List your devices.
To list your devices and their File systems
df -hT
The command above will populate all information about your currently mounted devices, Type of Filesystem used, total size of the device, the used size, available size , percentage usage and where the device is mounted on the virtual directory.
Identify the device you want to manually mount. This will be your removable disk.
Sample output:
[cloudspinx@rocky9 ~]$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs tmpfs 2.8G 0 2.8G 0% /dev/shm
tmpfs tmpfs 1.2G 8.7M 1.1G 1% /run
/dev/mapper/rl-root xfs 35G 1.7G 34G 5% /
/dev/vda1 xfs 960M 286M 675M 30% /boot
tmpfs tmpfs 567M 0 567M 0% /run/user/0
tmpfs tmpfs 567M 0 567M 0% /run/user/1000
/dev/sdb1 vfat 7.6G 2.2G 5.5G 29% /run/media/gidi/Gidi-USB
My device has a vfat file system.
2) Unmount your device.
To unmount your device. Use the umount command
sudo umount /dev/sdb1
3) Create ext4 Filesystem
Then create a new Filesystem using the mkfs command :
sudo mkfs -t ntfs /dev/sdb1
Command output:
$ sudo mkfs -t ntfs /dev/sdb1
Cluster size has been automatically set to 4096 bytes.
Initializing device with zeroes: 100% - Done.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
The process of creating NTFS Filesystem is a slow one (depending on your machine) If yours is as slow as mine, you need to move out and catch some air or read a chapter in your favorite book. (:-)
4) Mount your device
To mount your device manually, define the mount point. Lets create a mount point on /media/USB.
sudo mkdir -p /media/USB
We now mount our /dev/sdb1 removable disk on our new mount point.
sudo mount -t ntfs /dev/sdb1 /media/USB/
List your devices:
$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs tmpfs 2.8G 0 2.8G 0% /dev/shm
tmpfs tmpfs 1.2G 8.7M 1.1G 1% /run
/dev/mapper/rl-root xfs 35G 1.7G 34G 5% /
/dev/vda1 xfs 960M 286M 675M 30% /boot
tmpfs tmpfs 567M 0 567M 0% /run/user/0
tmpfs tmpfs 567M 0 567M 0% /run/user/1000
/dev/sdb1 fuseblk 7.7G 40M 7.6G 1% /media/USB
Congratulations, you have manually mounted your removable disk.
Step 6: Automatically mounting a device
This applies to internal disks. For permanent devices , Linux maintains the /etc/fstab file to indicate which drive devices should be mounted on the virtual directory at boot time.
The /etc/fstab file is a table that indicates the drive device file, mount point location and the Filesystem type.
To see the contents of the file:
$ sudo cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Jan 16 15:19:11 2025
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rl-root / xfs defaults 0 0
UUID=6a277ba7-e353-4b83-b757-a414e4d45bc2 /boot xfs defaults 0 0
/dev/mapper/rl-swap none swap defaults 0 0
To automount our device /dev/sdb1 we need to edit the /etc/fstab/ file.
1) Get the Name, UUID and File System Type
We can get these details by running the blkid command.
$ sudo blkid
/dev/sdb1: BLOCK_SIZE="512" UUID="364D12640F5D7CDE" TYPE="ntfs" PTTYPE="dos" PARTUUID="6a752310-01"
/dev/mapper/rl-root: UUID="e2887579-6ab9-4670-9906-ef662f2775e5" TYPE="xfs"
/dev/vda2: UUID="tb6gQR-d8s7-35sp-ubQr-S3nh-Nc0N-4oEAdP" TYPE="LVM2_member" PARTUUID="12bb8a90-02"
/dev/vda1: UUID="6a277ba7-e353-4b83-b757-a414e4d45bc2" TYPE="xfs" PARTUUID="12bb8a90-01"
/dev/mapper/rl-swap: UUID="31bc5014-53ff-4703-becb-e5f40c612611" TYPE="swap"
/dev/sr0: UUID="2024-11-16-01-52-31-00" LABEL="Rocky-9-5-x86_64-dvd" TYPE="iso9660" PTUUID="5d896d99" PTTYPE="dos"
From the output , we can gather the following information : UUID of our device, The Block Size , Filesystem type and the PARTUUID.
We intend to automatically mount /dev/sdb1.
2) Create a mount point for the device.
We will create our mount point in the /mnt directory.
sudo mkdir /mnt/<name-of-the-drive>
In our example:
sudo mkdir /mnt/sdb1
3) Edit /etc/fstab file.
Use a text editor to edit this file and as root.
sudo vim /etc/fstab
At the end of the file, append the details of your device in this format:
UUID=<uuid-of-your-drive> <mount-point> <file-system-type> <mount-option> <dump> <pass>
Our sample will look this way:
#
# /etc/fstab
# Created by anaconda on Thu Jan 16 15:19:11 2025
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rl-root / xfs defaults 0 0
UUID=6a277ba7-e353-4b83-b757-a414e4d45bc2 /boot xfs defaults 0 0
/dev/mapper/rl-swap none swap defaults 0 0
UUID=364D12640F5D7CDE /mnt/sdb1 ntfs defaults 0 2
~
Save and exit from the editor.
From the output NTFS Filesystem has been set on our device to automount on boot.
To see if the device works:
sudo mount -a
That is how to automatically mount NTFS Filesystem in Linux System.
4) To unmount the device
To unmount your device , use the umount command.
sudo umount /dev/sdb1
Step 7: How to fix errors in ntfs filesystem
To fix errors in NTFS Filesystem in Linux , use the command ntfsfix. Employing this command should come with caution as you can end up losing your data. Use it then with caution. If not absolutely sure, then you can engage the data recovery guys.
ntfsfix is a very useful utility for fixing ntfs filesystem related errors. It is part of the ntfs-3g package ( installed at the beginning of our article). ntfsfix repairs NTFS inconsistencies, resets NTFS journal files and schedules NTFS inconsistencies checks.
The example of an error could be “Failed to mount ‘/dev/sdax’: Input/output error, NTFS is either inconsistent, or there is a hardware fault, or it’s a SoftRAID/FakeRAID hardware“
Run the command:
sudo ntfsfix /dev/"device name"
For the purpose of this article , i will demonstrate this using my /dev/sdb1.
The output is as shown:
$ sudo ntfsfix /dev/sdb1
Mounting volume... OK
Processing of $MFT and $MFTMirr completed successfully.
Checking the alternate boot sector... OK
NTFS volume version is 3.1.
NTFS partition /dev/sdb1 was processed successfully.
You should have a similar output if no errors are found in your disk.
Conclusion
That sums up our article. I hope you have followed through. Please leave a comment or a suggestion.
For more resources :