Linux 讀取 NTFS (NT File System)

Loading

不知道你有沒有發生過這一種糗事,把資料複製到自己的隨身硬碟(USB Hard Drive),當要把他拿去 Linux 下讀取,糗了原來我的隨身硬碟(USB Hard Drive) 格式是 NTFS ,在 Linux 不能用,結果要把隨身硬碟(USB Hard Drive)格式成 FAT32 再重新複製一次,才能解決不同系統的資料複製,其實 Linux 是有支援 NTFS 的系統,但是 RedHat 預設是沒有將這些 Package 放在光碟中,你有需要可以去 Linux NTFS 的官方網站去下載

掛載和讀取

linux-ntfs.org(不知道為什麼網站關閉了) http://www.linux-ntfs.org/doku.php?id=downloads
這邊提供了 RedHat 所有版本已經編譯好了的套件,只要下載用 rpm 加入套件,系統即可掛載 NTFS 的檔案系統 (#mount -t ntfs /dev/sdb1 /mnt).只能掛載和讀取得動作不能做寫入.如果你還需要近一步的使用,請在下載下面的元件.

掛載和讀寫

需要 ntfs-3g , fuse 這兩個套件才可以讓 Linux 有讀取與寫入 NTFS 的權限.

  • 方法很簡單下載後安裝.
    ntfs-3g http://www.ntfs-3g.org/index.html#download

    [root@benjr ~]# tar -zxvf ntfs-3g.tar.gz
    [root@benjr ~]# cd ntfs-3g
    [root@benjr ntfs-3g]# ./configure
    [root@benjr ntfs-3g]# make
    [root@benjr ntfs-3g]# make install
    

    fuse – http://fuse.sourceforge.net/

    [root@benjr ~]# tar -zxvf fuse.tar.gz
    [root@benjr ~]# cd fuse
    [root@benjr fuse]# ./configure kernel_source
    [root@benjr fuse]# make
    [root@benjr fuse]# make install
    

    使用 #mount.ntfs-3g 的就可以寫入 NTFS 磁區.

    [root@benjr ~]# dmesg 
    [85054.697070] usb 2-1: new high-speed USB device number 8 using ehci-pci
    [85054.812771] usb 2-1: New USB device found, idVendor=0781, idProduct=5591
    [85054.812777] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    [85054.812780] usb 2-1: Product: Ultra USB 3.0
    [85054.812783] usb 2-1: Manufacturer: SanDisk
    [85054.812785] usb 2-1: SerialNumber: 4C530001200411105085
    [85054.859857] usb-storage 2-1:1.0: USB Mass Storage device detected
    [85054.860180] scsi host5: usb-storage 2-1:1.0
    [85054.860292] usbcore: registered new interface driver usb-storage
    [85054.866146] usbcore: registered new interface driver uas
    [85055.864722] scsi 5:0:0:0: Direct-Access     SanDisk  Ultra USB 3.0    1.00 PQ: 0 ANSI: 6
    [85055.865683] sd 5:0:0:0: Attached scsi generic sg3 type 0
    [85055.865997] sd 5:0:0:0: [sdb] 60062500 512-byte logical blocks: (30.7 GB/28.6 GiB)
    [85055.867567] sd 5:0:0:0: [sdb] Write Protect is off
    [85055.867573] sd 5:0:0:0: [sdb] Mode Sense: 43 00 00 00
    [85055.868628] sd 5:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
    [85055.880936]  sdb: sdb1
    [85055.884653] sd 5:0:0:0: [sdb] Attached SCSI removable disk
    [85101.848336] perf: interrupt took too long (3141 > 3131), lowering kernel.perf_event_max_sample_rate to 63000
    
    [root@benjr ~]# mkdir /run/media/root/ntfs
    
    [root@benjr ~]# mount.ntfs-3g /dev/sdb1 /run/media/root/ntfs/
    
    [root@benjr ~]# ll /run/media/root/ntfs/
    total 9855076
    -rwxrwxrwx. 1 root root       1639 Apr 14 10:06 ntfs.txt
    
  • yum
    使用環境為 CentOS 7 ,這兩個套件 ntfs-3g , fuse 也可透過 YUM 來安裝,但 YUM 預設並沒有這一些套件,所以我們需要新增 Repo 檔 (epel-release) ,或是手動編寫 /etc/yum.repos.d/epel.repo .

    [root@localhost ~]# yum install epel-release
    Loaded plugins: fastestmirror
    base                                                     | 3.6 kB     00:00     
    extras                                                   | 3.4 kB     00:00     
    nginx                                                    | 2.9 kB     00:00     
    updates                                                  | 3.4 kB     00:00     
    Loading mirror speeds from cached hostfile
     * base: centos.cs.nctu.edu.tw
     * extras: centos.cs.nctu.edu.tw
     * updates: centos.cs.nctu.edu.tw
    Resolving Dependencies
    --> Running transaction check
    ---> Package epel-release.noarch 0:7-6 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package                Arch             Version         Repository        Size
    ================================================================================
    Installing:
     epel-release           noarch           7-6             extras            14 k
    
    Transaction Summary
    ================================================================================
    Install  1 Package
    
    Total download size: 14 k
    Installed size: 24 k
    Is this ok [y/d/N]: y
    Downloading packages:
    epel-release-7-6.noarch.rpm                                |  14 kB   00:06     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : epel-release-7-6.noarch                                      1/1 
      Verifying  : epel-release-7-6.noarch                                      1/1 
    
    Installed:
      epel-release.noarch 0:7-6                                                     
    
    Complete!
    
    [root@localhost ~]# cat /etc/yum.repos.d/epel.repo 
    [epel]
    name=Extra Packages for Enterprise Linux 7 - $basearch
    #baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
    #baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=1
    
    [epel-source]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Source
    #baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=1
    

    現在就可以透過 yum 來安裝 ntfs-3g , fuse .

    [root@localhost ~]# yum install ntfs-3g
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: centos.cs.nctu.edu.tw
     * epel: mirror.premi.st
     * extras: centos.cs.nctu.edu.tw
     * updates: centos.cs.nctu.edu.tw
    Resolving Dependencies
    --> Running transaction check
    ---> Package ntfs-3g.x86_64 2:2016.2.22-3.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package         Arch           Version                      Repository    Size
    ================================================================================
    Installing:
     ntfs-3g         x86_64         2:2016.2.22-3.el7            epel         297 k
    
    Transaction Summary
    ================================================================================
    Install  1 Package
    
    Total download size: 297 k
    Installed size: 695 k
    Is this ok [y/d/N]: y
    Downloading packages:
    ntfs-3g-2016.2.22-3.el7.x86_64.rpm                         | 297 kB   00:01     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : 2:ntfs-3g-2016.2.22-3.el7.x86_64                             1/1 
      Verifying  : 2:ntfs-3g-2016.2.22-3.el7.x86_64                             1/1 
    
    Installed:
      ntfs-3g.x86_64 2:2016.2.22-3.el7                                              
    
    Complete!
    
    [root@localhost ~]# yum install fuse
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: centos.cs.nctu.edu.tw
     * epel: mirror.premi.st
     * extras: centos.cs.nctu.edu.tw
     * updates: centos.cs.nctu.edu.tw
    Resolving Dependencies
    --> Running transaction check
    ---> Package fuse.x86_64 0:2.9.2-6.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package         Arch              Version                Repository       Size
    ================================================================================
    Installing:
     fuse            x86_64            2.9.2-6.el7            base             84 k
    
    Transaction Summary
    ================================================================================
    Install  1 Package
    
    Total download size: 84 k
    Installed size: 219 k
    Is this ok [y/d/N]: y
    Downloading packages:
    fuse-2.9.2-6.el7.x86_64.rpm                                |  84 kB   00:04     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : fuse-2.9.2-6.el7.x86_64                                      1/1 
      Verifying  : fuse-2.9.2-6.el7.x86_64                                      1/1 
    
    Installed:
      fuse.x86_64 0:2.9.2-6.el7                                                     
    
    Complete!
    

    如果你使用的是 Linux 桌面系統,那 NTFS 的 USB Key 插入就可以看到,如果是文字介面可以透過指令 #mount.ntfs-3g (請參考前面的範例)

沒有解決問題,試試搜尋本站其他內容

One thought on “Linux 讀取 NTFS (NT File System)

  1. 自動引用通知: Linux – File | Benjr.tw

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料