1

I have Ubuntu installed in an USB drive. It is not a live or persistent live install. It is a regular, full install.

Is there any way to backup the USB drive to a .img or .iso file, which I can later use to restore a bootable version of Ubuntu to this USB drive or another USB drive?

2
  • I suggest that you use Clonezilla because it is efficient and safe. A Clonezilla image is a directory with a set of files, and the big files are compressed. Clonezilla is smart enough to copy only used blocks (in file systems known by its tool Partclone). See this link where I explain more about Clonezilla.
    – sudodus
    Sep 9, 2022 at 15:18
  • 1
    The gnome-disks app has "Create Disk Image" as one of the menu options. This will create a .img file the size of the whole USB drive. You can use the same app to restore from a .img file to another USB drive of the same or bigger size.
    – user68186
    Sep 9, 2022 at 22:00

1 Answer 1

1

Note that this is a simplistic method, that will create large files already for "small" devices.

Backup:

  1. use e.g. lsblk -ape7 to find out which /dev/... you have the USB drive positioned at
    (e.g /dev/sdc to have a true dev to show below).
  2. make sure the drive is NOT mounted
  3. Open a terminal, type
    sudo dd if=/dev/sdc bs=128k | gzip --best >/place/to/store/backup.img.gz
  4. hit Enter and fill in the (root) password

Restore:
The example /dev/sdc needs to be same-size USB drive, or larger than the backup source.

Also: Make sure /dev/sdc is the CORRECT device,
all earlier content will be lost and will NOT be recoverable.

Enter gzip -c /place/to/store/backup.img.gz | sudo dd of=/dev/sdc bs=128k
in a terminal (at the bash prompt) and provide the requested input (root password).

Additional options to dd (notrunc, noerror) and gzip might be in place.

Options:
The image file produced by dd, when uncompressed (and at least of some common content types), may be mounted as a loop device:
lodev=$(losetup -f) - will create a device, if possible, and keep the name in $lodev
sudo losetup $lodev imagefile - will attempt to use the imagefile, create a 'removable' disk and mount the partitions in it.
sudo losetup -d $lodev - will dismount the image, and deconstruct the loop device.

5
  • Note that this is a simplistic method, that will create large files already for "small" devices.
    – Hannu
    Sep 9, 2022 at 21:39
  • I am not very familiar with dd, can we add the progress indicator as described here ? If the progress indicator feature is compatible with this, can you please edit the answer to add that? Sep 10, 2022 at 20:47
  • Should there be a space between > and /place/to/store/backup.img.gz ? Sep 10, 2022 at 20:49
  • it should work as is.
    – Hannu
    Sep 11, 2022 at 5:51
  • Progress; Try just appending status=progress to the dd commands, it seems to work based on a simple check.
    – Hannu
    Sep 11, 2022 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .