Exact copy of files from NTFS to another NTFS using Linux

14

1

I try to copy all files from an NTFS to an external drive and want to preserve all permissions and attributes. The external drive has already an NTFS and contains other files.

I've considered using the following tools:

  • ntfsclone does not work since it operates on sector level and would clone the whole FS, thus destroying the old data. If used to create an image file, I can't access the content from a Windows machine.
  • rsync does not preserve all meta data.

An alternative would be to use robocopy inside a running Windows, but I would prefer to copy the files without. (The source partition is used as the system's C:\.)

How can I copy the files?

Scolytus

Posted 2014-03-31T10:20:59.173

Reputation: 314

5What exact metadata are you trying to retain here that RSYNC won't retain with the appropriate parameters? Are you referring to music file software type metadata or actual FS permissions, structure, time, owner, etc.? I'm not sure what you've tried already with RSYNC but it would seem that using the correct parameters such as -AXogt for example should retain the FS metadata for the most part. Please explain what you have tried that does not work and what "metadata" you're seeing that is not retained between NTFS partitions. – Pimp Juice IT – 2016-01-24T17:33:23.840

I know the files themselves can be copied exactly byte-for-byte in linux, but is it all the dates like created, modified, accessed that's missing? Or NTFS user/owner & permissions? Is there no way to change these dates & permissions on files after they're copied back to windows NTFS? – Xen2050 – 2016-01-26T11:17:59.630

Answers

8

There is no way to exactly copy NTFS files, passing through Linux. Even Wine, the Windows-compatibility layer on Linux, works by converting permissions back-and-forth between Linux and Windows, and so is limited to their (rather small) least common denominator.

The only solution I can see is running Windows on Linux inside a virtual machine (or physical).

I believe you have mentioned this possibility in your post and would prefer to avoid it, but I do not see another possibility. Only Windows can exactly copy NTFS files; Linux is only capable of copying NTFS partitions.

This article might help: How to install and run Microsoft Windows for free on Linux, using free virtual machines made available for download by Microsoft.

harrymc

Posted 2014-03-31T10:20:59.173

Reputation: 306 093

I'm not sure about it, but according to the manpage of ntfs-3g, the option streams_interface=xattr is set by default. If I understand it correctly, this means that NTFS file attributes (including Windows permissions) are mapped to xattr attributes in linux. Since cp -a and rsync -X does copy this attributes, shouldn't it be an exact copy?

– JojOatXGME – 2018-04-15T11:07:43.260

@JojOatXGME: The permissions models of Windows and Linux are completely different. Only the most basic attributes have an exact counterpart. – harrymc – 2018-04-15T11:25:41.733

I know. I don't claim that Linux does understand this attributes, but xattr attributes are key-value-paris that doesnt have to be understood by the operating system. ntfs-3g seems to make Windows permissions available as xattr attribute system.ntfs_acl. The same seems to be true for other matadata in NTFS. Since xattr attributes are copied when using rsync -X or cp -a, it might copy the metadata as well. It depends on the concrete limitations of xattr and the implementation of ntfs-3g, but it looks possible to me.

– JojOatXGME – 2018-04-15T14:51:30.637

1

Linux can copy NTFS files contents fine, just not all the modified/created/accessed dates & attributes (I'm assuming that's what you want preserved).

So why don't you just make note of the current dates & attributes (dir should be able to display them), then copy the files in linux, and once you're running Windows again change the dates & attributes back to the originals.

Use a tool in Windows that can change the files, like one of these ones:

Apparently Windows' own File Explorer doesn't even preserve all the file dates properly either. But zip & cygwin's tar commands should save file dates, so using one of those in Windows to create an archive first should work too, then just copy the archive any old way.


If the attributes are super-important, and difficult to copy even in Windows, they should probably be backed up in a text file or database, or made into part of the filename...

Xen2050

Posted 2014-03-31T10:20:59.173

Reputation: 12 097

1

First thing is, you need to make up your mind if you want to copy files, ...

or you want to make a complete, sector-by-sector, copy of your NTFS partition, including the "old data", the "other files", aswell "all the metadata" you have mention above very broadly.

For the latter, use dd:

dd if=/dev/sda2 of=/mnt/usbdisk/my-ntfs-partition-D.img bs=1M

Have fun.

Paxsali

Posted 2014-03-31T10:20:59.173

Reputation: 134

2Well, I've made up my mind, and it's already in the question. I want to copy the files with all associated meta data. This should be possible because source FS as well as destination FS is NTFS, thus having the same capabilities. Using dd would be a poor choice since it does not take FS information into account. If you have an NTFS you should always use ntfsclone for image creation. – Scolytus – 2014-04-01T21:46:24.193

In this case use robocopyor ntfscopy (https://tzworks.net/prototype_page.php?proto_id=9), but neither of those are available on linux.

– Paxsali – 2014-04-01T22:09:28.960

Well, I also mentioned robocopy in my question. So I appreciate your afford, but it's not really an answer to my question. – Scolytus – 2014-04-01T22:18:51.500