Date created: Friday, March 12, 2021 8:36:01 AM. Last modified: Sunday, October 27, 2024 4:48:19 PM

'dd' - Notes

dd commands:

Dump CD to ISO

$ dd if=/dev/cdrom of=/tmp/cdimg1.iso

Generate 10GBs

$ dd if=/dev/zero of=/tmp/image bs=1M count=10000

 

To view dd progress with more recent dd:

$ time sudo dd status=progress if=ubuntu-18.04.3-4.9-minimal-odroid-n2-20190806.img of=/dev/mmcblk0

 

To view dd progress when using older dd:

$ dd if=ubuntu-22.04-4.9-minimal-odroid-n2-20220622.img | pv | sudo dd of=/dev/mmcblk0
7944192+0 records in5MiB/s] [                                                                                                                                      <=>         ]
7944192+0 records out
4067426304 bytes (4,1 GB, 3,8 GiB) copied, 555,282 s, 7,3 MB/s
3,79GiB 0:09:15 [6,99MiB/s] [                                                                                                                                   <=>            ]
7944192+0 records in
7944192+0 records out
4067426304 bytes (4,1 GB, 3,8 GiB) copied, 581,472 s, 7,0 MB/s

 

To view dd progress in a separate terminal when using older dd:

$ sudo dd status=progress if=ubuntu-18.04.3-4.9-minimal-odroid-n2-20190806.img of=/dev/mmcblk0
$ pgrep -l '^dd$'
4858 dd
$ kill -USR1 4858

The progress will be dumped in terminal window where dd is running. Use watch to have continuous output:

$ watch -n 60 'sudo kill -USR1 4858'

 

To compress a drive copy:

dd if=/dev/hdb | gzip -c > /image.img

To restore a compressed drive copy:

gunzip -c /image.img.gz | dd of=/dev/hdb

Zero out free space on a drive before copying into gzip for better compression:

mkdir /mnt/hdb
mount /dev/hdb /mnt/hdb
dd if=/dev/zero of=/mnt/hdb/zero
rm /mnt/hdb/zero
umount /mnt/hdb
dd if=/dev/hdb | gzip -c > /image.img

Faster copy:

bs=100M conv=notrunc

Previous page: 'curl' - Notes
Next page: 'dig' - Notes