How to use dd for disk imaging and cloning
· Category: Linux
Short answer
dd copies data at the block level, making it ideal for disk images, backups, and cloning.
Steps
- Create a disk image:
sudo dd if=/dev/sda of=/backup/sda.img bs=4M status=progress
- Clone a disk:
sudo dd if=/dev/sda of=/dev/sdb bs=4M status=progress
- Restore from image:
sudo dd if=/backup/sda.img of=/dev/sda bs=4M status=progress
- Create a compressed image:
sudo dd if=/dev/sda bs=4M | gzip > /backup/sda.img.gz
Tips
status=progressshows transfer statistics (GNU dd).bs=4Mimproves speed over the default 512 bytes.- Use
fdisk -lorlsblkto identify correct devices.
Common issues
- Wrong
ofdevice overwrites the wrong disk irreversibly. - Very large images: ensure destination has enough free space.