在Centos7系统中挂载NTFS格式的磁盘

    xiaoxiao2021-04-15  179

    转载自 https://www.rootusers.com/how-to-mount-a-windows-ntfs-disk-in-linux/

    How To Mount A Windows NTFS Disk In Linux

    Posted by Jarrod on May 24, 2017Leave a comment (4)Go to comments

    The New Technology File System (NTFS) is a proprietary file system created by Microsoft and is used extensively in Microsoft’s Windows operating systems.

    By default most Linux distributions are not able to mount NTFS, however it is possible to install a driver that allows us to do this so that we can read and write data to an NTFS disk.

     

    In this example I have attached the VMDK file from a Windows based virtual machine to a CentOS 7 Linux virtual machine.

    When we run ‘fdisk -l’ we can see that the disk is recognized (after a system reboot), however it is not yet mounted for us to access the data. We can see the primary disk for the Linux system /dev/sda, while /dev/sdb is our 1GB NTFS disk which has the /dev/sdb1 NTFS partition.

    [root@centos7 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0004c930 Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xfc757b2a Device Boot Start End Blocks Id System /dev/sdb1 128 2091135 1045504 7 HPFS/NTFS/exFAT

    By default when I try to mount the NTFS disk, we get the below error.

    [root@centos7 ~]# mkdir /windows [root@centos7 ~]# mount /dev/sdb1 /windows/ mount: unknown filesystem type 'ntfs'

    Install Required Packages

    In order to perform the mount, we need to install the ntfs-3g package, which is a Linux NTFS userspace driver. This package comes from EPEL if you’re using CentOS/RHEL, so if you have not yet configured your system to use the EPEL repository, run the following command.

    [root@centos7 ~]# yum install epel-release -y

    Now we should be able to install the ntfs-3g package from the EPEL repository.

    [root@centos7 ~]# yum install ntfs-3g -y

    Otherwise if you’re using Ubuntu/Debian, you should just be able to run ‘apt-get install ntfs-3g’ straight away. In my Debian 8 installation it was already available so I was able to mount NTFS without any problems.

    Mount The NTFS Disk

    We can now successfully perform the mount without any errors.

    [root@centos7 ~]# mount /dev/sdb1 /windows/ [root@centos7 ~]# blkid /dev/sdb1 /dev/sdb1: LABEL="NTFS" UUID="CA4A1FD94A1FC0DD" TYPE="ntfs"

    We can confirm that the NTFS disk is now seen as mounted by the operating system.

    [root@localhost ~]# df -h /windows/ Filesystem Size Used Avail Use% Mounted on /dev/sdb1 1021M 11M 1011M 2% /windows

    At this point you should be able to read and write data on the mounted NTFS disk.

    Automatically Mount NTFS

    We can create an entry in the /etc/fstab file so that our NTFS disk will automatically mount on system boot. Below is an example of the entry that I have placed into my fstab file. This will mount the disk to the /ntfs directory.

    /dev/sdb1 /windows ntfs-3g defaults 0 0

    Once this configuration has been added, the NTFS disk should mount automatically on system boot. Before performing a reboot, it is recommended to first run the ‘mount -a’ command and confirm that the disk mounts without errors. If there are errors that happen during boot, you may be left with a system that does not properly boot so it’s important to test first.

    Summary

    We have seen that it is possible to easily mount an NTFS disk in CentOS 7 Linux once the ntfs-3g package has been installed which provides us with the necessary drivers.


    最新回复(0)