How to make disk image with dd on Linux

Recently I had to send my notebook to service (by the way – it’s fifth time when it’s in service). When I sent my notebook first time, I made a full backup because service after repair usually delete all data on disk and install clean Windows to check …


This content originally appeared on DEV Community and was authored by Chris Texe

Recently I had to send my notebook to service (by the way - it's fifth time when it's in service). When I sent my notebook first time, I made a full backup because service after repair usually delete all data on disk and install clean Windows to check if everything is OK. But when I sent my notebook third time I said ENOUGH! Every few months I had to install Linux Mint, configure it, install my apps and so on, and so on... Then I started to create images. So how to make disk image with dd on Linux and what is the disk image?

What is disk image?

Disk image is a one big file which contains every byte of some disk. Notice that it's not a copy if files. DIsk image is created by special applications from low level disk reading. It means these applications read disk sectors byte by byte and write them to another disk creating one big file. It's very useful when you want to change disk to another for instance HDD to SSD.

How to create whole disk image?

This command creates image of whole disk:

dd if=/dev/ORIGIN_DISK of=/dev/PLACE-TO-WRITE bs=64K conv=noerror,sync

To clone /dev/sda (250GB) to /dev/sdb (250GB) in Linux, type this:

dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync

After running above command you will get a big 250GB file.

How to create a partition image?

This command creates image of whole disk:

dd if=/dev/sda1 of=/dev/sdb1 bs=64K conv=noerror,sync

Let's stop here for a moment and see what we have here:

if - input device/file

of - output device/file

bs=64K - The block size. Usually peope use 64K or 128K, but you can use other values if know what you do

conv=noerror - dd will continue operation and ignore all read errors

sync - add input blocks with zeros if there were any read errors (it means data offsets stay in sync)

How to create disk image using live CD or USB flash drive?

Just boot your CD/DVD or USB flash drive and run terminal. Then list your disks by using fdisk:

sudo fdisk -l

You should see similar to this:
fdisk

Sometimes you can see different names of disk, eg. nvme for SSD M.2.

To create disk image run this:

dd if=/dev/sda conv=sync,noerror bs=128K | gzip -c > SSD_image.gz

DD will create compressed image of whole sda disk. The image will be in current directory. If you want to save it in another directory, tell dd where to save the image:

dd if=/dev/sda conv=sync,noerror bs=128K | gzip -c > /media/disk2/images/SSD_image.gz

Above commands clone the entire hard disk, including the MBR, bootloader, all partitions, UUIDs, and data.

How to restore disk image?

To restore compressed image to a new disk:

gunzip -c SSD_image.gz | dd of=/dev/sda

We assume SSD_image.gz is in current directory and we will lost all data on /dev/sda.

Bonus tip

If you want to see the progress just add status=progress:

dd if=/dev/sda conv=sync,noerror bs=128K status=progress | gzip -c > /media/disk2/images/SSD_image.gz


This content originally appeared on DEV Community and was authored by Chris Texe


Print Share Comment Cite Upload Translate Updates
APA

Chris Texe | Sciencx (2022-07-12T19:23:21+00:00) How to make disk image with dd on Linux. Retrieved from https://www.scien.cx/2022/07/12/how-to-make-disk-image-with-dd-on-linux/

MLA
" » How to make disk image with dd on Linux." Chris Texe | Sciencx - Tuesday July 12, 2022, https://www.scien.cx/2022/07/12/how-to-make-disk-image-with-dd-on-linux/
HARVARD
Chris Texe | Sciencx Tuesday July 12, 2022 » How to make disk image with dd on Linux., viewed ,<https://www.scien.cx/2022/07/12/how-to-make-disk-image-with-dd-on-linux/>
VANCOUVER
Chris Texe | Sciencx - » How to make disk image with dd on Linux. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/12/how-to-make-disk-image-with-dd-on-linux/
CHICAGO
" » How to make disk image with dd on Linux." Chris Texe | Sciencx - Accessed . https://www.scien.cx/2022/07/12/how-to-make-disk-image-with-dd-on-linux/
IEEE
" » How to make disk image with dd on Linux." Chris Texe | Sciencx [Online]. Available: https://www.scien.cx/2022/07/12/how-to-make-disk-image-with-dd-on-linux/. [Accessed: ]
rf:citation
» How to make disk image with dd on Linux | Chris Texe | Sciencx | https://www.scien.cx/2022/07/12/how-to-make-disk-image-with-dd-on-linux/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.