Pinterest Stumbleupon Whatsapp
Advertisement

Just because you’re running a Linux operating system doesn’t mean that you won’t run into problems from time to time. It’s always good to have a backup plan, just in case a problem strikes. Perhaps a rare Linux virus will attack; perhaps you’ll be targeted by ransomware scammers.

Your Linux installation might develop a bug; you could be upgrading your hard disk drive to a larger volume. Or your HDD might simply fail Avoid Linux HDD Faults & Errors With These Tools Avoid Linux HDD Faults & Errors With These Tools From personal experience, whenever I have a problem with any component in my computer, it's more often the hard drive than anything else. My CPU has never failed me, nor my RAM, and my motherboard... Read More . Whatever the problem, if you have a backup of your Linux installation — or even the entire disk — then getting things back up and running again will be relatively simple.

Whether you use functions that are built into your Linux operating system, or you install a third-party tool, it shouldn’t be long before you’re able to get your system back up and running.

1. dd, The Native Linux Cloning Tool

Perhaps the most powerful Linux tool of them all, dd (sometimes referred to as “disk destroyer”) can clone an entire HDD or disk partition to another. But if misused, it can delete the contents of your disk.

As such, you should use with extreme care. You’ll find dd built into most Linux operating systems. If not, install it from the package manager. To clone your computer’s hard disk, use the command:

dd if=/dev/sdX of=/dev/sdY bs=64K conv=noerror,sync

Here, sdX is the source disk, while sdY is the destination. The numerical value 64K, corresponds to the block size command, bs. The default value is 512 bytes, which is very small, so it’s best to include 64K or the larger 128K as a condition. However: while a larger block size makes transfer quicker, a smaller block size makes the transfer more reliable.

Advertisement

If you only want to clone a partition of your drive, use

dd if=/dev/sda1 of=/dev/sdb1 bs=64K conv=noerror,sync

As you can see, the partition sda1 (that is, partition 1 on device sda) will be cloned to sdb1 (a newly created partition 1 on device sdb), for instance a secondary, or external, HDD attached to your computer.

Tap Enter to run the command. How long it takes will depend on the size of the disk or partition. Just make sure that destination volume is large enough to store it!

2. Partimage, Partition Backup Tool

If you have run into problems trying to get your head around the instructions with dd, or would prefer to avoid accidentally deleting your HDD with typo, partimage is also available for most distros, and doesn’t carry any “disk destroyer” risks!

However, partimage does not support the ext4 filesystem, so avoid using it for cloning disks or partitions of that type. However, if necessary, it can be used to clone Windows disk formats (FAT32 or NTFS, although this is experimental) as well as the more widely used Linux filesystem ext3, and other, older alternatives.

Before starting, ensure that the partition you wish to clone us unmounted (with the umount command Mounting Hard Disks and Partitions Using the Linux Command Line Mounting Hard Disks and Partitions Using the Linux Command Line Looking to get more from the Linux terminal? Learning how to manually mount and unmount your hard disks is a great place to start. Modern Linux distributions make this much easier and intuitive than ever. Read More ). Otherwise you’ll need to exit partimage to do so before continuing with the process. You can exit at any time with the F6 key.

For Ubuntu, install with

sudo apt-get install partimage

You should then launch from the command line with

sudo partimage

This is a mouse-driven application, which requires you to first select the partition to be cloned.

Tap right on the arrow keys to move to the next section, Image file to create/use, and give it a name (or enter the filename of the image to be restored).

You can then select the correct Action to be done (ensure the chosen option has an asterisk) and press F5 to proceed. In the following screen, select the Compression Level, and your preferred Options. There is also the choice of setting an image split mode, and setting an instruction for what should happen after the backup is made.

Tap F5 to continue, confirm the details, then tap OK to begin the process. The speed of this will depend on the power of your computer.

If you’re looking for a quick and dirty — but safe — disk cloning solution for Linux, partimage is the best choice.

3. Partclone, Software for Partition Imaging and Cloning

For a more mature alternative to dd that supports backups of the ext4 filesystem, partclone is simple to use, but again requires text commands rather than a keyboard or mouse driven interface. Install with

sudo apt-get install partclone

…and launch with

partclone.[fstype]

…where [fstype] is the filesystem type of the partition you wish to clone.

The following command will create a disk image of hda1 (hard disk drive 1, partition 1) called hda1.img:

partclone.ext3 -c -d -s /dev/hda1 -o hda1.img

You might want to restore that image, so use

partclone.extfs -r -d -s hda1.img -o /dev/hda1

Further details on usage can be found on the partclone website.

4. Clonezilla, Popular Disaster Recovery Solution

For a more flexible solution, why not try Clonezilla? This disaster recovery, software is based on Partclone, and is suitable for a range of disk cloning tasks. All of the expected filesystems are supported, across Linux, Windows, and macOS (and beyond).

Unlike dd and partclone, however, Clonezilla is available as a bootable ISO, which you can burn to DVD or write to a USB stick. Clonezilla is straightforward to use, opting for keyboard-driven menus, rather than obscure commands, meaning that anyone can get to grips with it.

Find out more in our focused look at the Clonezilla disk imaging tool Clonezilla - Free Advanced Hard Drive Cloning Software Clonezilla - Free Advanced Hard Drive Cloning Software Read More .

You can also use Clonezilla in a professional capacity, to quickly image multiple similar PC setups with the same operating system.

While you might prefer to simply sync your vital data to the cloud 10 Cloud Solutions You Should Be Using on Linux 10 Cloud Solutions You Should Be Using on Linux Some mainstream cloud storage options don't offer a decent Linux client. But you're not out of luck. Many popular services do work under Linux. You can even roll out your own cloud solution! Read More , it is always a good idea to have a full disk backup that you can quickly restore in the event of system errors. Remember to use these tools with care, however, as they can easily cause you to accidentally lose your data.

How do you clone your Linux hard drive? Do you use these tools, or is there a utility you think we should know about? Perhaps you prefer to backup individual files Déjà Dup - The Perfect Linux Backup Software Déjà Dup - The Perfect Linux Backup Software Read More ? Tell us in the comments.

Image Credit: Joe Techapanupreeda via Shutterstock.com

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. S. S. Framson
    April 29, 2017 at 12:03 am

    Clonezilla has never been able to clone an entire stand alone system disk of Ubuntu 16.04 due to the reason that it always shows the destination disk as being smaller than the source disk. Clonezilla does this even when the physical size of the destination disk is twice that of the source disk. It must be noted that the source disk on which the existing Ubuntu OS is installed is a Samsung ssd of 240 GB and the destination disk is Samsung ssd of 520 GB. DO NOT PUT TOO MUCH FAITH IN CLONEZILLA'S CAPABILITY. Till April of 2017 there is no software tool that can copy and clone an entire Ubuntu OS from a ssd to another ssd. THANKS

  2. Hank Castello
    April 12, 2017 at 1:19 pm

    I've been using Clonezilla for years. Some of those other methods aren't safe to use before your morning coffee!

  3. apple
    January 9, 2017 at 11:53 pm

    The Linux HD is making squeaky noise so a clone is needed.

    When only the OS HD is present, using "fdisk -l", it shows sda with sda1 and sda2. However when placing a new HD (to be cloned to), it it listed sda and sdb. sdb1 and sdb2 have similar size of above. Clearly it seems the HD wit bootable OS becomes sdb and the empty new HD is assigned as sda.

    How can I be sure that the OS boot HD is indeed sdb and the empty HD to be cloned to is sda?

    I really don't want to erase the HD because it's so important.

    Thanks!

  4. germeten
    July 5, 2016 at 9:40 pm

    OK the first problem I run into running mount in terminal is I get: /dev/sdb1 on /type ext4
    According to your instructions, my HD should be sda but it's not. My CD drive may in fact have master status. Question is how do I identify my current HD to the new one I wish to clone. Don't want to make any fatal errors!

  5. johnC
    April 14, 2016 at 12:48 am

    Justin,, I ran into a file lock issue with using dd but it was good enough to get the
    job done with copying my hard drive to a USB stick.

    I deleted the file lock but got the error again and after digging thru it , I seen a issue
    with a symbolic link of a file into a file that was in /tmp. It was plexing me and I
    am trying to understand it. Any ideas??

    Otherwise, like your 'dd' tips and thank you. JohnC.

  6. Timal
    January 23, 2016 at 7:38 pm

    You and the commenters obviously know nothing about dd and cloning a hard drive.

    • Justin Pot
      January 24, 2016 at 4:11 pm

      I know enough to get the job done, and to try to teach other people, but I could always learn more. Got any tips?

    • Concerned Comment Viewer
      October 5, 2016 at 2:23 am

      And you have no idea to be useful or helpful in any of this... so please keep your comments to yourself so others may actually learn something that you pretend to know, but do not share.

      • Timal
        October 5, 2016 at 3:39 am

        Thanks for caring. What exactly are you here to "learn" about? How NOT to clone a hard drive? Be my guest. And yes, I will keep my comments to myself just like you are keeping yours to yourself. Have a nice day!

        • John Galt
          November 13, 2016 at 11:02 pm

          Timal's comments are the reason so many give up on Linux.
          They forget that they too were once a newbie and didn't know how to do things.

  7. Anders
    July 22, 2011 at 12:55 am

    This is ok method, as long as you don't use it to install on new/other computers.  Then there are much better methods.  Like FAI or other automatic installation softwares.

  8. Babr
    July 21, 2011 at 7:13 am

    You can also compress dd on the fly like this;
    dd if=/dev/sda1 |gzip > /backup-path/somename.img.gz
    reverse looks like this;
    gzip -dc /backup-path/somename.img.gz | dd of=/dev/sda1
     If you backup your root partition always do it with a live-cd, as said by jahid65.
    It is not smart to include a running /tmpfs that contains the thread of your dd command!

  9. jahid65
    July 20, 2011 at 6:31 pm

    I prefer fsarchiver, though it's not a partition cloning tool. It makes a compressed archive of a partition/file-system. you can put more than one partition in one archive. you can split that archive also. One of the advantage is that the file-system can be restored on a partition which has a different size and it can  be restored  on a different file-system. But you have to restore archive using live cd's (only applicable for root partition) or other linux distro installed in your HDD which has fsarchiver insalled. just make sure while you backup/restore archive the particular partition should be unmounted. well you can backup mounted partition(in case of root partion), but it is not preferable.