From the Linux User Support Team (L.U.S.T) List on Mon, 19 Jul 1999
I have a disk in a Redhat Linux 6.0 machine that has developed some bad sectors, about 200 meg's worth. Everything seems to be working but I would like to replace the disk. Is there a way I can copy the whole partition to another disk and then just swap them. I suppose I can do something like mirroring the disks but I haven't a clue where to start.
Thanks for any help.
I usually mount new disks under /mnt after fdisk & mke2fs to make it ext2fs
mount /dev/newdrive /mnt cd / for i in `\ls |grep -v proc |grep -v mnt` do cp -aRv $i /mnt/ done
boot with boot stiffy & rerun lilo
Ack! So complicated.
If you have three partitions that you want backup to /mnt (let's say /, /usr, and /home) you could use something as simple as:
for i in / /usr /home; do cp -pax $i /mnt done
.... the -x will prevent the GNU cp command from crossing over filesystem/mount boundaries. Thus you needn't worry about inadvertantly copying /proc or recursing down into /mnt.
(Obviously to just get the root filesystem you'd just use cp -pax / /mnt; to list all your currently active filesystems just use the mount command with no arguments; to list all the partitions/filesystems on your system use the 'fdisk -l' command).