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
  • 19,653
  • 18
  • 73
  • 128
Qassam Mahmoud
  • 245
  • 1
  • 4
  • 7
  • dd if=/dev/sda of=/dev/sdb bs=64k ? – Soren A May 24 '17 at 11:17
  • 2
    Do you want 1) an image (a huge compressed image file) as by `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 use `dd` (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). – sudodus May 24 '17 at 11:21
  • Soren A : bs=64k for what ?? – Qassam Mahmoud May 24 '17 at 16:45
  • @QassamMahmoud, `bs` is the block size *while cloning* with `dd`. It does not affect the block size or sector size on the target drive, but it can affect the speed of the operation. I use `bs=4096`, which I find a good value in most cases. The default is `bs=512`, which makes `dd` 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. – sudodus May 25 '17 at 02:19
  • sudodus how to use dd if=/dev/sda of=/dev/sdb bs=64k and save it to img.raw output ? – Qassam Mahmoud May 26 '17 at 08:31
  • @SorenA that should be a K not a k. – Rinzwind May 27 '17 at 11:37

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
  • 45,126
  • 5
  • 87
  • 151
  • how to skip free blocks with Clonezilla ? – Qassam Mahmoud May 28 '17 at 16:21
  • It is done automatically when Clonezilla uses `partclone`, the default tool for standard file systems like ext4, NTFS and I think also FAT32. `partclone` understands the file system structure and can identify which blocks are used. – sudodus May 28 '17 at 18:45