How to clone a Linux system

Making a clone of your Linux system is a great way to make a complete backup. This type of backup would preserve all your system and personal files, as well as any customizations and settings that you have applied to your operating system over time (assuming everything is on one hard drive). Cloning and restoring a Linux system is relatively easy, since Linux will not encounter errors if you clone it onto different hardware – at worst, you may have a few hiccups, such as the need to uninstall and install necessary drivers.

You can even make a clone of your Linux system as its running. There are a few applications built especially for this type of function, like Partimage and Clonezilla, but we can also use a simple, default command line tool such as dd. In this tutorial, we will take you through the step by step instructions to make a clone of a running Linux system. You will learn three different methods below and can choose the one that you think fits your situation best.

In this tutorial you will learn:

  • How to clone a Linux system with dd command
  • How to clone a Linux system with Partimage
  • How to clone a Linux system with Clonezilla
How to clone a Linux system
How to clone a Linux system
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software dd, Partimage, Clonezilla
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to clone a Linux system step by step instructions




If you do not wish to install extra software, and can clone your Linux system directly to another hard drive or solid state drive, the dd command is the recommended method for you to follow below. If you prefer to make a clone file of your installation, then the Partimage or Clonezilla options would be your best route.

Clone Linux System With dd

dd can be used to clone your entire hard drive that contains your Linux operating system installation. Everything will be copied, including partitioning information and all data present on the hard disk at the time of cloning.

The easiest way to use this tool is to insert your backup hard drive into your computer. You do not need to partition or format the backup disk in any way, as dd will write to it as a block device.

Once the hard disk has been inserted, execute the following command to clone your Linux system onto the backup disk:

$ sudo dd if=/dev/sda of=/dev/sdX bs=64K conv=noerror,sync
  • if (input file) is block device /dev/sda
  • of (output file) is block device /dev/sdX
  • bs (bit size) is 64K, as small chunks are less likely to encounter errors
  • conv settings are noerror, and sync which will try again on error and synchronize input and output

In this example, /dev/sda is the disk that contains our Linux system (the disk being cloned). /dev/sdX is the backup disk which we are cloning to. You can use fdisk -l to obtain the device paths to your own hard drives, and then adapt the command above as needed.

After successfully running the command, you can pop your backup hard disk into any computer, and you will load into the Linux system just as you would on the original disk.

Clone Linux System With Partimage

Keep in mind that Partimage can only clone unmounted partitions, so your root partition cannot be currently in use if you hope to clone it.

  1. The first step is to install Partimage:
    $ sudo apt install partimage
    
  2. Next, launch Partimage from command line:
    $ sudo partimage
    
  3. Use the arrow keys on your keyboard to select the partition that you want to clone. Once it is highlighted, press Tab to move onto the next field. Pick a name for your clone, and then press F5 to proceed to the next menu.



    Select partition to clone, and fill out the desired image name
    Select partition to clone, and fill out the desired image name

  4. Choose your desired compression settings, then hit F5 to continue.
    Choose compression settings for cloned image
    Choose compression settings for cloned image
  5. Partimage will then make a clone of your selected partition, and output it to the image file you specified.
    Partimage is done creating our clone of the partition
    Partimage is done creating our clone of the partition

Clone Linux System With Clonezilla

  1. The first step is to install Clonezilla:
    $ sudo apt install clonezilla
    
  2. Next, launch Clonezilla from command line:
    $ sudo clonezilla
    
  3. Clonezilla will allow us to clone our Linux system to an image file, or directly to another hard disk. Choose whichever one you desire, but we will go with image file in this example.

    Choose whether to clone to image file, hard disk, or something else
    Choose whether to clone to image file, hard disk, or something else



  4. Next, choose to clone your local hard drive, unless you have some situation where you need to clone the disk from a different computer via the network.
    Select to clone the local disk
    Select to clone the local disk
  5. Next, choose which mode you would like to use. Stick with beginner unless you have some specific settings you need to apply to your cloned image.
    Choosing beginner mode
    Choosing beginner mode
  6. Choose whether you want to save the entire disk image, or just that of a partition.
    Save disk or partition image
    Save disk or partition image
  7. Lastly, choose a name for your cloned image.
    Choose name
    Choose name

    Clonezilla will then make a copy to your specified image. All done.

Closing Thoughts




In this tutorial, we saw how to clone an entire Linux system. This included a whole disk, individual partition, and even a currently running operating system. The stock dd tool suffices for the job, but extra applications are also available like Partimage, Clonezilla, and a slew of others that we did not cover here. Cloning your Linux installation is ideal for a backup solution and to load your same configuration onto a whole array of computers.



Comments and Discussions
Linux Forum