There are three ways, (that I know of, there might be more ways to this) to clone an installation (making an image of it). These are not the perfect way to clone a large drive. I'm using the 3rd method with an 128 GB disk. This will work fine with the same machine, but if you clone this into another machine, it might not work, or you'll need to configure the boot partition to work with that machine.
Gparted/Clonezilla Method
Gparted comes along with the Ubuntu ISO, you can use that during live USB. Clonezilla is a separate ISO, that can also clone an HDD/SSD.
In this method, you'll need at least 3 storage devices.
- Your main drive, you'll make all the settings in this one
- Your live USB, you'll use this one to clone the first drive to the third
- Your backup drive, you'll clone everything into this drive. You'll need to keep this offline. THIS HAS TO BE EQUAL TO OR LARGER THAN THE FIRST DRIVE
Steps
- Install Ubuntu to the first drive, make necessary additions and set it to your desire
- Turn off your system, now boot from the second drive, attach your third drive
- Open Gparted/Clonezilla and clone every partition (in the same order) from the first drive to the third. (you can resize these partitions, but it's much likely, that this will corrupt your partitions)
- Once the cloning is done, eject your third drive and keep it somewhere safe.
With the clone in the third drive, you can re-clone it from your third drive to your first drive and restart with the configurations you've saved.
Gunzip Method
With this method, you'll compress your main drive into an .img.gz
file. This will be easier to store thanks to the compression.
In this method, you'll need at least 3 storage devices.
- Your main drive, you'll make all the settings in this one
- Your live USB, you'll be using this to create an image to your third drive. This can be any Linux distro, the only requirements are
gunzip, dd, and necessary packages to read the file systems
- Your backup drive, you'll store the image in this device. Since this method compresses the disk, this can be smaller than the first drive. The resulting file size is dependent on the storage used. (I've compressed 128 GB disk into 14 GB file)
Steps
- Install Ubuntu to the first drive, make necessary additions and set it to your desire
- Turn off your system, now boot from the second drive
- Determine your main drive's letter(
/dev/sdX
, X being the letter you've determined), you can use Gnome disks(gnome-disk-utility)
, lsblk
, ...
- Attach your third drive, determine where it is mounted.
- Run
sudo dd if=/dev/sdX conv=syns,noerror bs=64k| gunzip -c > /path/to/third/drive/YOUR_BACKUP_NAME.img.gz
- Once the cloning is done, eject your third drive and store the file somewhere safe.
The reinstallation
- Boot from the second drive(live USB), attach a third drive containing the image file
- Determine your main drive's letter
- Run (as root),
gunzip -c /path/to/backup/YOUR_BACKUP_NAME.img.gz | dd of=/dev/sdX bs=64k
.
Gunzip + Ventoy Method
This method is similar to the second method, but utilizing Ventoy's persistent live USB's to eliminate the need of a third drive.
You'll need at least 2 storage devices
- Your main drive, you'll make all the settings in this one
- Your live USB + temporary storage, you'll clone with this, and store in this drive. Since this will store quite a bit, I recommend at least 64 GB for this one.
Steps
- Install Ubuntu to the first drive, make necessary additions and set it to your desire
- Create a ventoy disk and set persistence storage for your desired Linux distro, (I won't get into the details of this, follow the documents on the ventoy's site)
- Boot from your ventoy drive into live USB with persistent storage. Determine where your persistent storage is mounted.
- Run
sudo dd if=/dev/sdX conv=syns,noerror bs=64k| gunzip -c > /path/to/third/drive/YOUR_BACKUP_NAME.img.gz
- Once the cloning is done, turn off your computer and store the file somewhere safe.
The reinstallation
- Boot from the second drive(live USB) with persistent storage
- Determine your main drive's letter
- Run (as root),
gunzip -c /path/to/backup/YOUR_BACKUP_NAME.img.gz | dd of=/dev/sdX bs=64k
.
Conclusion
All these methods will take at least an hour depending on your setup, drive speeds and used storage. You can replicate the gunzip method with a second computer, but I've assumed you have only one computer + sata/nvme to usb 3.0 adapters are usually slower than using it in the computer.