CentOS 7 cloned XFS to EXT4

In this tutorial we are going to clone a CentOS server created with XFS partitions. Our Backup software r1soft do not support XFS partitions. So we are going to clone the server in a different server with rsync and EXT4 partitions.

a) Create all the partions on the new server with cfdisk ( try to keep all the partitions with the same order and the same size)

sda      8:0    0    20G  0 disk 
----> sda1   8:1    0 517.7M  0 part /boot
----> sda2   8:2    0  19.5G  0 part /
sdb      8:16   0    10G  0 disk 
----> sdb1   8:17   0     2G  0 part [SWAP]
----> sdb2   8:18   0     8G  0 part /home
sr0     11:0    1  1024M  0 rom  

b) Disable Selinux on the original server and reboot it

c) Stop the database on the original machine (in case you have one)

d) Create the following path in which we are going to mount out system and give format to the new partitions

    mkswap /dev/sdb1
    mkfs.ext4 /dev/sda1
    mkfs.ext4 /dev/sda2
    mkfs.ext4 /dev/sdb2

    mkdir -p /mnt/centos

e) Mount the partitions

    mount /dev/sda2 /mnt/centos/
    mkdir -p {/mnt/centos/boot,/mnt/centos/dev,/mnt/centos/sys,/mnt/centos/proc,/mnt/centos/tmp,/mnt/centos/home}

    mount /dev/sda1 /mnt/centos/boot
    mount /dev/sdb2 /mnt/centos/home/

f) Rsync everything from the original sever via ssh. The is the IP of the original server

rsync --numeric-ids -aHxrv root@* /mnt/centos/ --exclude=/dev --exclude=/proc --exclude=/sys --exclude=/tmp
rsync -aHxrv root@* /mnt/centos/home/

g) Get the UUIDs for the new hard drives


/dev/sda1: UUID="34de7422-d4dd-4f59-b07c-87143c3667a3" TYPE="ext4" 
/dev/sda2: UUID="872e3a2e-4e15-498e-b255-8d851571285f" TYPE="ext4" 
/dev/sdb1: UUID="06a87d65-c272-4bd9-bf41-f2ba0380ba86" TYPE="swap" 
/dev/sdb2: UUID="10dba318-c313-454c-ab70-3d111b3c4826" TYPE="ext4"

h) CHROOT the system

cd /mnt/centos
mount --rbind /proc/ proc/
mount --rbind /dev dev/
mount --rbind /sys  sys/

chroot . /bin/bash
source /etc/profile
PS1="(chroot) $PS1"

i) Fix the /etc/fstab

UUID=872e3a2e-4e15-498e-b255-8d851571285f /                       ext4     defaults        1 1
UUID=34de7422-d4dd-4f59-b07c-87143c3667a3 /boot                   ext4     defaults        1 2
UUID=10dba318-c313-454c-ab70-3d111b3c4826 /home                   ext4    defaults        1 2
UUID=06a87d65-c272-4bd9-bf41-f2ba0380ba86 swap                    swap    defaults        0 0

j) Check that the version of grub is similar to the original server and generate a new grub.cfg

mv /boot/grub2/grub.cfg  /boot/grub2/grub.cfg.back
grub2-mkconfig -o /boot/grub2/grub.cfg

k) Install the boot loader to the first disk

grub2-install /dev/sda

l) Install the ext4 tools

 yum install e4fsprogs

m) Generate another initramfs

dracut -fH /boot/initramfs-2.6.32-358.el6.x86_64.img 2.6.32-358.el6.x86_64

n) Umount all partitions

umount -l  /mnt/centos/proc 
umount -l  /mnt/centos/sys 
umount -l  /mnt/centos/dev
umount -l  /mnt/centos/home
umount -l  /mnt/centos/boot
umount -l  /mnt/centos/

o) Boot the server

p) modify the IP with the network tool