How to use dd command to copy and backup whole disks

How to copy whole disks or partitions from/to disk or image, regardless of the file system.

Syntax dd if=SOURCE of=TARGET for basic operation

Change default block size to bs=1M for faster operation. Test block size performances



Copy whole disk to image dd bs=1M if=/dev/sdX of=/storage/backup01.img

Copy partition to image dd bs=1M if=/dev/sdX1 of=/storage/backup01.img

Copy partition to other disk partition dd bs=1M if=/dev/sdX1 of=/dev/sdY1

Copy image to disk partition dd bs=1M if=/storage/backup01.img of=/dev/sdX1


Create compressed .gz image from whole disk dd bs=1M if=/dev/sdX | pigz -c0 > /storage/backup01.gz

Compress image to .gz pigz -k0 /storage/backup01.img

Decompress .gz image to raw image pigz -dk /storage/backup01.gz

Decompress .gz image to whole disk pigz -dc /storage/backup01.gz | dd bs=1M of=/dev/sdX

Mount image

Look at partitions inside a raw image, find sector start and sector size fdisk -lu backup01.img

Mount from image with sector start and sector size mount -o loop,offset=$((137216 * 512)) backup01.img /media/bkp1/


Be aware that if you use theses commands without understanding them, you can render all your data inaccessible.

If you dont have pigz installed apt-get install pigz Or you can use gzip instead of pigz.

List devices by block name lsblk