Linux – Create an Image of a disk having software raid partitions

backupcentos7clonelinuxsoftware-raid

I want to create a bootable backup image/clone of my centos7 server "A" having software raid partitions and use this backup to create new servers with same configurations.

my partitions are

sda
--> sda1
----> md120 /
--> sda2
----> md121 swap
--> sda3
----> md122 /boot
--> sda4
----> md123 /var/images

sdb
--> sdb1
----> md120 /
--> sdb2
----> md121 swap
--> sdb3
----> md122 /boot
--> sdb4
----> md123 /var/images

sdc 

I have used dd command to take backup of sda parttion (containing boot and swap, root and /var/images )

dd if=/dev/sda of=/dev/sdc bs=512 conv=noerror,sync

but when i restore the image on another server "B" (bare metal with same configuration) sda partition.

I was hoping that i will automatically boot up the server and raid sync will start on the other sdb drive.

But unfortunately it is not working.

Could anyone please suggest me the way to take backup of software raid partitions. And do i need to take backup of both drive ?

Thanks

Best Answer

Your approach is wrong, first of all an idea to do backup of swap is bad.

Anyway, IIUC you want to have a kind of template for your servers. I would suggest to use kickstart with install option with liveimg parameter - this way you could create an image with all your files which would be "populated" into your new installed server during kickstart-based unattended installation.

See: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/sect-kickstart-syntax#idm140037269828320

If you do not want to have 100% equal machines, just use kickstart with nfs or url parameter pointing to either public Centos repo or your mirror.

You can create all storage kung-fu in kickstart, see documentation.