2

Is it possible to use dd to copy data from an NTFS drive to an XFS formatted drive?

I am converting my NAS from a WHS(Windows Home Server) setup to Linux based OpenMediaVault. So I am preparing to convert the drives from NTFS to XFS.

If possible I would like to directly copy from NTFS hdd to a XFS hdd and then reformat the NTFS hdd to XFS to copy the second HDD.

I know copying if=/dev/sda will copy the partition and filesystems too. But what if I copy /dev/sda1 to a partition that is in a different format?

4
  • Why dd instead of a file-level tool like rsync ? – bertieb Apr 13 '17 at 12:38
  • Some of the folders I am copying contain a ton of small files which slow down the transfer rate. If there is another way to overcome this I would like to know. – charsi Apr 13 '17 at 12:41
  • 1
    You need to operate on mounted filesystems using a recursive copy tool. There is absolutely no way around this, unless you roll your own conversion tool. – Daniel B Apr 13 '17 at 13:06
  • @DanielB that is what I was trying to confirm was the case. I have gone with rsync. Copying around 6TB total eta around 18hrs. – charsi Apr 13 '17 at 19:02
4

Is it possible to use dd to copy data from an NTFS drive to an XFS formatted drive?

No, dd reads/writes blocks, not files. When writing a backup image from a source NTFS drive to a target (XFS/EXT4/FAT32) drive, the target drive would become NTFS no matter what FS it was formated with before.

It's possible to mount an dd image and copy the data:

mount -o ro,loop -t ntfs myimage.img /mnt/

but then better just tar your data = archive it without compression but save user, group and permission!

tar cvf /foo/bar/my_backup.tar /

But what if I copy /dev/sad1 to a partition thats in a different format?

Yes, you can mount two drives with different filesystems and copy files between them. ie: /dev/sda with NTFS and /dev/sdb with XFS .

3
  • 2
    dd reads and writes files just fine. dd if=a of=b is equivalent to cp a b. It doesn’t do what the OP thinks/wants, that’s for sure. But loop mounting or archiving are very far from what the OP is trying to achieve. – Daniel B Apr 13 '17 at 13:04
  • if=/dev/sda how would you cp that? – Michael D. Apr 13 '17 at 13:08
  • @MichaelD. Easily: cp /dev/sda myimage.img. – Kamil Maciorowski Apr 13 '17 at 15:05
3

But what if I copy /dev/sad1 to a partition that[']s in a different format?

(Presumably a typo, meaning /dev/sda1)

If you copy with dd, the result is that the new partition uses the same format, because dd preserves the filesystem's formatting. So, the result doesn't end up being "in a different format".

Is it possible to use dd to copy data from an NTFS drive to an XFS formatted drive?

Yes, you can do what you asked.
However, from your description, it's not clear that what you're asking (can you store data from NTFS onto XFS) will do exactly what you want.

From a comment made on Michael D's answer:

dd if=a of=b is equivalent to cp a b

I typically think of dd as being designed to work well with devices. If "a" and "b" (in the prior examples) are files, then what you said is true. However, dd is typically used when "a" or "b" is a "device" object (or, if both "a" and b" are devices). In this context, the term "device" refers to a type of object on the filesystem. Most commonly/traditionally, interacting with such devices will involve communicating to hardware, e.g. /dev/sda may refer to a hard drive. As software is highly customizable, there can be other cases, like /dev/sda1 which communicates with just a section of data on the hard drive.

So, this can work well:

dd if=/dev/sda1 of=~/ntfscopy.img

This stores the entire NTFS partition, including the "metadata" like the internal structures of the filesystem, into a file called ~/ntfscopy. You could then copy that to a XFS drive:

cp ~/ntfscopy.img /mnt/xfsdrive/ntfscopy.img

Or, you could skip that separate step:

dd if=/dev/sda1 of=/mnt/xfsdrive/ntfscopy.img

Now, this may be useful to back up data. When you find some empty space on a partition, you can write it out. (Of course, this example involves writing to a partition, so you've got to be VERY CAREFUL that you don't end up overwriting data.)

dd if=/mnt/xfsdrive/ntfscopy.img of=/dev/sdb2

This shows a useful example of having data copied from an NTFS drive to an XFS drive, and that works.

Now, what if you just wanted the files copied from an NTFS drive, and not the entire NTFS partition (including the internal filesystem structure which is what makes the partition use NTFS formatting)? In that case, you wouldn't want to have used dd. By using a different tool, you can avoid unnecessarily reading/copying all of the NTFS internal filesystem structures. e.g., you could mount the NTFS drive (read-only, if you like), and then use "cp" to copy data from the NTFS drive (or maybe "tar", if you want the output to be one convenient file).

2
  • Thanks for this @TOOGAM. I did in fact mean copying from /dev/sda1 and not /dev/sda. Your answer has confirmed what I was thinking. I can either copy to a .img file using dd and then extract files from it later or not use dd altogether. – charsi Apr 13 '17 at 18:53
  • As explained in the comment to my question only reason I was looking to use dd is that I found it to be a lot quicker than cp or rsync where lots of small files are involved. – charsi Apr 13 '17 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.