Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc



This page is intended for everyone who has an existent Gentoo Installation and wants to replace his/her Hard Disk without losing it. When I had to do it I searched a bit in Gentoo Forums and found some solutions for the problem, but not a conventional way to do it. Here I will describe the simplest method, proven to work.

Instead of reinstalling Gentoo you could simply move your installation to the new disk and continue use it like nothing happened. In this HOWTO we suppose that you want to keep your current partition scheme (the principle is the same even if you don't), but you want bigger partitions. And according to my experience I am describing particularly an upgrade from a PATA drive to a SATA drive.

Adding Linux SATA Support

(Only if you are upgrading to SATA Drive)

The first thing you should do is to compile your kernel with SATA support. See this guide.

Preparing the new Disk

We suppose you already have installed the new hard drive and booted the system.You can type :

fdisk -l

to check if it is detected.Most likely it wont have any partition on it so now we need to create the same partitions on the new disk as these you already have on the old one.We`ll just use fdisk. BE SURE that you are partitioning your newly installed drive, you don`t want by accident to destroy the partition scheme on your current hard disk ! The new disk must be /dev/sda and your old one /dev/hda (This is just an example).Now fire up fdisk on the new SATA drive :

fdisk /dev/sda

and create the same partitions like on your old hard drive(The Size Can be bigger or the same) After that you must create filesystems to the partitions: ext2,ext3.... eg:

mkswap /dev/sda3
mke2fs /dev/sda2      # Ext2, eg. /boot
mke2fs -j /dev/sda4   # Ext3, eg. /home

When you are done it is time for the tricky part.

Installing the MBR on new disk prior to copying

(A simpler alternative is to configure grub via the new disk; this is MUCH SAFER, as it ensures no changes are made to original disk - see later sections)

This could be easy and straight forward but some times can be tricky. We`ll use your current grub config file to install the mbr.Make sure to edit it to point to the new root partition, for example from /dev/hda3 to /dev/sda3.

File: /boot/grub/grub.conf
root (hd0,0)
kernel /kernel-2.6.18 root=/dev/sda3

After that run :

grub-install --recheck /dev/sda

This will recheck your bios devices and write them the file. If you have external SATA controller your SATA drive will most likely be hd1 and your PATA hd0. NOTE: Grub will probably map your new (SATA) drive as hd1 and your original one as hd0, but when you remove it the new one will be hd0.So keep the configuration in grub.conf as hd0 ! Even if you mess it up here it is not fatal,you can reconnect your old hard disk and try to install Grub again.

File: /boot/grub/
(hd0)   /dev/hda
(hd1)   /dev/sda

You can change the /boot/grub/ file if you see anything wrong with the automatic detection then you must execute :

grub-install /dev/sda

Rebooting and Copying the content from the live CD

Now when you have your new disk partitioned correctly you can boot from the Gentoo Minimal CD and copy the data from the old Hard Disk. Make two directories to mount the partitions on them :

mkdir /olddisk
mkdir /newdisk

Now mount the partitions one by one and always check with :

df -h

what have you mounted.

Execute :

cp -ax /olddisk/* /newdisk/

for every partition you have. BE CAREFUL =)

or ( quicker ) use

tar -cpf - /olddisk/* | tar -C /newdisk -xf -

Edit: The above tar did not work for me. What worked for me is

cd /olddisk/; tar -cpf - --numeric-owner . | (cd /newdisk; tar -xpf -)

Edit: Or, just the same, from working old system

cd /newdisk
tar -cpf - -C /olddisk . | tar -xpf -

We are ready! Booting from the new disk

When the copying is complete you can remove the old disk and try to boot from the new one, which at this point should be an exact mirror.If it does not boot don`t panic.Just reconnect your old disk and try to install grub again.Probably the device was not mapped properly.Try editing

Installing the MBR on new disk after copying

This method was added when a viewer of this HOWTO needed to replace one SATA with another

Having copied all data to new partitions (section above), turn off PC, remove old disk and swap the connector (so new disk is attached to old motherboard header) or swap order in BIOS. Reboot with the live CD and run fdisk -l to ensure everything`s OK.

Now enter the following commands - remember this is on the live CD.

rm -Rf /boot/*
mount -t ext2 /dev/sda2 /boot
mkdir /newHD
mount -t ext3 /dev/sda3 /newHD

Where sda2 and sda3 are your boot partition and root respectively - the basic grub commands (for sda2 - 2nd partition on 1st disk) would be:

root (hd0,1)
setup (hd0)

Note, with this method, do not try to run the script grub-install - you`d need to hack lots of directory paths to find commands etc.

Quick note on changing partition numbers, type, order, etc

The files you'll need to edit are /boot/grub/grub.conf, /etc/fstab, and /etc/mtab.


When for some reason you can not get the new root partition to mount or it gives errors you can always pass the old partition to grub (root=/dev/<oldroot>). It does not matter what is in your fstab the partition in root= will always be mounted as /. It might complain but you should still be able to login. You obviously still need the old disk for this ;-)

Alternate method using dump/restore

Another method of doing the actual copying of partitions is to use dump and restore. This will only work for filesystem types supported by dump and restore - currently ext2 and ext3. The advantage of using dump and restore is that they understand the underlying filesystem, and you don't have to worry about the /proc and /dev directories. If you try to copy files using tar and don't exclude the /proc directory tar will try to save the whole of memory, among other things. Also dump and restore get permissions right. Another advantage of dump is that, because it was originally developed for backing up filesystems you may actually get around to making a backup of your / and /usr partitions. It's not until a hard drive blows up that you realise how much work went into setting everything up !

You will need a disk partition, separate from the partition being dump'ed, with enough room to hold the dump file. A USB disk drive makes it particularly easy because you can take the dumps on the old "source" system, then replace the old disk with the new one, boot off a live CD, and restore the filesystems from the USB drive. If you can mount both the new and old disk drives on the same machine then you can even pipe the output of dump straight into restore and so don't need a separate disk partition for the dump file. But if you do use the pipe method be VERY CAREFUL that you don't unintentionally trash one of the partitons on the old disk by mistake. If you never have the new and old disks mounted at the same time it's harder to make a mistake - but not impossible !

All the instructions below essentially replace the section "Rebooting and Copying the content from the live CD". You will still need to prepare the empty partitions on the new disk, install grub, and fix up the new /etc/fstab file as described above.

First you'll need to emerge the dump and restore programs:

emerge app-arch/dump

Then, if necessary, mount the partition that will hold the dump files - we'll assume it's mounted on /work/dumps for this example. Next, work out what individual disk partitions you have. Do a "df" to see what physical partitions hold which filesystems - typically you will have a / partition and a /usr partition, but you may also have /boot, /home, /var, etc. You'll need to dump each partition individually, so note them down so you don't make a mistake. Now for the actual dumps:

cd /work/dumps
dump -0 -v -f root.dmp /
dump -0 -v -f usr.dmp /usr
.. and so on for each partition..

Look at the dump man page for more details. The "-0" option asks for a full (level 0) dump, the "v" option gives verbose output which may make you feel better, the "-f" option tells dump where to write the dump file. You can call the files anything you like, but meaningful names are a big help.

Once you have all your partitions dumped you have to mount the new disk partitions, either by swapping disks and booting off a live CD, or by mounting the new disk on the old system, or whatever other method you can think of. When you're ready to restore:

cd /newdisk/ - or whatever mount point it's actually on
restore -r -v -f /work/dumps/root.dmp
cd /newdisk/usr - again, wherever you mounted the new /usr partition
restore -r -v -f /work/dumps/usr.dmp
..rinse, repeat for any other partitions..

Again, look at the restore man page for more details of the options. The "-v" option gives verbose output which slows down the restore, but may give you a nice warm feeling that everything is going well.

Don't forget to edit the new /etc/fstab if you have moved partitions around on the new disk. Other than that, just follow the rest of the directions above to boot up your new system. If you did use a separate USB drive then a nice side efect is that yu'll have a backup of your partitions just in case your new disk dies, or you accidentally trash a filesystem by mistake.

Retrieved from ""

Last modified: Fri, 05 Sep 2008 06:41:00 +0000 Hits: 17,194