2

I would like to copy/clone/move my CentOS (which is on a 20GB hard drive) to a smaller hard drive (5GB)...

Can someone tell me how to do this?

Wolfy
  • 332

1 Answers1

3

You should be able to tar up everything and extract it to the new drive. First plug in the second drive, then boot into something that doesn't use the source drive, such as a live CD. After that just copy everything over. For example:

# Mount the source drive
mkdir /mnt/source
mount /dev/sda1 /mnt/source
# Mount the destination drive
mkdir /mnt/destination
mount /dev/sdb1 /mnt/destination
# Copy everything
cp -rp /mnt/source /mnt/destination

Don't reboot just yet, you have to install Grub on the destination drive, something like:

grub-setup -d /mnt/destination /dev/sdb

You can also use an intermediate drive if you can't connect the second drive to the same computer, but the steps are similar. Finally remember, don't use those commands as is, always check and double check that they apply to your system.

(In case someone has a slightly different requirement that doesn't include a smaller destination drive, Clonezilla is definitely a better choice.)

phunehehe
  • 20,240
  • 1
    I'd like to mention that you have to make sure that you don't try cloning virtual filesystems... – xenoterracide Mar 17 '11 at 01:15
  • why doesn't grub copy over with the cp command. And you mentioned tarring but never explained how???? – Joshua Robison Jun 05 '11 at 08:32
  • @Joshua Parts of grub is stored in the MBR, which doesn't get copied with cp. tar is an archiver, like zip or rar. Basically you make an archive from the source drive, then extract it to the destination drive. Refer to man tar for how to use it, or ask in another question. – phunehehe Jun 05 '11 at 13:11