Migrate partitions from old disk to new one.

Environment: Centos7, virtual machine on KVM with 15 GB of unique disk.

In this article we will see how to migrate your data from old disk to newly added one.

This may save your journey if you encountered some problems with your volumes or FS and you don’t have any other choice apart moving your data from one disk to another.

Let’s suppose block size or cylinders were altered. You want to restart your system you will probably get kernel panic error after rebooting the server.
Regardless you were lucky because you had a snapshot, you reverted it. Now this solution is for you. You can move all data including boot sector from your faulty disk to new.

I have one disk with two partitions; /dev/vda is my disk, vda1 and vda2 are my partitions.

I will add a new disk at least same size with vda from my Vcenter hypervisor.
So new disk will be named vdb, 16G of total size.

Once it’s done we have to make the disk recognized by OS. To do that for newly added disk type:

echo “- – -” > /sys/class/scsi_host/host0/scan

We can start migration steps. First, copy partitioning scheme with sfdisk command.

Let’s check fdisk;

We added new disk into our cl volume groupe;

We are ready to move data from old disk to /dev/vdb2.
We will move old disk, pay attention to pvmove command usage, pvmove /dev/vda2 (means move old disk).

Let’s kick the old disk out!

We should copy the boot sector on vdb1 partition.

Here we are! We must reinstall grub to reboot the server from new disk. If you just do a grub2-install /dev/vdb probably you will be redirected to grub menu after reboot and your system won’t start (It’s not always the case you will see my example, depending on your block size, parition type error message can change). It’s because in your actual /boot/grub2/device.map file (hd0) device for boot is set to old. disk,/dev/vda.

I read some other documents that if you are using grub, you should change it by editing this file, just set it to new disk, /dev/vdb but they say Grub2 doesn’t care about device.map file, it makes changes automatically. I don’t think so. I tried this procedure many times and encoutered this problem everytime. I mean, you should absolutely edit this device.map file or we have another clean way do to it.

First, I will show you what happen if you just run grub2-install command.

Result after rebooting:

The proper way should be;

grub2-install –recheck /dev/vdb


run sync command synchornize.

–recheck option will read device.map if it doesn’t exist it will be created with new settings. You can rebbot the server without any problem.

To have more information about grub installation command, check following link:


Result after passing grub2-install –recheck /dev/vdb. Reboot finishes correctly.

This was about volume migration with boot partition. If you are looking for migration without cloning boot sector, do steps;

Then you can remove physically your disk.