How to copy from one disk to another, the best way

If you are migrating, say, your /home directory to a new drive, I found the following commands to be the most useful. We assume you went into gparted or a similar tool and formatted the new drive/partition to ext4.

Step 1: Remount the drive

First, remount the new drive with the most efficient parameters. Here the new drive is an SSD and it’s re-mounted in ‘as fast as possible’ parameters. We assume that /dev/sdc1 is your new drive’s partition and that you wanted to mount it to, say, /newhome

# mount -oremount,defaults,noiversion,auto_da_alloc,noatime,errors=remount-ro,inode_readahead_blks=32,discard /dev/sdc1 /newhome

Step 2: The actual copying of data

Here is the rsync command that I found that was the safest and most useful:

# rsync -axHAXWSv  --numeric-ids --info=progress   --delete-excluded  /home/turgut   /newhome  --delete --ignore-times  --exclude='/home/*/.gvfs'   --exclude='/home/*/.l
ocal/share/Trash'   --exclude='/var/run/*'   --exclude='/var/lock/*'   --exclude='/lib/modules/*/volatile/.mounted'   --exclude='/var/cache/apt/archives/*'   --exclude='/home/*/.mozilla/f
irefox/*/Cache'   --exclude='/home/*/.cache/chromium'

This excludes lots of temporary files, and does a checksum-based comparison of the copied files, should you have to re-run this command a second time — and you know you will 🙂   Because we excluded the access times with the remount command, we need the –checksum parameter. This keeps all symlinks, all access rights, dates, etc, all the same. Handles sparse files efficiently and more.

If the verbosity is too much, exclude the ‘v’ parameter and change the –info=progress to –info=progress2  which will give you an ‘animated’ progress line.

 

Leave a Reply