[CentOS] Copying CentOS to new drive

Wed May 4 12:20:15 UTC 2016
Brian Miller <centos at fullnote.com>

On Wed, 2016-05-04 at 12:38 +0200, Timothy Murphy wrote:
> I recently asked about copying a running system to a new drive.
> 
> As a postscript, I'm wondering if it would have been preferable 
> to run the machine under a Live OS, and simply copy the root partition
> to the new drive?
> Eg while running under the LiveOS,
>   # mkdir /mnt/old /mnt/new
>   # mount /dev/sda7 /mnt/old
>   # mount /dev/sdb6 /mnt/new
>   # cp -avx /mnt/old /mnt/new
> or
>   # rsync -ax --progress /mnt/old /mnt/new

When copying systems I developed a preference for cpio; fewer problems
handling weird inode types.

My typical recipe is:
- rescue boot the new system and create my desired disk partitioning
- decide what top level directories I want duplicated on the new system
- iterate through them:
 for i in bin boot lib etc .... ; do
  mkdir -p /mnt/sysimage/$i
  ssh root@$OLDSYSTEM "cd /$i && find . -xdev -print0 | cpio --null
-oaVc" | (cd /mnt/sysimage/$i && cpio --no-absolute-filenames -imVdc )
done

- make any adjustments that might necessary in the configuration
- if this was a copy of a running system I might quiesce the original,
do a final rsync of data that might have changed between now and when I
made the cpio copy
- grub-install (or equivalent)
- release the hounds.