[Ubuntu] Clone drive?

Place to discuss Debian Linux and Debian based distributions
Post Reply
User avatar
Duo Maxwell
user
user
Posts: 8
Joined: Fri Jul 22, 2005 6:50 pm
Location: not there, there!
Contact:

[Ubuntu] Clone drive?

Post by Duo Maxwell » Mon Oct 23, 2006 9:36 am

What up? I'm trying to clone over to a bigger HD my entire install, files and all. Tried booting off a live CD and using GParted to clone the main install partition. But every time I try to copy it over it errors out, it doesn't show me what the error is either so thats a dry hole...

System is a Sempron64 3000+ 1Gb DDR400 SATA Samsung 80Gb HD080HJ and the new Segate 320Gb S3320620AS in 3.0Gbps mode nVidia Geforce 6150LE / 430 based mobo, so it sould have the muscle to handle this task fine.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Oct 23, 2006 10:32 am

There are several ways to accomplish what you want to do and I have done this many times over the years. My preferred method may not be the fanciest method availble today but it is 100% reliable in my experience. I'll give you an example of what I would do.

Say the drive I currently have installed is a 20GB drive and shows up to my system as "hda" and I have a 40GB drive I want to replace it with. Assume I also have 3 partitions on the installed drive. hda1 = /boot and is 100MB ext3, hda2 = swap and is 1GB, hda3 = / and is ~19GB ext3.

Here are the steps I would take:

1) Attach the new drive as a secondary drive. It should show up as something other than "hda", probably "hdb".

2) Boot from CD (rescue disk, KNOPPIX, etc) and perform the rest of these tasks while booted from this alternate media.

3) Use fdisk to create partitions on the new drive that are slightly larger than the partitions on the old drive because of possible drive geometry differences, in the same order and of the same type (hdb1 would be a primary partition of type ext3 and 105MB in size (5MB larger than the old partition size), hdb2 would be of type swap and make it 1GB in size (same size as old swap partition), hdb3 would be type ext3 and make it the size of the rest of the available space allows (~39GB).

To get a list of partitions and size/type information from the old drive:

Code: Select all

# fdisk -l /dev/hda
To start editing the partition table on the new drive:

Code: Select all

# fdisk /dev/hdb
If you need help with how to use fdisk let me know and I can help you. Use a "?" to get a help menu and there are plenty of howtos out there. It's really not hard to use.

4) dd the two ext3 file systems over to the new ext3 partitions:

Code: Select all

# dd if=/dev/hda1 of=/dev/hdb1
# dd if=/dev/hda3 of=/dev/hdb3
5) Resize the file systems on the new drive to fill the size of the new larger partitions:

Code: Select all

# resize2fs /dev/hdb1
# resize2fs /dev/hdb3
(You'll probably have to run an fsck on the partitions before it will let you resize them, do that first when it tells you to)

5) Create the swap:

Code: Select all

# mkswap /dev/hdb2
6) Remove old drive and configure new drive so it shows up as "hda", boot from CD again and reinstall your boot loader on the new drive, assuming grub:

Code: Select all

# mkdir /mnt/sysimage
# mkdir /mnt/sysimage/boot
# mount /dev/hda3 /mnt/sysimage
# mount /dev/hda1 /mnt/sysimage/boot
# chroot /mnt/sysimage
# grub-install /dev/hda
# exit
7) Remove CD and boot onto new disk.
Last edited by Void Main on Mon Oct 23, 2006 5:49 pm, edited 2 times in total.

Jenda
programmer
programmer
Posts: 156
Joined: Mon May 23, 2005 9:46 am
Location: Prague, Czech Republic
Contact:

Post by Jenda » Mon Oct 23, 2006 5:21 pm

Void, are you trying to fit 29.1 Gigabytes on a 20 Gig drive?
You must be a lawyer :) Glad to meet someone of my trade in here...

BTW, gparted might be easier to use for step 3)

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Oct 23, 2006 5:46 pm

Ooops, that was a typo, good catch. I personally find fdisk easier than gparted but some would call me a little strange. :) It might also be because that's what I've been using for the last 15 years and I'm quite used to it. Really though, it's about as simple as it gets. I could probably partition up that drive with my eyes closed in about 5 seconds with fdisk.

Jenda
programmer
programmer
Posts: 156
Joined: Mon May 23, 2005 9:46 am
Location: Prague, Czech Republic
Contact:

Post by Jenda » Mon Oct 23, 2006 6:25 pm

Oh I could partition the drive in a few seconds too with fdisk and closed eyes... I'm just not sure if there would be any data left ;).

Post Reply