This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
dd
¶
dd
is a core utility whose primary purpose is to convert and copy a file. Similarly to cp
, by
default dd
makes a bit-to-bit copy of the file, but with lower-level I/O flow control features.
Warning
Incorrect use of the dd
command can wipe any drive connected to the system. Always backup all
important data.
Reference(s)
$ man dd
- https://www.cyberciti.biz/faq/unix-linux-dd-create-make-disk-image-commands/
- https://wiki.archlinux.org/title/Dd
- https://wiki.gentoo.org/wiki/Dd
- https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation
- https://docs.fedoraproject.org/en-US/quick-docs/creating-and-using-a-live-installation-image/
- https://wiki.archlinux.org/title/Securely_wipe_disk#dd
- https://wiki.archlinux.org/title/Disk_cloning
- https://wiki.archlinux.org/title/Dd#Disk_cloning_and_restore
Table of contents¶
- Make sure some drives are not mounted
- Installing/cloning an ISO image on a target drive
- Cloning a disk or a partition from a source drive to a target drive
- Creating and restoring a disk (or a partition) image
- Securely wipe a drive
- Benchmark read and write speed
Make sure some drives are not mounted¶
A lot of dd
commands require a "source" and/or a "target" drive to not be mounted. Here,
source and target drives refers to the disks you want to run dd
upon.
-
Let's say that your system is on the
/dev/sda
device, that the source drive is on the/dev/sds
device and the target drive is on the/dev/sdt
device, then you might see something like bellow when runninglsblk
: -
Now, depending on what
dd
command you are using, you might have to make sure that the source drive (on device/dev/sds
) and/or the target drive (on device/dev/sdt
), are not mounted:
Installing/cloning an ISO image on a target drive¶
Tip
See https://docs.fedoraproject.org/en-US/quick-docs/creating-and-using-a-live-installation-image/
-
Make sure your target drive (e.g. on
/dev/sdt
) is not mounted. -
Then, use
dd
to install/clone the ISO image on the target drive:
Warning
Be extremely careful when using the dd
command, in particular pay attention to the
of=/dev/some-device
part! You really don't want to get the wrong device there or you will end
up overwriting the wrong disk!
Tip
A better way to visualize the progression of dd
, is to use
pv
(see
https://askubuntu.com/questions/215505/how-do-you-monitor-the-progress-of-dd), e.g. for an
.iso
of 42 Go:
(do not try with:
or the output will look bad)
Tip
Another way to see the progression of dd
, is to run:
This will display the progress in the associated dd
terminal window without halting the
process (by printing to its stderr
stream).
If you would like to get regular updates of the dd progress, then enter:
Note
The dd command might take a long time to complete in order to "sync". Be patient.
Cloning a disk or a partition from a source drive to a target drive¶
-
Make sure your source drive (e.g. on
/dev/sds
) AND target drive (e.g. on/dev/sdt
) are not mounted. -
Then, use
Or to clone a source partition (e.g. on devicedd
to clone a source disk (e.g. on device/dev/sds
) to a target drive (e.g. on device/dev/sdt
):/dev/sds2
) to a target partition (e.g. on device/dev/sdt6
):
Warning
Be extremely careful when using the dd
command, in particular pay attention to the
of=/dev/some-device
part! You really don't want to get the wrong device there or you will end
up overwriting the wrong disk!
Note
The dd command might take a long time to complete in order to "sync". Be patient.
Creating and restoring a disk (or a partition) image¶
Creating a disk (or a partition) image from a source drive¶
-
Make sure your source drive (e.g. on
/dev/sds
) is not mounted. -
Then use
Or to create a partition image fordd
to create a disk image for/dev/sds
, i.e cloning it to a file (sds-image.gz
):/dev/sds2
, i.e. cloning it to a file (sds2-image.gz
): -
The previous command just cloned the entire hard drive, including the MBR, bootloader, all partitions, UUIDs, and data.
Restoring a disk (or a partition) image to a target drive¶
-
Make sure your target drive (e.g. on
/dev/sdt
) is not mounted. -
In order to restore a disk image (
Or to restore a partition image (/path/to/sds-image.gz
) to a target drive:/path/to/sds2-image.gz
) to a target drive (e.g./dev/sdt6
):
Warning
Be extremely careful when using the dd
command, in particular pay attention to the
of=/dev/some-device
part! You really don't want to get the wrong device there or you will end
up overwriting the wrong disk!
Note
The dd command might take a long time to complete in order to "sync". Be patient.
Securely wipe a drive¶
Benchmark read and write speed¶
If this cheat sheet has been useful to you, then please consider leaving a star here.