Warning
dd
is a powerful but also dangerous tool. Check and double-check, that everything is correct before you launch the command lines! dd
does what you tell it to do without questions. A small mistake (typing error) can make you overwrite and destroy valuable documents, for example the family pictures.
Command lines
Text after the #
character is a comment for the human eye, not used by the shell interpreter.
If you are sure that /dev/sdx
is the correct target device, you can use the command
sudo dd if=/dev/sda of=/dev/sdx bs=64K # should be upper case K
to clone the drive to the device /dev/sdx
, where x can be b, c, ...
If you want to create an image file (without compression), you can use the command
sudo dd if=/dev/sda of=dd-clone.img bs=64K # should be upper case K
If you want to create a compressed image file, you can use the command
sudo -s # to get the root prompt `#`
dd if=/dev/sda bs=64K | xz -c > dd-clone.img.xz
exit # to get the user prompt `$`
Such a compressed image can be extracted with
sudo -s # get the root prompt `#`
xzcat dd-clone.img.xz > dd-clone.img # get a big uncompressed file
xzcat dd-clone.img.xz | dd of=/dev/sdx bs=64K # clone to `/dev/sdx`
exit # get the user prompt `$`
Tips
If you want the compression to be more efficient, you should overwrite the free drive space with zeros. You can do that in the following way:
Use zerofree
for linux ext
partitions.
Mount other partitions and use the following command lines for partitions with other file systems. Let us assume that you have mounted a partition at the mountpoint /mnt
, and that the whole drive is used for partitions. Check that you have mounted a partition there! Otherwise you will fill the root partition and your running operating system will stop working.
sudo dd if=/dev/zero of=/mnt/blank bs=4096 # Let it fill the partition
sudo rm /mnt/blank
See Tools at this link: SanDisk SSD Plus: Half the performance on Linux than on Windows?
Alternative
Clonezilla is an alternative to dd
. It is safer and it is faster, particularly if there is a lot of free space. Clonezilla will only copy used blocks (and skip free blocks), which will make the copy much faster, particularly if a fair part of the main partition /dev/sda3
is free (not used by files).
dd
(wrapped by mkusb to avoid mistakes) or a directory with several files as by Clonezilla), or 2) a clone (an exact copy of the internal hdd, so that the external drive can replace the internal one)? In both cases you can usedd
(with or without wrapper) and Clonezilla. I would recommend Clonezilla, because it will only copy used blocks (and skip free blocks), which will make the copy much faster, particularly if a fair part of the main partition /dev/sda3 is free (not used by files).bs
is the block size while cloning withdd
. It does not affect the block size or sector size on the target drive, but it can affect the speed of the operation. I usebs=4096
, which I find a good value in most cases. The default isbs=512
, which makesdd
slow in current linux operating systems. But be warned:dd
is a powerful but also very dangerous tool. It does what you tell it to do without questions. A small mistake (typing error) can make you overwrite and destroy valuable documents, for example the family pictures.