How do I clone an Ubuntu system to a new machine?

16,486

Solution 1

Clonezilla is your friend. Download its ISO from https://clonezilla.org/downloads/download.php?branch=alternative then make a LiveUSB from the ISO file. Reboot your PC after attaching the destination drive to the original PC and boot from the Clonezilla USB. Choose disk to disk and clone away!

Then, for your sanity's sake, once the disk-to-disk cloning completes, image the system with Clonezilla, saving the partitions (which will be compressed) to the target drive's root or /home partition. Once completed, boot from that drive, be it HDD or SSD. Obtain the size of the compressed image, and burn that to DVDR. Make a second copy to a USB flash drive. Verify the contents match the source, then the DVDR goes offsite, and the copy on USB is attached to the Clonezilla flash drive so you can reconstitute your system as of (today) if you ever need.

Solution 2

When using Linux copying or migrating your existing system to an other harware is much easier than you might think with your Windows experience. You need a copy of your HDD or put your existing one in your new computer and you have pretty good chances that you boot in your new hardware without any problem.

If you want to copy your existing system to a new HDD:

  1. Make sure your new location is as big or bigger than your existing one.

  2. Boot a live CD (any one will fit you that offers a terminal).

  3. Make sure your existing system (the drive you want to move) and your new drive are connected to your machine but they are not mounted. (cat /proc/partitions will show your available drives.)

  4. Now this will do the trick for you:

    sudo dd bs=4M conv=sync,noerror status=progress if=/dev/hda of=/dev/hdb 
    

    where /dev/hda is your existing system and /dev/hdb is the new drive you want to copy your existing system to. Take care not to use partition numbers because you want to copy everything (eg. MBR, partitions and all contents) to your new location.

Be sure not to exchange the drive names in if=your_existing_drive and of=your_new_drive or you will destroy your existing system by overwriting it with the contents of your new drive (e.g. a bunch of pretty zeroes if that is a brand new formatted drive).

If you could boot from /dev/hda in your old system chances are that your new cloned drive /dev/hdb will fit in any computer hardware and you will boot from it. After you started your new system you may finish adjusting settings that your new hardware offers or requires, and check for gparted to adjust your partition sizes if your new drive is bigger than the old one.

Share:
16,486

Related videos on Youtube

eSurfsnake
Author by

eSurfsnake

Updated on September 18, 2022

Comments

  • eSurfsnake
    eSurfsnake over 1 year

    I have an Ubuntu system with a large project, many small projects, and (of course) loads of packages and libraries.

    If I buy a new computer and want to replicate all of this, how do I do it? I presume installing Ubuntu on the new machine and then copying the file tree from some point down will fail since the new machine will have it's own way of viewing things, understanding of how things are tied together, etc., and just replacing the new file tree starting with root with a copy from the old machine is an idiotic idea.

    • oldfred
      oldfred over 4 years
      I still believe in new clean install & restore /home, perhaps some settings in /etc. but are the applications server type that have folders in /, not in /home? You can export a list of installed apps and restore that. You should normally do all that as backup as when hard drive fails, you have to restore from backups. Best practice for Backups - theFu ubuntuforums.org/showthread.php?t=2368992& ubuntuforums.org/…
  • chili555
    chili555 over 4 years
    +1000 for clonezilla!
  • eSurfsnake
    eSurfsnake over 4 years
    I presume once I do the clone to a hard drive, I then use Clonezilla on the new machine, having it read from the hard drive?
  • K7AAY
    K7AAY over 4 years
    Clone drive-to-drive in Clonezilla, and then make a backup drive-to-image. That creates a file you can then write to DVDR.
  • Mast
    Mast over 4 years
    Why would you need both USB and DVDR? Nothing indicates the clone has to be archived.
  • K7AAY
    K7AAY over 4 years
    Belt-and-suspenders. A DVDR lasts longer than a flash drive, so that's what I suggest goes offsite.