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

https://www.tecmint.com/what-is-ext2-ext3-ext4-and-how-to-create-and-convert-linux-file-systems/

http://lhermie.net/xfs-cheat-sheet/

For my tutorial, i’m using XFS filesystem.

Command that I used:

fdisk /dev/sdX #replace X with drive name

On fdisk

n
p
1
2048
20299199

#repeat for next partition

n
p 
2
202099200
enter

#change partition type for sda2

t
8e

#save partition and write to disk
w

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 
xfs_admin -L "/boot" /dev/sda1
xfs_admin -L "/" /dev/sda2
#EXT FS
e2label /dev/sda1 /boot
e2label /dev/sda2 /

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

#VM4 
ip addr add 192.168.222.3/24 dev ens224

#VM4-v2v 
ip addr add 192.168.222.2/24 dev ens192

#verify it should be ping from both server.

[root@localhost ~]# ping 192.168.222.2
PING 192.168.222.2 (192.168.222.2) 56(84) bytes of data.
64 bytes from 192.168.222.2: icmp_seq=1 ttl=64 time=0.220 ms
64 bytes from 192.168.222.2: icmp_seq=2 ttl=64 time=0.264 ms
64 bytes from 192.168.222.2: icmp_seq=3 ttl=64 time=0.384 ms
^C
--- 192.168.222.2 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

==========================

#to 
==========================
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