12

I have an Ubuntu 12.04 production server with a 500 GB (nearly 15 gb used) HDD. I want to duplicate whole HDD including, its partition structure, to another HDD with 400 GB size so that changing the HDD will not affect the working system.

Which tool is the best solution for this task?

2
  • Do you have physical access to the server? If so, can you install a drive in RAID? That would probably be the easiest and safest solution.
    – don.joey
    Aug 29 '13 at 19:33
  • Clonezilla Sep 3 '13 at 9:12
6

There are many tools that can do this, each with its own advantages and disadvantages. Clonezilla is a utility that's often used for this task; however, I'm not sure how well it would cope with the fact that your target disk is smaller than the source disk.

Another option is to manually partition the target (using GParted, parted, fdisk, gdisk, or some other tool), create filesystems on the target, mount the target partitions, and copy everything over with cp or tar. This will require some additional changes on the target, such as (possibly) adjusting its /etc/fstab and installing a boot loader. Overall, this method requires more effort than many, but if you know what you're doing, it's quite flexible, and it can definitely copy from a larger disk to a smaller one, provided the files will actually fit into the target space.

6
  • 1
    Wouldn't copying the contents of the entire filesystem with cp pose problems for directories like /dev and /proc? Aug 28 '13 at 20:18
  • 1
    The /dev and /proc directories are both dynamic -- they're created as virtual filesystems by special drivers in the kernel. Thus, you'd normally omit those directories from a copy operation.
    – Rod Smith
    Aug 29 '13 at 16:46
  • 1
    Yes, you have to omit those. Use "cp --one-file-system".
    – Jakob
    Sep 3 '13 at 22:16
  • By default clonezilla pseudo-clones the HDD: (1) it backs up the structure metadata, including MBR; (2) the used data sectors, meaning that it ignores the free space of partitions with filesystems that it understands; and (3) compresses the backed-up partitions. All this means that it can "clone" a 500GB HDD to a 400GB HDD as long as there is at least 100GB of free space on the original disk. In other words, clonezilla would cope with the fact that the target disk is smaller than the source disk.
    – landroni
    May 6 '14 at 0:36
  • @RodSmith, Regarding "copy everything over with cp"... Then what about metadata (last accessed timings and etc)?
    – Pacerier
    May 2 '15 at 11:50
3
+25
  1. Backup your production-hdd.
  2. Use gparted to shrink your production-harddisk to a little less than the capacity of your target-disk, in your case smaller than 400GB.
  3. Copy whole hdd. To do so, boot from a live-cd and use dd if=/dev/sda of=/dev/sdc bs=1M where sda is your production-hdd and sdc your new hdd. Or something like clonezilla (copy whole disk).
4
  • 1
    Any filesystem-resizing operation comes with some risk of catastrophic filesystem failure. That risk is small, but still, taking that risk is unwise when there are alternatives (such as using Clonezilla, if it can handle the smaller target, or using tar or cp).
    – Rod Smith
    Aug 29 '13 at 16:48
  • 1
    We use gparted on a regular basis in our production environment. Quote from Clonezilla: "The destination partition must be equal or larger than the source one." Manual copy is ok if you have the required knowledge about partitions, bootsectors, fstab etc.
    – Clausi
    Aug 30 '13 at 6:48
  • 1
    I stand by my statement: Partition resizing poses some risk of catastrophic failure. Note: catastrophic. A power failure or system crash mid-resize, a bug, or other problems can cause the resize to result in mangled data structures that will be time-consuming and costly to fix, if they can be fixed at all. There are better alternatives, even if Clonezilla isn't one of them. If you do this regularly and haven't been bitten, then that means you've been lucky, nothing more.
    – Rod Smith
    Aug 30 '13 at 15:49
  • 1
    Much better than repeating your opinion and referring to luck would be a substantial proof of your theory. In my experience a "catastrophic failure" can only occur if you have no backup - which is no.1 one my list. ;)
    – Clausi
    Sep 2 '13 at 7:27
1

I would recommend Clonezilla, its simple to use, performs whole disks backup, and doesnt use much space for the backup also.

To do that, first you would have to download the clonezilla ISO from here.

After you have downloaded it, you will need to burn it to a CD.

Then you will have to boot from it to do the full system Backup.

The full procedure for it is given here- http://clonezilla.org/clonezilla-live-doc.php

You will have to choose the option "Save disk image", the procedure for which is given here-http://clonezilla.org/show-live-doc-content.php?topic=clonezilla-live/doc/01_Save_disk_image

After you have made the backup, you can restore it using the option- "Restore Disk Image", the procedure for which is given here- http://clonezilla.org/show-live-doc-content.php?topic=clonezilla-live/doc/02_Restore_disk_image

Look into it. If you have any queries let us know.

Thank You!

1

As others proposed, Clonezilla could do the job if you resize working partition to smaller size. However, I have seen there is a tool named FSArchiver that allows to restore data to a smaller drive, as soon as the data fits in (like in your case). I am sorry I can not help you more in this since I have used only Clonezilla but there is some information in the link and in their forum.

0

You can use dd to copy the disk. This post describes how to clone a hard drive using an Ubuntu Live CD.

4
  • But keep in mind that hdds are nkt in equal sizes. will any problem occur because of size difference?
    – hunter
    Aug 23 '13 at 6:34
  • 1
    Copying from a larger disk to a smaller one with dd is not recommended, since the result is likely to be be lost and/or truncated partition(s), and therefore data loss.
    – Rod Smith
    Aug 23 '13 at 17:01
  • A little more detailed answer on dd in this post: askubuntu.com/a/55908/58950
    – carnendil
    Aug 23 '13 at 17:35
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – RolandiXor
    Aug 28 '13 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.