How to clone a Linux system.

APM

APM

Associate
Joined
9 Nov 2011
Posts
1,460
Location
Wales
I use Macrium Reflect to clone my windows system on a regular basis and I would like to do the same for my Linux install.

I tried DD which is ok if you only want to clone a partition whereas I want to clone an entire drive with 4 partitions on it.

I'm looking at Clonezilla which I guess I can use to make an image file but then I'd have to run a usb live to re-install that image back to another HDD I guess?

What I really want is a way to just clone a running Linux install to another drive which I could then just plug and play at a later date if I have a drive failure with the initial drive.
Does such a thing exist or what is the nearest approximation to it?

Many thanks in advance.
 
Last edited:
Assuming GPT+UEFI boot with default loader path, my usual approach is :

Code:
source_disk=/dev/sda
destination_disk=/dev/sdb

# copy GPT partition table
sgdisk --replicate=${destination_disk} ${source_disk}
sgdisk --randomize-guids ${target_disk}

# for every mountpoint of a "real" filesystem
findmnt --real --noheadings --raw --output target,fstype \
| while read source target fstype ; do
  # replace the disk name of the source filesystem block device with the new disk name
  dest_part=${target/${source_disk}/${destination_disk}}
  # make filesystem
  mkfs.${fstype} ${dest_part}
  # make a temporary mount point if it doesn't exist
  [ ! -d temp_mnt ] && mkdir temp_mnt
  # mount and copy all files in only that filesystem (not sub-mounts), preserving permissions, xattrs, hard-links, posix ACLs, and uids/gids.
  mount ${dest_part} temp_mnt && rsync -axAHX --numeric-ids ${target}/ temp_mnt/
  # finished with that filesystem
  umount temp_mnt
  # on to the next one
done

Then fix /etc/fstab if you're using filesystem UUID, or partition UUID. If you're using partlabel, good to go!

If you're using ZFS then better to do a zfs send replication stream, then you get all snapshots/compression/encryption, and it goes as fast as your drive can go anyway because it doesn't need to stat()/open()/close() every file twice like rsync.
 
Last edited:
matja you are a star,thank you very much.

I should have stated that the system is a Fedora 36 workstation edition.

I will look into the info you provided and have a go at running those commands if they are available to me for the system I am in otherwise I have a lot more info to work with than previously so thank you again.
 
I'd try in a VM with a pair of virtual disks first, to see how it works out first :)

sgdisk is part of the gptfdisk package on my distro, not sure about Fedora. It does non-interactive GPT partitioning, useful in scripts. "gdisk" is the interactive version (like fdisk, but more GPT options).

If the disk sizes are different, then you'd need to manually create the partition table first, in the same partition order.

If you have/want MBR partitions, that part would be different.

Sorry I don't know any pre-made tools that do the whole lot. Like you said, Clonezilla might do the job - but I haven't used it for a long time.

I know that Clonezilla can be a bit more clever than just a straight dd, I think it uses e2image/xfs_copy/etc to only copy allocated blocks, not free space, so if you only have 10GB of files on a 1TB drive, it won't take forever.

However, an advantage of the rsync approach rather than a straight dump/image approach is you get a defrag for free :)

Oh, and if its booting via UEFI, having the loader named /EFI/BOOT/bootx64.efi in the ESP partition means it should boot on any machine, even if it doesn't have a boot entry for the loader, since that's the fallback name. I use this for my machines and bootable USB sticks etc.
 
Last edited:
All good info thanks again,especially the boot info.

The disks are both 1TB with the existing OS having 57Gb reserved so I'm thinking the native disk will be smaller compared with the back up disk.

Rescuezilla is another option I've been looking at ,it would be nice to be able to just clone to another drive as I do with Windows then just plug and play the back up drive if the need arises but it looks like a Clone or Rescue zilla image back up will have to do in the case of Fedora.

Not too much faffing running a live usb to transfer the image onto another drive I guess though maybe a little time consuming.
I have Gparted on a disk somewhere so I may have a look in there and see what options that offers.
 
I don't have a huge amount of experience with this, but I have recently cloned a drive with my Linux installation on (multiple partitions) using dd so I'm not sure what the issue you're having is.

I booted from a usb install image to do so since none of the partitions can be mounted at the time.

Edit: I guess if you really want to do this live then DD is useless.
 
Last edited:
I'm looking to clone my Linux system and found this thread as I searched for Rescuezilla. What is the "DD' reference that is being used in this thread?

What I'm looking to do is have a backup of my Linux setup just in case the system dies on me as it's a really old laptop. Rescuezilla is what I'm looking for?

I'll be backing up to an external HDD.
 
Last edited:
I'm looking to clone my Linux system and found this thread as I searched for Rescuezilla. What is the "DD' reference that is being used in this thread?

What I'm looking to do is have a backup of my Linux setup just in case the system dies on me as it's a really old laptop. Rescuezilla is what I'm looking for?

I'll be backing up to an external HDD.

Its this, not sure if its still relevant to you but here: It's a command in linux.

 
Last edited:
Foxclone

Linux app. Claims to offer a gui front end for partclone. I haven’t tried it and it doesn’t appear to be open source so we can’t audit the code.
 
Back
Top Bottom