Two uses of dd
All in all, in everyday life I mainly use dd for two purposes: writing a bootable ISO image to removable media, such as a USB stick, and cloning hard disks, often increasing the size of a partition if the new disk is larger than the old one.
Some preliminary suggestions are necessary.
- Use the dmesg and lsblk commands to clearly identify the correct device names, otherwise you risk completely deleting your data. Pay very close attention to the device names, because even a small mistake can have disastrous consequences.
- It is essential that the partitions involved are not mounted.
With that in mind, let's look at the two commands for both use cases.
How to write a bootable ISO image to a removable media
Let's assume that the file is called liveimage.iso and that the USB stick is /dev/sdX (replace these details with the appropriate values for your case!). The command in this case will be:
sudo dd bs=4M if=/path/to/liveimage.iso of=/dev/sdX conv=fsync oflag=direct status=progress
Enlarge your hard... drive
This is the typical situation: when you change your hard drive. You buy a new device with much more capacity than the previous one, and you want to transfer everything from one to the other, including the partition table, the boot partition, etc.
Let's assume that the old disk is /dev/sdX and the new one is /dev/nvme0nX. So the command to clone the entire disk (including the partition table and bootloader) will be:
sudo dd if=/dev/sdX of=/dev/nvme0nX bs=64M conv=noerror,sync oflag=direct status=progress
Just two warnings. The first is that after executing the dd command, partitions in both disks will have the same UUIDs. Therefore, the PC may become confused and I recommend disconnecting the old disk one when the system first reboots. The second is that if you use certain file systems such as ext4, you could use gparted to increase the size of one or more partitions. In this case, gparted may complain about “backup GPT table”. Give it permission to fix the problem: it's just one click.
And finally, here are a few brief explanations
- conv=noerror,sync continues even with unreadable sectors, filling them with zeros
- oflag=direct tells dd to bypass the operating system cache and write directly to the disk; this prevents data from remaining in the cache without being written immediately
- conv=fsync forces dd to perform a fsync() on the destination file after each write; this ensures that the data is physically written to the device before moving on to the next block.
Posted on 2025-08-13
__________________
Copyright © 2019-2025 Marcello Zaniboni