Comments on Linux dd Command Explained for Beginners (8 Examples)
The dd command is a powerful utility used for low-level data copying and conversion on Linux systems. It stands for "data duplicator" and is often employed to create exact copies of files, partitions, or entire disks, making it useful for tasks like creating backups, cloning drives, or writing disk images to physical media.
5 Comment(s)
Comments
I have **Never** used dd in the ways shown above. Not once in 25 yrs as a Unix admin.
I use dd a few times a month, usually to make a bootable Linux flash drive for some Distro.
$ sudo dd if=/path/to/ubuntu.iso of=/dev/sdZ bs=1M
That will make a flash drive with a single distro ready to be booted with which ever type of boot the distro supports (EFI/Legacy BIOS / Both). Ubuntu supports both, BTW.
The real power in dd, is how stupid it is. It moved bytes from A ---> B. Need to mirror a partition? Use dd at the partition level. Need to mirror a whole disk, including all the partition tables and boot records? Use dd at the whole disk level.
Assume sda is your boot disk with multiple partitions on it and sdZ is the target, disk that is the same or larger size of sda.
$ sudo dd if=/dev/sda of=/dev/sdZ bs=1M
That command copies, bit for bit, everything from sector 0 to the end of sda onto sdZ. You'll get any boot sector, partition tabels, and all data in all partitions. If using GPT, the GPT partition table at the end of the disk will be in the wrong place unless it is exactly the same size. Use gdisk to fix it. The 1st GPT table will be used and the partitions and all data on them will be perfectly fine.
If you ever find yourself with dd, but without simple commands like ls, you can use dd to read a directory. Just copy the directory file to the terminal. That's what the ls command does too.
And don't forget that if the source disk is having issues, using ddrescue or gddrescue will continue and try to get all the input data it can, whereas dd will fail and stop at the first error. ddrescue has slightly different command options, but it is basically the same thing. It copies bytes from A --> B too.
Thank you Pete; it's funny the exact information I came to this page to learn is in the comments. Glad I decided to scroll down and and continue reading.For any experts out there reading I do have a question.Is there anyway to have the input file continue writing, repeating from begining to end, to the destination until the destion has had every bit replaced and is full?
eMMC and SD cards suffer damage from constant use and often need to be restored or replaced.
Yesterday I used it to backup a ODROID-C2 eMMC across the LAN from a x86_64 PC using the following command. I have used similar command to backup my other 4 ARM SBC's.
ssh -X 192.168.10.230 "dd if=/dev/mmcblk0 bs=64K | gzip -c --fast"|dd of=odroid64_eMMC.img.gz bs=64K status=progress
Thank you Sid. I came accross this article because I need to do just this.
I really like what you did there Sid