Linux How-To Use DD to Copy A Drive to a New One
There are times when it’s necessary to migrate all the data from one disk to another.
- Upgrading to a larger disk
- Pre-emptivey moving to a new drive following a SMART alert
- Making a copy before moving a server
There are lots of software tools that can be used, both open-source/free and paid-for, for example CloneZilla
One of the simplest is simply to use the Linux command ‘dd‘ from a recovery disk
dd is a command-line tool for copying disk content (filesystems) from one location to another, primarily used to make a ‘file’ of a specific size for speed/io testing, or to copy an entire disk image.
WARNING: dd is often called data-destryer for good reason if you’re not 100% sure on what you are doing !
As simple and quick as DD is, as with most CLI tools, it operates ‘silently’ unless there are errors to report – and so there are disadvantages for use as a drive duplication too, like being able to monitor the progress of the disk copy – below are the 2 most common solutions …
How to show progress during a dd copy
Simple Method – using iostat
If you started your machine with a SysRescCD Live-Linux distribution (the most widely used way to get a box ‘up’ to be able to DD the contents – then you have access to another command-line tool called ‘iostat‘
To check how far your disk duplication has reached, simply open another terminal window (ALT-F2) and type:
This will report the KB_read and kB_wrtn (written) for your disks – divide the written by 1024 and you have the amount of MB completed so far, and can guestimate the remaining time based on the size of the disk (which you can obtain from an ‘fdisk -l’
Advanced Method – sending a USR1 kill to dd
For a more ‘interactive’ progress report you can send a USR1 signal to the dd process from another terminal window …
- Determine the process-id (pid) for the running dd command:
$ pgrep -l ‘^dd$’
This will output the pid and binary name e.g. 2188 dd
- Send the USR1 signal to the pid:
$ kill -USR1 2188
When dd picks up the USR1 signal it will print the current statistics to STDERR
on the original terminal and continue.
- Switch to the terminal running dd and view the output:
12698193+0 records in
12698193+0 records out
54735860224 bytes (55 GB) copied, 4529.87 seconds, 12.1 MB/s
- Use the ‘watch‘ command to execute the USR1 kill every minute:
$ watch -n 60 kill -USR1 2188
- Kill the watch when the copy has completed with CTRL-C