Re: Replacing boot drive: how to make a copy of it?
Kaspar Fischer wrote:
I need to replace my boot disk as it starts failing (with bad blocks).
What is the easiest way to obtain, on a new harddrive (at least as
large as the old one), an exact copy of the root file system and
Never touch a running system -- so my intention is to *copy* the
drive instead of installing a new Debian system.
Thanks and regards,
If for example you have two identical hard drives /dev/hda and
/dev/hdb, with your root partition on /dev/hda, and you don't have
any bad blocks on either drive, then you can make a perfect sector-
-by-sector mirror using "cp /dev/hda /dev/hdb"
This streams the data between drives, and will copy each sector
in order, including partition tables and boot loaders, which may
be useful if you have multiple OS's installed.
The utility "dd" can also be used for this purpose, and gives you
additional options such as specifying what to do with bad or
unused sectors. For my purposes cp has always been sufficient.
If you don't need a perfect sector-by-sector mirror then you can
use "cp -a", tar or rsync to copy individual partitions, filesystems or
directory trees. I prefer rsync, which is simpler to use than tar
and unlike "cp -a" preserves all timestamps.
For example when I mirror a mounted root partition between different
types of drives, and my target partition is /dev/hdb1, I may use a
command like this:
rsync -cxaHD --delete / /mnt/hdb1/
The "a" option specifies a recursive copy and preserves all metadata.
The "c" (checksum) is optional and the "D" option may be contingent on
whether you use udev. The "x" option prevents other mounted partitions
from being copied. The "H" option perserves hardlinks.
This command alone will not result in a bootable copy of the root
filesystem. In my case, lilo will not have the correct root device
and the /dev directory will not be correctly configured because I
am using udev. I use a small script to make the copy bootable using
lilo -r and fixing up the /dev directory.
Disclaimer: Make make sure you are fully backed up and know exactly
what you are doing before doing dangerous operations like these.