ntfs-3g

最後更新: 2022-02-21

目錄

 


Install

 

# C7

yum install epel-release

yum install ntfs-3g ntfsprogs

# C6

yum install ntfs-3g ntfsprogs

 


Format Disk

 

mkntfs / mkfs.ntfs

Opt

  • -n, --no-action                 # DRY RUN. It will display what it would do
  • -f, --fast                          # This will skip both zeroing of the volume and bad sector checking
  • -L, --label STRING            # 設定 Volume 的 Label
  • -c, --cluster-size BYTES    # Default: 4k (a cluster cannot be smaller than a sector)
  • -s, --sector-size BYTES     # If omitted, it attempts to determine the sector-size (Default: 512 bytes)
  • -F, --force                        # Force mkntfs to run, even if the specified device is not a block device

e.g.

Format a disk partition

mkfs.ntfs -f /dev/sdXN

Format Image File

fallocate ntfs.img -l 1g

mkfs.ntfs -f -F ntfs.img

Cluster 64k

# Cluster Size: 512 bytes ~ 2 MiB

mkfs.ntfs -c 65536 -f /dev/sdXN

Win10 Default

  • Sector Size: 512
  • Cluster Size: 32768 # 32k

 


ntfs-3g

 

Usage:

ntfs-3g [-o option[,...]] <device|image_file> <mount_point>

Opts: 

  • ro (read-only mount)
  • remove_hiberfile              # 當系統有啟動休眠時, 只有 ro 或 remove_hiberfile
  • uid=
  • gid=
  • umask=
  • fmask=
  • dmask=

Other Opts:

big_writes    # prevents fuse from splitting write buffers into 4K chunks

relatime       #

inherit         # When creating a new file,

# set its initial protections according to inheritance rules defined in parent directory

Example:

# readonly mount

# 當要 fsck 時 readonly 很有用, 因為不用 check 它.

mount -o ro -t ntfs /dev/xxx /mnt/windows

OR

ntfs-3g -o ro /dev/loop0 /mnt/winxp

 


ntfsfix

 

這工具只能修改一些很基本的 NTFS 問題, 所以可以的話還是用 windows 的 chkdsk 為好

ntfsfix /dev/sdb1

Mounting volume... OK
Processing of $MFT and $MFTMirr completed successfully.
NTFS volume version is 3.1.
NTFS partition /dev/sdb1 was processed successfully.

 


ntfsresize

 

ntfsresize [OPTIONS] [--size SIZE[k|M|G]] DEVICE

  • -i, --info
  • -f, --force    <-- 無視  consistency check 的 flag
  • -n, --no-action  <-- 測試
  • -s, --size SIZE[k|M|G]
  • -v, --verbose

ntfsresize -f -i /dev/sdb1

ntfsresize v2.0.0 (libntfs 10:0:0)
Device name        : /dev/sdb1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 8587158016 bytes (8588 MB)
Current device size: 21473787904 bytes (21474 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 2873 MB (33.5%)
Collecting resizing constraints ...
You might resize at 2872438784 bytes or 2873 MB (freeing 5715 MB).
Please make a test run using both the -n and -s options before real resizing!

 * 當沒有任何 -i, -s 參數時, 它會 resize 到最大

ntfsresize -f /dev/sdb1

ntfsresize v2.0.0 (libntfs 10:0:0)
Device name        : /dev/sdb1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 8587158016 bytes (8588 MB)
Current device size: 21473787904 bytes (21474 MB)
New volume size    : 21473784320 bytes (21474 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 2873 MB (33.5%)
Collecting resizing constraints ...
WARNING: Every sanity check passed and only the dangerous operations left.
Make sure that important data has been backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device '/dev/sdb1'.

 


Fix NTFS boot

 

Recovery Console from the Windows installation disk.

Vista or Windows 7

To repair the Master Boot Record of the boot disk:

bootrec /fixmbr

To write a new partition boot sector to the system partition:

bootrec /fixboot

To rebuild the Boot Configuration Data (BCD) store:

    bootrec /rebuildbcd

WinXP

To repair the Master Boot Record of the boot disk:

    fixmbr

To write a new partition boot sector to the system partition:

    fixboot

To rebuild the boot.ini configuration file:

    bootcfg /rebuild

 


lowntfs-3g

 

比 ntfs-3g 多了 ignore_case Opts

Usage:

lowntfs-3g [-o option[,...]] <device|image_file> <mount_point>

ie.

lowntfs-3g -o noatime,ignore_case,windows_names public_html.ntfs.img public_html/

Opts

ignore_case

Accessing FOO, Foo, foo, etc. designate the same file

All files are displayed with lower case in directory listings.

windows_names

Prevents files, directories and extended attributes to be created with a name not allowed by windows.

Existing such files can still be read (and renamed)

  • not allowed character ( * / : < > ? \ | )
  • name is reserved
  • last character is a space or a dot

Notes

 * 大細階會被保留, 但會被看成細階

測試

lowntfs-3g -o noatime,ignore_case,windows_names public_html.ntfs.img public_html/
touch public_html/DataHunter            # 建立有大細階的檔案
ls public_html/ | grep -i datahunter
datahunter                              # 顯示成細階
umount public_html
ntfs-3g -o noatime public_html.ntfs.img public_html/
ls public_html/ | grep -i datahunter
DataHunter                              # 大細階有被保留

 


Tips

 

1) Backup Disk 建議用大的 cluster-size

mkfs.ntfs -L BackupDisk -c 65536 -Q /dev/nbd0p1

2) Windows 認唔到 ntfs-3g 建立的非 512 bytes sector size(-s) filesystem

3) Win10 開始才 support 8K/16K cluster-size 的 compression (algorithm: XPRESS) [Per-file]

4) 用 parted 建立 partition 時要注意 type, 否認 Windows 唔認碟

(parted) mklabel msdos

(parted) mkpart pri ntfs 0% 100%

5) Allocation unit size = cluster size

 

Creative Commons license icon Creative Commons license icon