3

How to take image from my internal hdd to external one using dd ?? This is my hdd info

    root@PartedMagic:~# lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk 
├─sda1   8:1    0  44.3M  0 part 
├─sda2   8:2    0   753M  0 part 
└─sda3   8:3    0 930.7G  0 part 
sdb      8:16   0 931.5G  0 disk 
└─sdb1   8:17   0 931.5G  0 part 
sr0     11:0    1   595M  0 rom  
loop0    7:0    0  39.3M  1 loop 
loop1    7:1    0 184.1M  1 loop 

sda is my internal HDD

sdb is my external HDD

Arronical
  • 20,241

1 Answers1

3

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).

sudodus
  • 47,684