0

TL;DR: Is there a way to clone a disk's metadata to another disk?

I'm trying to copy all the data (including metadata) of a 4TiB disk to another 2TiB disk. I've verified that the 4TiB disk contains only 1TiB data, and its filesystem is ext4.

My previous approach was as follows:

  1. Resize the filesystem on the source disk: resize2fs -M <source disk mountpath>
  2. Calculate the number of 16MiB blocks needed for the shrunk filesytem.
  3. Use dd to copy all the data (including metadata): dd bs=16M if=<src> of=<dst> count=<# block calculated in step2.

This method works fine when the data amount is relatively small. But when the data size is large, for example 1TiB, both resize2fs and dd can take a long time.

I'm thinking about using rsync instead of dd, so there is no need to resize the original filesystem, and plus rsync seems to be faster than dd. But one problem is that rsync does not copy over the disk metadata, like uuid, label, etc.

I would like the new disk to have the exact the same metadata as the original one, so that I can directly use the new disk to replace the original one without modifying anything on the server. Is there a way to clone the disk's metadata as well?

0

Yes there is a way to clone the drive with metadata: use dd as you originally approached. Though why you need to do it in 16MB chunks is unclear.

Writing large chunks of data takes time, there's no way around this unless you get faster drives.

4
  • Thanks! If using dd, how to determine the boundary of the metadata, i.e. how do you determine of and if positions? Originally to copy all the data, I would first resize the filesystem to its minimum size. But since I only want to copy the metadata, is there a way to skip the resize step? – Patrick Dec 26 '20 at 2:33
  • Copying the filesystem's metadata to a different filesystem without copying the data will not be of use to you since the metadata may not point to the same data. If you're just trying to swap a physical drive, shrink the partition, dd the data/metadata and then resize the partition after. Are you after the filesystem metadata, or just the information about the physical disk that the OS uses? – RobbieCrash Dec 27 '20 at 3:21
  • I actually need the both the data and metadata, but I think the data part could be copied to a new driver by rsync. What rsync did not copy over is the metadata, so I'm wondering if there exists a way to copy the metadata as well. – Patrick Dec 27 '20 at 6:22
  • None that I'm aware of. dd'ing the entire partition is the proper way to do this. Unless all you're looking to do is sync the file metadata like access/update time, in which you can run rsync with --archive and do it again. But since you mention disk UUID, I suspect dd and some spare time is your only real option. – RobbieCrash Dec 28 '20 at 6:09

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.