10

Given HDD 1TB with a two partitions: one is small ~24GB (for Ubuntu) and all the rest is the second partition with about 10% occupied space for multimedia files.

I want to duplicate it as fast as possible. I boot from USB stick. The second disk is /dev/sdb.

sfdisk -d /dev/sda > a
sfdisk /dev/sdb < a

Then I copy bytewise the small partition:

dd if=/dev/sda1 of=/dev/sdb1 bs=4M status=progress

It takes about two minutes. Then I want to copy in optimal manner contents of the second partition. Just filesystem w/ file attributes:

rsync -avHAX /media/ubuntu/sda2dir /media/ubuntu/sdb2dir

After that I tried to boot from second HDD and can't.

How to copy MBR and other crucial information?

dd if=/dev/sda of=/dev/sdb takes about 1h20m for 1TB HDD. It is not acceptable. And seems also not works.

1 Answers1

12

I would use Clonezilla

Get a Clonezilla iso file, make a USB boot drive, and boot from it.

See the documentation on clonezilla.org.

Use Clonezilla to clone the whole drive. This will work if

  • the target drive is at least as big as the source drive. You can check that (if the sizes are nominally the same) with

      sudo parted /dev/sdx u B p
    

    where x can be for example a (/dev/sda) and b (/dev/sdb) for the two drives. The target drive should not be one single byte smaller than the source drive, otherwise you must shrink the last partition so that its tail end will be within the target drive.

  • the physical sector sizes of the two drives are the same. You can check that with

      sudo parted -ls
    

Clonezilla is smart enough to copy/clone only the used data blocks on the drive and skip unused blocks, so it is faster than cloning with dd, particularly when there is a lot of unused drive space (as in your case).

Clonezilla fixes the GPT backup partition table at the tail end of the drive. (If the drive sizes are different, and you use a simple raw cloning tool (for example dd), and the partition table is GPT, you must repair the backup table at the end of the drive. You can do that manually with gdisk or with the shellscript gpt-fix.)

Clonezilla is also safer than dd, because it has a user dialogue that helps you to check and double-check that you will clone to the correct target device. dd does what you tell it to do without questions. A minor typing error can make you overwrite the family pictures.


Please notice that Clonezilla can

  • clone a drive to another drive of at least the same size
  • create a compressed image (a directory with a number of files)
  • clone a partition and create an image of a partition
  • restore from a compressed Clonezilla image to a drive of at least the same size
  • work locally or via a network
sudodus
  • 46,324
  • 5
  • 88
  • 152
  • 1
    Expressing a different opinion: I have found Clonezilla's verbiage unhelpful. dd has been simpler, requiring only a few commands for my purposes. So far, dd has not subjected me to the dismaying discovery, too late, that Clonezilla's black box gave me a failed archive. Yes, one must be careful. I use Windows programs for the family photos. As you indicate, Clonezilla shares dd's weakness regarding larger source and smaller target drive. Timewise, I can generally let the process run while doing other things. See https://raywoodcockslatest.wordpress.com/2021/08/18/vmware-v2p/#Command – Ray Woodcock Sep 29 '23 at 17:20
  • 1
    @RayWoodcock, Thanks for the link to your well written blog post. I appreciate your different opinion or maybe we should say different experience of Clonezilla. I have used it for several years and I am happy with it. But there is a learning curve. It takes time to get used to the dialogue and workflow in Clonezilla. – sudodus Sep 29 '23 at 18:22