How to use kpartx to edit VM images to migrate new dom0 in data center

Linux VM disk can be edited and modify configuration files without booting it or when it is unable to boot. Using kpartx you can migrate Vms to new dom0 or new data centres by modifying configuration files like /etc/sysconfig/network, etc. We will see by complete kpartx example.
Kpartx demo :
How kpartx can be used to manipulate XEN VM?

    Modify configuration files like /etc/ config files. you can edit any file as VM disk image disk will be mounted as a loop device.
    You can modify network files and rsync to other Dom0 or DC to bring up VM there. Kpartx can handle LVM also.

Let’s see how to use kpartx to migrated VM from one Dom0 to other by kpartx example.

Kpartx Example :
Let us migrate from dom0 name A to dom0 in other data centre B with a different network.

1.losetup -vf abc.img
above will set up local loop device related to boot disk of vm.img.
After executing the above command, it will provide a loop device number associated with the above boot image.
2.kpartx -va /dev/loop67
It will show the mounted VG name.
4.vgchange -ay vgname
5.mkdir /mnt/test1
6. lvs
7.mount /dev/vgname/lv_root /mnt/test1/
8.In /mnt/test1 will show all files related to boot image so that you can edit using VM
Now you can modify /etc/, network etc related new data centre or dom0.
9. unmount kpartx mounted local loops as below
vgchange -an VGname
kpartx -d /dev/loop7
losetup -d /dev/loop7

Leave a comment

Your email address will not be published.