Copying CentOS To New Drive

Home » CentOS » Copying CentOS To New Drive
CentOS 5 Comments

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

5 thoughts on - Copying CentOS To New Drive

  • Hello Timothy,

    I personally would not copy FROM or TO running systems. Thus, proceeding to the copy from a third (liveCD or not) system sounds good to me. A bare cp -ax, tar or rsync. Of course, make sure that the target fs is empty before copying (WRT system files).

    Regards,

  • 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.

  • I’m not sure I share your love of cpio for things like this.

    Exactly how does cpio handle xattr/acl/selinux contexts?

    jh

  • Agreed. It appears others have had success doing so; but, I prefer to eliminate as many variables as possible.

    I’ve done the following:

    1. yum update Server 1.
    2. complete a minimal CentOS install on Server 2. <>
    3. yum update Server 2.
    4.Then boot both using LiveCD of choice.

    <>

    5. rsync –delete-after –force -aAHPWl
    –exclude-from=”/root/CentOS7-rsync-exclude.txt” / root@10.10.10.200:/
    <<----the host address of the server to receive the sync/copy. ((that's a lowercase "L" after "-aAHPW")) 6. the “CentOS7-rsync-exclude.txt” file contains: boot dev etc/fstab etc/grub2.cfg etc/mtab etc/default/grub etc/networks etc/sysconfig/network* etc/sysconfig/kernel etc/udev lib/modules mnt proc sys tmp var/lock

  • As has been discussed, doing file copies from a running system is not recommended.

    If by “Live OS” you mean booting the system with a LiveCD, then clonezilla would all of the above.

    note: target (new) disk >= disk of the old system

    — Arun Khan