Skip to content
Log In Sign Up info@muvcloud.com

Read This Before Any dd Command

  • No undo, no question: dd writes to its output at once and never asks for confirmation.
  • Check the target every time: device names can change between boots and when a disk is added. Run lsblk right before the command.
  • Never write to a disk in use: nothing on the target may be mounted.
  • Snapshot or backup first: on a VPS, take a snapshot in your provider's control panel before any write to a device.
  • Read the line again: look at of= once more before you press Enter.
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,MODEL

The examples use /dev/sdX as a placeholder for a device; on a VPS, disks are often named vd followed by a letter. Reading the list is explained in how to list disks in Linux.

The Syntax

dd if=INPUT of=OUTPUT bs=BLOCK_SIZE count=N status=progress
OperandMeaning
if=Input file or device
of=Output file or device
bs=4MBytes per read and write
count=Number of blocks to copy
status=progressShows progress
conv=fsyncFlushes to disk before exit
oflag=directBypasses the page cache

dd uses key=value operands instead of dashes. Without of= it writes to standard output, and without if= it reads standard input. The default block size is 512 bytes, which is slow; 1M to 4M suits most copies. On Ubuntu 26.04 dd comes from the Rust rewrite of the core commands; these operands are the standard ones, but its messages may be worded differently.

Create a Test File

dd if=/dev/zero of=testfile.bin bs=1M count=1024 status=progress
dd if=/dev/urandom of=random.bin bs=1M count=100

The first line writes 1 GiB of zeros, the second 100 MiB of random data, which does not compress. Use them to test uploads, transfers, or quotas, and delete them afterwards. For a swap file, follow how to add a swap file in Linux, which says which method each file system needs.

A Rough Disk Write Test

df -h .
dd if=/dev/zero of=ddtest.bin bs=1M count=1024 oflag=direct status=progress
rm ddtest.bin

Check free space first. oflag=direct skips the memory cache, and the last line of output shows the speed. This measures one sequential write only, and storage that compresses data can make zeros look faster than real data. For a fuller picture, see how to check disk I/O in Linux.

Back Up a Disk to an Image File

The source disk must not be in use: image it while it is unmounted, or from a rescue system. An image of a running system disk is inconsistent. The image file belongs on another disk with enough free space. Here the device is only read and the output is a file:

lsblk -o NAME,SIZE,TYPE,MOUNTPOINT
sudo dd if=/dev/sdX of=/mnt/backup/sdX.img bs=4M status=progress conv=fsync
sudo dd if=/dev/sdX bs=4M status=progress | gzip > /mnt/backup/sdX.img.gz

Compare the size of the image with sudo blockdev --getsize64 /dev/sdX. For files rather than whole disks, the rsync command is the better tool.

Restore an Image to a Disk

This overwrites the whole target disk. Before you run it:

  1. Run lsblk and identify the target by size and model, not by name alone.
  2. Confirm that its mount point column is empty.
  3. Confirm that the target is at least as large as the image.
  4. Type the command, then read of= once more.
sudo dd if=/mnt/backup/sdX.img of=/dev/sdX bs=4M status=progress conv=fsync
gunzip -c /mnt/backup/sdX.img.gz | sudo dd of=/dev/sdX bs=4M status=progress conv=fsync

Afterwards, sudo partprobe /dev/sdX makes the kernel read the restored partition table. partprobe comes with the parted package.

Save the First Sector

On a disk with an MBR partition table, the first 512 bytes hold the boot code and the partition table. Reading them is safe and gives you a copy to compare against:

sudo dd if=/dev/sdX of=sdX-mbr.bin bs=512 count=1

Common Problems

  • No progress shown: add status=progress.
  • A no-space message at the end: when dd writes to a device until it is full, this is expected. When it writes to a file, the target file system is full; see no space left on device.
  • Permission denied: devices can be read and written only by root; use sudo.
  • Very slow: the block size is too small; set bs=4M.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations