P2V / V2V Migration via Tar Over SSH

Physical-to-Virtual ("P2V" or "p-to-v") involves the process of decoupling and migrating a physical server's operating system (OS), applications, and data from that physical server to a virtual-machine guest hosted on a virtualized platform.

Virtual to virtual (V2V) is a term that refers to the migration of an operating system (OS), application programs and data from a virtual machine or disk partition to another virtual machine or disk partition. The target can be a single system or multiple systems.

In this scenario, I used VMWare ESXi and already deployed CentOS 7 named VM4
If you want to change password, you copy /etc/shadow to /root then proceed changing to simple password. (as i using vnc)

1. Create new target OS with same specification (CPU, RAM, HDD) with VM4, I named it VM4-v2v

2. Make sure, CentOS is loaded up and boot into rescue mode.

3. Select option 3 to deploy shell access

4. You need to determine the targeted partition and need to be same for destination server. There is some tools that can be used such as fdisk.

There is some cheetsheet that I find online for ext4, ext3 and xfs


For my tutorial, i'm using XFS filesystem.

Command that I used:
fdisk /dev/sdX #replace X with drive name
On fdisk


#repeat for next partition


#change partition type for sda2


#save partition and write to disk

Now I should have same partition with the targeted OS

5. Format the partition that already be created. Refer cheetsheet

mkfs.xfs /dev/sda1
mkfs.xfs /dev/sda2
6. Label both partion

xfs_admin -L "/boot" /dev/sda1
xfs_admin -L "/" /dev/sda2
e2label /dev/sda1 /boot
e2label /dev/sda2 /

7. Assign both server an IP address. In the scenario, I use for VM4 and for VM4-v2v

ip addr add dev ens224

ip addr add dev ens192

#verify it should be ping from both server.

[[email protected] ~]# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.220 ms
64 bytes from icmp_seq=2 ttl=64 time=0.264 ms
64 bytes from icmp_seq=3 ttl=64 time=0.384 ms
--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.220/0.289/0.384/0.070 ms

8. Mount all drive created at destination server

#create directory
mkdir /mnt/root
mkdir /mnt/boot

#mount partition to directory
mount /dev/sda1 /mnt/boot
mount /dev/sda2 /mnt/root

#to verify
df -h

9. Start to copy from target server to destination server
*command is ran on destination server

#for this, i exclude /boot (because on another partition), /tmp & /proc 

ssh -p 9321 [email protected] "tar cvf - /bin /dev /etc /home /lib /lib64 /media /mnt /opt /root /run /sbin /srv /sys /usr /var" | tar xvf - -C /mnt/root

#for boot partition
ssh -p 9321 [email protected] "cd /boot; tar cvf - *" | tar xvf - -C /mnt/boot

10. Edit fstab file to configure partition

vi /mnt/root/etc/fstab

#you can use full drive device name or label

#device id

/dev/sda2 / 		xfs     defaults        0 0
/dev/sda1 /boot 	xfs     defaults        0 0

#by label

LABEL=/ / 		xfs     defaults        0 0
LABEL=/boot /boot 	xfs     defaults        0 0
11. Reboot and put on rescue mode again
Press 1 to continue

#Rescue mode should detect your system

chroot /mnt/sysimage

#If rescue mode not detected your partition simply
mkdir /mnt/root
mount /dev/sda1 /mnt/root
chroot /mnt/root

12. Restore back grub, initrd, intramfs

cd /boot
dracut initramfs-3.10.0-514.el7.x86_64.img initramfs-3.10.0-514.el7.x86_64 -f
mkinitrd initrd-plymouth.img 3.10.0-514.el7.x86_64 -f

#restore grub2
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-install /dev/sda

#if using old grub 

vi /etc/grub.conf

# and change the line of the kernel version from
kernel /boot/vmlinuz-2.6.18-92.1.22.el5 ro root=/dev/md4
initrd /boot/initrd-2.6.18-92.1.22.el5.img


kernel /boot/vmlinuz-2.6.18-92.1.22.el5 ro root=LABEL=/
initrd /boot/initrd-2.6.18-92.1.22.el5a.img

Reboot and your server should be booting up.

Correct the IP address and host name, and use ipswap to change the IP for directadmin
Recreate tmp folder

mkdir /tmp
mkdir /var/tmp
chmod o+t /tmp /var/tmp