Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ntfsclone (ntfsprogs) utility won't convert between partitions of different sector-size (e.g.: 512B to 4KB, or vice-versa) #95

Open
mzcs opened this issue Dec 7, 2023 · 5 comments
Assignees

Comments

@mzcs
Copy link

mzcs commented Dec 7, 2023

a Few Days Ago I've Been Fiddling Quite a Bit With Cloning a NTFS Partition, From an Older (512B Sectors) To a Newer (4KB Sectors) SSD, To Preserve a 'Windows 10' OS Setup In a Good Working State.

Thru Much Experimentation (I've Used 'SystemRescueCD v10.02/amd64' Dist.), I've Discovered That 'Windows 10' OS Recognize NTFS Partitions, Cloned Between Different Sector-Sized Drives - With No Related Conversion, As Damaged & Unusable : Classifying These as 'RAW' (Unformatted) .

a Related Conversion Option, Added To 'ntfsclone' Utility, Would Make It Usable For Such Tasks Too, Removing The Need To Turn To Proprietary-Software Tools (Some Unreliable and/or Pricey)... Given The Lack of a Usable F/OSS Alternative ! :)

@Super-Pizza
Copy link

I’ve had the same issue cloning from a NVMe drive to a SATA SSD. The partition becomes unusable in windows

@unsound
Copy link
Member

unsound commented Dec 10, 2023

I can see how this can be a problem. However sometimes you can't trivially convert an NTFS volume from one sector size to another, but other times you can. I've created a patch to add a new option to ntfsclone, --adjust-sector-size, which adjusts the sector size to suit the target device if it's possible to do so in a simple non-destructive manner: 1c19e59
Feedback would be appreciated. I've tested this only with a few very simple test volumes.

Patch: 0001-ntfsclone.c-Add-option-to-adjust-NTFS-sector-size-af.patch

@unsound unsound self-assigned this Dec 10, 2023
@jpandre
Copy link
Collaborator

jpandre commented Dec 10, 2023

@unsound maybe you should use ioctl(BLKPBSZGET) instead of ioctl(BLKSSZGET) to get the physical sector size, see https://mail.gnu.org/archive/html/bug-parted/2012-10/msg00018.html (I have no 4k sectored disk and cannot check the difference).

@mzcs
Copy link
Author

mzcs commented Dec 10, 2023

@unsound:
1st, I'd Like To Say a Big Thank You ! :)

2nd, Until I'd Get To Test It Myself ( On a Computer I Can Compile 'ntfsclone'... ) , I'd Like To Share My Idea of a Test Case :
I) Creating a New NTFS On a 512B-Sector Disk Partition.
II) Unpacking a Huge Source Archive ( +1M Files of Many Different Sizes, Some Recent 'gcc' - Perhaps ? ) Onto It.
III) Utilizing 'ntfsclone', With The New 'adjust-sector-size' Patch, To Clone/Convert It To a 4KB-Sector Disk Partition.
IV) Comparing The Hash of Every File (e.g.: by 'SHA1') On The Cloned/Converted NTFS - With It's Archived Counterpart.

On 'Windows', I Find 'Arsenal Image Mounter' As a Very Handy Tool For Such Experiments (Just Be Sure To Select The Desired Sector-Size Upon Image Mounting).
While On 'Linux', 'losetup -f -b 512 imagefile' (or '-b 4096') Is Just As Useful :)

@unsound
Copy link
Member

unsound commented Dec 11, 2023

@jpandre:

@unsound maybe you should use ioctl(BLKPBSZGET) instead of ioctl(BLKSSZGET) to get the physical sector size, see https://mail.gnu.org/archive/html/bug-parted/2012-10/msg00018.html (I have no 4k sectored disk and cannot check the difference).

Thanks for checking. I'll have to validate what Windows does here, but from what I recall from memory the sector size stored in the NTFS boot sector is the logical sector size (e.g. BLKSSZGET), not the physical sector size (e.g. BLKPSSZGET), in which case the call to ntfs_device_sector_size_get should produce the right result. The physical sector size is mostly useful for optimizing alignment of data and partitions to avoid performance loss on emulated 512-byte sector drives.

(In fact if the physical sector size was being used in the NTFS boot sector then you couldn't move volumes between native 512-byte sector drives and emulated 512-byte sector drives with 4k physical sector size so that wouldn't make much sense from a practical perspective since the whole selling point of these drives is to maintain compatibility with 512-byte sector drives.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants