# [FAQ] Howto move the system on to a bigger harddrive ?

## tragor

Running out of disk space ? Your root partition has only some MBs free ? Can't find a spot to install that new app to ?

Method 1: (Source: This post from tecknojunky)

Using dd to duplicate the drive including partition table. 

Note: This method has the disadvantage, that only the last partition can be resized and that requireing a tool to resize the file system on it. If you have to resize a partition other then the last one, use Method 2. The advantage is, that you do not have to reinstall your bootloader, since the MBR will be copied too.

These 5 easy and safe steps will transfer the data on the current hard drive onto a new bigger one.  The last partition will hold the newly aquired free space.

I have drawn this from my own setup which is based upon the x86 installation howto from Gentoo.  My hard drive was partitioned this way:

- /dev/hda1 : ext2 boot partition

- /dev/hda2 : swap partition

- /dev/hda3 : reiserfs root partition.

Also, I have a dvd-rom on /dev/hdb and the new disk was the primary drive on the second controler: /dev/hdc.  Where is located the new disk is irrelevant.  Just be sure you know that you are accessing the new drive and not another disk that hold crucial data!!!

These steps insure that your hda is untouched and will serve as a backup until you are sure the new drive is functional.

Prerequisites: make sure you have the tools for each of the file systems on the drive.  Also, a partition program is essential (fdisk, cfdisk, ...).

1- Tranfer the data.

```
# dd if=/dev/hda of=/dev/hdc
```

This copies integraly the whole drive onto the new one, including the MBR and partition table.  It can take a very long time depending on bus speed and drive size.

2- Fix the partition table.

```
# cfdisk /dev/hdc
```

You can use any disk partition program you wish.

You will see that on the new drive, you'll have the same partition table with additionnal free space trailing it.  

Make the boot partitition bootable if it is not so.

Delete the last partition and recreate it using the whole free space.  Write the partition table.  This only changes the partition table, not the data in the partition.

3- Resize the filesystem on last partition.

Depending on the type of file system you had, use the proper tool to resize it.  I had reiserfs:

```
# resize_reiserfs /dev/hdc3
```

4- Check file system integrity

```
# reiserfsck --fix-fixable /dev/hdc3

# e2fsck /dev/hdc1
```

5- Swap the drive and reboot.

Working?  Congrat, you succefully duplicated your disk.

This is based on my setup.  I'm guessing other setups may fail with this.  If so, post your unsuccess here (with preferably a fix).

Method 2: (Source: This thread  and own experience)

Formatting and repartitioning the new drive and copying all data with permissions - then reinstall the bootloader.

You will need a LiveCD and the usual fdisk and mk<yourfstype> stuff and cpio for this method.

1- Partitioning the new drive

Use fdisk or cfdisk (or any other program that does the job) to partition the new harddrive. I will assume that you will create the same number of partitions as on the old drive. But you can surely add more partitions as you like (and maybe even create fewer - would be a bit more complicated I guess)... Don't forget the swap partition !

2- Creating the filesystems

Use mkreiserfs or mke2fs or another tool to create your filesystems. (See this if you are unsure.)

3- Booting from the LiveCD and mounting the new drive

Boot up your favorite LiveCD and mount the empty partitions of the new drive. You should mount them as /mnt/hdb[X] according to the current drive/partition names to avoid confusion. Further on I will assume you have the old drive partitions mounted as /mnt/hda[X] and the new drive partitions as /mnt/hdb[X].

Don't forget, you need not to mount the swap...

5- Copying the files without loosing permissions

Now cd to /mnt/hda1 (your old system boot partition) and copy the files:

```

# cd /mnt/hda1

# find . -print | cpio -pamd /mnt/hdb1 

```

Do that for alle of your old partitions.

6- Swap system-drive and reboot with LiveCD

Halt the system and replace the old system-drive with the new one. Don't forget to set the jumper right ! Then start up again with the LiveCD.

7- Reinstalling the bootloader

Once you have rebooted, mount your system drive as described in the installation guide. Then chroot into the system and run lilo (or grub):

```

# chroot /mnt/<where you mounted the system> /bin/bash

# lilo

```

8- Reboot the system

So that would be all. If all went the right way, your system should start now properly.

Note: I had a problem with the x-server immediately shutting down after startx without telling any error... But for all I know, that does not happen normally. But if it does, you can just reemerge xfree, that did the trick for me.

Thanks to the forum for all the great help!

tragor

----------

## teknomage1

what i did was load up a knoppix cd and mount the partions i needed as writeable. the I used cp -a /mnt/olddrive /mnt/newdrive. I chrooted to the new drive and updated the fstab and ran lilo. no problems

----------

## fimblo

I followed all the instructions in your howto, and also the grub part in the installation guide, and when I rebooted I got "Grub Error 17". The system won't boot.

anyone recognise this problem?

EDIT: I forgot to search the forum first. I found a few tips, Ill try them first  :Smile: 

----------

## fimblo

K I searched and didnt find any help. Anyone got any tips?

----------

## gonzalo

 *teknomage1 wrote:*   

> what i did was load up a knoppix cd and mount the partions i needed as writeable. the I used cp -a /mnt/olddrive /mnt/newdrive. I chrooted to the new drive and updated the fstab and ran lilo. no problems

 

Same here, mounting the new partitions and cp -a. Nothing else

----------

## fimblo

 *gonzalo wrote:*   

> Same here, mounting the new partitions and cp -a. Nothing else

 

hmm did you do a lilo/grub?

----------

## gonzalo

Sure, you modify your lilo ot grub with the new root and/or boot partitions.

----------

## fimblo

exactly what I did (I use grub). and I got an Grub error 17 at boot. I looked at the list of grub errors, and it seems to be the error you get when the problem doesnt match any of the other error codes...

 :Sad: 

----------

## scr7b

 *teknomage1 wrote:*   

> what i did was load up a knoppix cd and mount the partions i needed as writeable. the I used cp -a /mnt/olddrive /mnt/newdrive. I chrooted to the new drive and updated the fstab and ran lilo. no problems

 

Shouldn't you add "--preserve=all" to the cp command?  Were all the original permissions preserved after the copy?

----------

## gonzalo

cp -a, Equivalent to -dpPR

-p Preserve the original files' owner, group, permissions, and timestamps

$man cp   :Wink: 

----------

## RaaR

 *fimblo wrote:*   

> exactly what I did (I use grub). and I got an Grub error 17 at boot. I looked at the list of grub errors, and it seems to be the error you get when the problem doesnt match any of the other error codes...
> 
> 

 

Did you reinstall grub or just edit grub.conf?

In case you did reinstall (which I think you should), are you sure you installed grub to the correct hd?

----------

## fimblo

I reinstalled grub, and I have only one drive  :Smile: 

But I just got a hint from a Unix veteran (+15years) who has fiddled with pretty much every os which resembles unix- he told me to dd 512k of /dev/zero onto the first part of hda then reinstall grub.

gonna try this!

----------

## fimblo

oops    :Shocked: 

don't dd the first 512 bytes onto the hd! I managed to remove the partition table as well...  :Sad:  Afterwards, I looked into the specs and the last 64 bytes of the first 512 bytes of a hd contains the partition table.

I managed to rescue the partion table using gpart... and fixed my bios,, which was the original problem  :Razz: 

----------

## Becks

And another method which can be used over network:

Asumed you have computer1 and want to move the content of a drive to computer2.

Computer1 is still alive and can be booted:

1) On computer1:

emerge nfs-utils

nano -w /etc/exports

add the drive you want to copy

/etc/init.d/nfs start

2) On computer2:

Start the LiveCD

run net-setup

/etc/init.d/nfs start

mkdir /mnt/import

mount -t nfs IP:/exporteddrive /mnt/import

mkdir /mnt/newdrive 

mount /dev/XXX /mnt/newdrive

And then just cp -a /mnt/import /mnt/newdrive on computer2.

If computer 1 is broken - boot from a LiveCD, edit /etc/exports, start the network and start nfs. And then copy the drive like shown above.

Moving a system and making the new machine bootable:

create all needed partitions on the new machine (like shown in the installation manual) and copy the contents of computer1 to the correct drives on computer2 (including /boot) using the above mentioned method

Making the machine bootable:

Mount the drives on computer2 locally (like shown in the installation manual, f.e. /mnt/hda3 to /mnt/gentoo, /mnt/hda1 to /mnt/gentoo/boot, /proc to /mnt/gentoo/proc and so on), chroot into the so created new system (also described in the inst. manual) and run grub to install the bootloader on the new system. Then reboot.

Alex

----------

## beacher

I just got through doing this in reverse (larger to smaller hard drive) and when i rebooted, I got the dreaded Lilo - Timestamp mismatch .  I wish that I had read this before doing it because I found my mistake, and it's a real goofy one....   I did cp -Rp from / to the /new_hd  and I didn't catch the fact that it had copied /proc.  It took me a day of screwing around before I finally went into livecd, mounted hda1 and rm -rf /mnt/gentoo/proc . I made sure the new fstab had /proc in it and rebooted.  That's how I got rid of it.

I felt like a dumba$$ but I couldn't find the solution on google, so I'm posting it here so someone can benefit from my mistakes....

Maybe the grub error is the same?

B

----------

## befortin

There's a great CD that can help to do this kind of job. Take a look at the "SystemRescueCD" (you should find it on Google).

- and it's based on Gentoo! -

----------

## Nate_S

fimblo:  parted can recover a deleted partition table if you know approxamately where the starts and ends of the deleted partitions are.  

I think the problem many of you are having with gurb/lilo is that if you set it up with the old disk still connected before the new one, eg /dev/hda was your old disk, and /dev/hdb is the disk your copying to, the numbers that grub (and presumably lilo does something similar,) would change as soon as you disconnect the first disk.  I'd recommend that you try booting from the livecd and setting up your bootloader from there, once you pull out the old drive.  

Also, dd_rescue deserves some mention, it's like dd, except optimized for recovering data from failing hard disks.  And even if your drive is not failing, it's got some nice features like letting you see the progress with the -v flag.  It's in portage, as well as on that system rescue cd that someone already mentioned.  

-Nate

----------

## eNTi

is any of those methods working with sata?

----------

## befortin

I think that the SystemRescueCD should work with SATA. Read the following :

http://www.sysresccd.org/kernel.en.php

Good luck!

----------

## wskellenger

I went from a 7GB old clunker to a new 80GB drive in about 40 minutes, including popping the case open and putting it back together, using the method posted here.

A few things to note...

First -- My drive was configured exactly like the author's.  I had ReiserFS as my last partition.

1.  I got a little scared when using cfdisk and I didn't see the ReiserFS type listed when I created the new partition.  I went with just "Linux" (type 83).  When you use the ReiserFS tools in the next steps, it must convert the partition into that FS type.  (?) 

2.  I used the following dd command as recommended in this post to "save time".  As I've never done this before, I didn't know how much time a "long time" would be...  But at any rate, with only 7GB it wasn't that long at all.

```
dd if=/dev/hda of=/dev/hdc bs=2048k
```

Thanks again for this helpful post.

----------

## nsahoo

 *gonzalo wrote:*   

>  *teknomage1 wrote:*   what i did was load up a knoppix cd and mount the partions i needed as writeable. the I used cp -a /mnt/olddrive /mnt/newdrive. I chrooted to the new drive and updated the fstab and ran lilo. no problems 
> 
> Same here, mounting the new partitions and cp -a. Nothing else

 

Ya, this is the most straight forward way I believe.

----------

## KingPunk

my best suggestion would be to just use partimage.

clone the entire drive, in real time, or backup to dvd and then move it to the

new drive.

its quite simple, and a very good program.

i've requested this program, to be on the 2005.1 offical gentoo livecd.

 :Wink: 

----------

## Bob P

 *teknomage1 wrote:*   

> what i did was load up a knoppix cd and mount the partions i needed as writeable. the I used cp -a /mnt/olddrive /mnt/newdrive. I chrooted to the new drive and updated the fstab and ran lilo. no problems

 

i tried this using the Gentoo live CD 2004.3.  

instead of using 

```
cp -a /mnt/olddrive /mnt/newdrive
```

i used this: 

```
cp -a /mnt/olddrive/* /mnt/newdrive
```

using the second method results in the contents of /olddrive being copied into the root directory of /newdrive, while the first method would put the contents of /olddrive in a folder named /olddrive on the /newdrive, like this:  /newdrive/olddrive, with the contents of the original drive's root directory in a folder named /olddrive on the new system.  essentially, if you use the first method you end up with the contents of the original drive being deposited as children into a parent directory named /olddrive  instead of having them go into the target's root directory.

----------

## Lar

I used method 1.  Worked like a champ.  I have a setup very similar to tragor but my /dev/hda3 partition contains an EXT3 filesystem as per the current installation guide.  I only had to make one minor alteration to the plan.  Step 3 becomes:

```
# e2fsck -f /dev/hdc3

# resize2fs /dev/hdc3

```

If you attempt to run resize2fs without first e2fsck'ing the drive, it will remind you to run it.  Thanks everyone for making this a very smooth migration.  Now I have enough free disk space to compile OpenOffice.   :Smile: 

--Lar

----------

## PaoloP

Usually when I need to move entire partitons I follow this HOWTO.

Never had a problem

----------

## alinv

 *tragor wrote:*   

> # cd /mnt/hda1 
> 
>  # find . -print | cpio -pamd /mnt/hdb1 

 

cpio silently failed to copy a 3+ Gb file to the new location (the file was created, but zero-sized).

I would recommend using either tar

```
(cd /path/to/source ; tar cpsO .) | (cd /path/to/destination ; tar xf -) 
```

or cp -a , as previously stated.

BTW, either method is faster.

----------

## revertex

I'm surprised nobody sugested rsync.

----------

## alinv

 *revertex wrote:*   

> I'm surprised nobody sugested rsync.

 

Usually, this is a one-time job, and I don't think rsync is that efficient.

----------

