64

The HDD I have my Ubuntu installed is about to fail. I would rather not lose 3 years worth of data, customisation and apps. I am looking for a way to move the complete system (SWAP included, because I'm not sure if I can relink the system to a new SWAP partition) to another HDD. But not the complete HDD< only the partition containing Ubuntu, to a partition on a different HDD. Basically I'd like to do what I've been able to do with Norton Ghost for my Windows install. I thought about using Clonezilla but I think I would have issues with GRUB (Especially trying to boot from a different UUID than what is in the conf file). do you know of any way this could be done?

PS, my home directory is encrypted but that's not really an issue, because I can work around that.

EDIT: changed the explanation to make it clearer

5 Answers 5

34

I actually ended up using Gparted from the Live CD. I copied the partition and pasted it in the unallocated space on the other HDD. Then I used blkid to check the UUIDs and edited the fstab file. Worked like a charm!

3
  • 6
    If you are moving your partition within the same system for whatever reason (e.g. need more space), you will have to change the UUID of the new partition before altering the fstab, since it will have the same UUID as the original (see askubuntu.com/questions/109938/change-hdds-uuid) Jun 27, 2015 at 19:06
  • 1
    This is the reason because I love linux
    – deFreitas
    Sep 19, 2016 at 13:56
  • 1
    If you are replacing your old boot drive with the new one, then you need to also install grub on it. If you're adding a new drive or replacing a data drive, then you don't need to do this.
    – David C.
    Mar 22, 2018 at 22:42
9

Well, I just used usb stick + ubuntu live.

I was transferring ubuntu 13.10 from larger hdd to a smaller ssd, and clonezilla "said" that it can't be done this way since target partition is smaller than the source partition.

So I started ubuntu live, mounted both hdd's (new disk, was partitioned earlier of course, don't forget about swap ;) ), and just:

cd /media/ubuntu/old-hdd-uuid/

then:

sudo cp -R --preserve=all bin/ boot/ cdrom/ dev/ etc/ home/ lib/ lib32/ lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/ srv/ sys/ tmp/ usr/ var/ /media/ubuntu/new-hdd-uuid/

above you can see that it's just copying all directories from one hdd to another, recursively with all permissions and stuff preserved.

cd /media/ubuntu/new-hdd-uuid/

then I had to make two symlinks in root directory of a new disk:

sudo ln -s boot/vmlinuz-x.xx.x-xx-generic vmlinuz
sudo ln -s boot/initrd.img-x.xx.x-xx-generic initrd.img

and the next step was installing grub, so:

sudo grub-install --boot-directory=boot/ /dev/sdxy

where x - device, y - partition number (if unsure use cfdisk or fdisk to print partition table...)

and the last step was, changing uuid of a new hdd to uuid from old hdd (it's the easiest way to fool grub config, fstab or else without searching and fixing configurations)

sudo tune2fs /dev/sdxy -U OLD-UUID

new UUID will show after device remounting. So now reboot and if everything is ok, your ubuntu should start...

5

You can do it by using dd. For complete info check the site.

Clone a Hard Drive Using an Ubuntu Live CD

Warning dd is a very powerful low-level tool and even one little typo is sufficient to wipe out an entire disk. Please be very careful with its use and try to use a higher-level tool if at all possible.
Note also that this method only works if your target disk is the same size or larger


Cloning hard drives is a common maintenance task. Don’t bother burning a new boot CD or paying for new software – you can do it easily with your Ubuntu Live CD.

Not only can you do this with your Ubuntu Live CD, you can do it right out of the box – no additional software needed! The program we’ll use is called dd, and it’s included with pretty much all Linux distributions. dd is a utility used to do low-level copying – rather than working with files, it works directly on the raw data on a storage device.

You can also use:

Clonezilla, a free hard drive cloning software. Clonezilla runs from a live CD, and features a simple user interface. You’ll still need to be aware of what you’re doing, of course, but this tool can simplify your job immensely with its step-by-step breakdown.

You can download Clonezilla here

Warning Make sure that you check out the Limitation of Clonzilla before you start.

You also mentioned that you have used Ghost for windows, well you can use Ghost for Linux as well.

Source: http://www.howtogeek.com/howto/19141/clone-a-hard-drive-using-an-ubuntu-live-cd/

Source: http://www.makeuseof.com/tag/2-methods-to-clone-your-linux-hard-drive/

6
  • Does dd also allow for partitions only to be copied? As in sudo dd of=/dev/sdb3 of=/dev/sda2
    – boywithaxe
    Jun 15, 2012 at 8:18
  • Providing both drive are the same exact size. And the command is in your case dd if=/dev/sd3 of=/dev/sd2
    – Mitch
    Jun 15, 2012 at 8:29
  • Thanks, however the partitions are on two different physical drives, /dev/sda and /dev/sdb. Wouldn't Using sd3 and sd2 as descriptors copy within one physical drive?
    – boywithaxe
    Jun 15, 2012 at 8:34
  • the drives do not need to be the same size, the only requirement is that the drive you are copying the information to is bigger than the drive being copied. Jun 15, 2012 at 8:49
  • 2
    ddrescue would be a better option here since the hard disk is faulty. Apr 27, 2014 at 7:15
4

@boywithaxe - Regarding your comments to Mitch's answer you can indeed just copy the relevant partitions by doing dd if=/dev/sdb3 of=/dev/sda3. That is actually the easiest part. The most tricky part is that you will also have to mount the newly copied partition, as well as a couple of other partitions and install grub (grub-install /dev/sda) (and add a swap partition before you reboot (if you are cloning a bootable partition)). Using this method there is no need to resize2fs either.

I have just had to do this myself, and I used a combination of Boot repair after a Windows Upgrade on Ubuntu 14.04 (non-RAID) and jasmines answer.

So, after having booted from the liveCD:

dd if=/dev/sdb3 of=/dev/sda3

When that has finished, then

sudo mount /dev/sda3 /mnt 

where sda3 contains the recently copied boot and root partitions)

sudo mount --bind /dev/ /mnt/dev/

sudo mount -t /proc none /mnt/proc

sudo chroot /mnt

sudo grub-install /dev/sda 

note this is sda not sda3

update-grub

exit
0
4

Some years ago I used successfully this tool to "clone" my partitions: G4L. Everything worked with some post-installation corrections, such as resizing partitions (I cloned the partitions on different size HD) and grub reinstall (it's pretty simple, you only need a live CD to reinstall it in the MBR).

You can safely ignore your swap partition (you will be able to recreat it at a second time) or clone it too and active it later, manually editing /etc/fstab or from command line.

In the past weeks I did again the clone with clonezilla, and everything went ok with the same post-cloning corrections. So don't worry and give them a try, nothing on your original HD will be touched!

EDIT:

I found an old mail where I described the first cloning process. I acted as follow:

  • Partitioned my new HD connected via USB exactly as the old one
  • Cloned the partitions in raw mode with G4L
  • Booted with a Live CD and did the resize of partitions with resize2fs
  • Disconnected the HD from USB and mounted on SATA/PATA.
  • Booted again with the Live CD and mounted the new disk:

    mkdir disk
    mount /dev/sda1 disk        (where sda1 contains boot and root partitions)
    mount /dev/sda2 disk/boot   (if you have a different boot partition) 
    mount --bind /dev/ disk/dev/
    mount -t proc none disk/proc
    chroot disk /bin/bash
    grub-install /dev/sda       (to install GRUB on sda MBR)
    
  • Restart, check the swap

  • Enjoy

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .