4

I currently have Ubuntu MATE installed (full install) on a flash drive. How do I make an exact copy of the flash drive for backup purposes? Because I'm getting scared about the eventual inevitable failure of the drive.

2 Answers2

4

A complete 1:1 clone/image of any drive or partition can be made with dd.

First find out the file descriptor corresponding with the device you want to back up. The command lsblk will be useful for that. I will assume now that you want to back up the partition /dev/sdb1, please change this value to match your configuration.

Then you can run dd like this:

sudo dd if=/dev/sdb1 of=~/my-backup.img bs=4M status=progress

Warning! Whatever you specify as of=... will get overwritten! Make sure you do not accidentally wipe your data and check the correctness of this argument twice!

Here is what the parameters mean:

  • if=/dev/sdb1: read from file /dev/sdb1 (which represents the raw partition)
  • of=~/my-backup.img: write to the specified file. File name, extension and location is arbitrary, just don't write to the same partition you are reading.
  • bs=4M: always process blocks of 4 MB at once. This speeds the process up.
  • status=progress see some progress info while it is running

When you later want to restore the image again, simply swap if= and of= so that the file gets read and you write to a partition (which should have the same size).

Byte Commander
  • 107,489
  • Sorry, i have a stupid question. So with the filename post "of" I would put something like "of=/home/flashbackup.img". I assume .img is necessary? – Thomas Yun Sep 14 '16 at 14:03
  • 1
    The .img is not necessary, as Linux systems normally don't care about file extensions. It's just for the humans to get a better idea what the file contains. Where you store the image file is arbitrary, just make sure you're not writing it to the same device you're reading from. I would recommend ~/my-backup.img (~ stands for /home/YOUR-USERNAME). – Byte Commander Sep 14 '16 at 14:09
  • If this answer solved your problem, please consider accepting it by clicking the grey check button on its left. Also make sure to invest two minutes in taking the [tour] where you can learn the most important things about how this site works. Thanks and welcome to Ask Ubuntu. – Byte Commander Sep 15 '16 at 14:13
2

1) Either get another one of the EXACT same flash drive, or a different flash drive greater in capacity.

Note: You could also write it to a .img file if you don't care about having a functional backup. (As in, you can boot the backup)

2) Boot from a live DVD, or any other Ubuntu install that's not the USB stick you want to clone

Disclaimer: I WILL NOT BE RESPONSIBLE FOR YOU BRICKING YOUR COMPUTER BECAUSE YOU FAILED TO SPECIFIY THE CORRECT BLOCK DEVICE!

To identify which is the correct block device, run: lsblk.

3) Fire up a terminal and run:

#Replace /dev/sdb and /dev/sdc accordingly!!!

sudo dd if="/dev/sdb" of="/dev/sdc" status="progress"

4) Wait. For possibly several hours, depending on the size of your USB drive.*

*You can add the bs=4M parameter to the end of the dd command, which will speed it up exponentially. It may or may not boot though. You could try doing it with the parameter first, and if it didn't work, then without.