arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Host(/mirror) your Own online KVM VPS Locally
#2
In the previous post I've shown how to clone a block device over the network and I did give the example of cloning my VPS-9 block device that we'll be assuming that's located at :
/media/phoenix.img.gz

By decompressing it, we'll have the raw disk image of my VPS-9:
gzip -d /media/phoenix.img.gz
ls -al /media | grep phoenix.img
-rw-r--r--. 1 userX userX 107374182400 Jul  14 09:27 phoenix.img

Now is the time to build a KVM guest VM around the phoenix.img disk image. For that we need both QEMU/KVM and Libvirt.

Linux comes with native support for virtualization extensions thanks to a kernel module called KVM (Kernel based Virtual Machine). KVM simply turns the Linux kernel into a hypervisor when installed. While QEMU is a userland program that does hardware emulation while closely working with KVM to allow the creation of VMs with all its adhoc hardware and peripherals. Libvirt, on the other hand, is the API layer for VM management, ie VM creation, starting, stoping, destroying etc...

Of course, I won't delve into the details of these three technologies -outside the scope of this thread- nor on how to install them in different distributions, suffice to say that on Fedora, the process of installing all these three technologies is fairly simple:
sudo dnf install @virtualization

From now on I'll assume that both QEMU/KVM and Libvirt are available on the system and running smoothly without any problem.

Building a KVM guest around an existing disk image
A new VM can be created either with the graphical virt-manager or with the command-line tool virt-install. Given that I don't like to bother with including images in this post, I'll be using the more versatile option that's virt-install.

Besides virt-manager doesn't differ match from any other Virtualization software that the average users are already familiar with (eg VMware, VBox etc..)

Now, to create a basic KVM VM, I can simply run the following command -with this minimum pieces of information- and libvirt will happily be filling all the missing parameters with their defaults:
virt-install --name=centos8Phoenix \
--os-type=linux --os-variant=centos8 \
--ram=8192 --vcpus=2 \
--disk path=/media/phoenix.img \
--import

Above, I gave the VM a name and set the RAM size and the number of vCPUs while indicating the disk image's operating system which is CentOS 8. Then I pointed to the location of my raw disk image while specifying the import parameter which tells libvirt to skip the OS installation process and just boot from the disk.

Now this will work if all we wanted is to build a VM from the VPS disk BUT that's not our goal!.. Remember!.. what we want is to emulate the specifics of Phoenix VPS-9 system in the details and that's what we will be doing in the next post.

Before ending this post, I have to warn you that when you run the above command for the first time, the VM will fail to boot and will enter the emergency mode with a message like this:
Generating "/run/inittramfs/rdsosreport.txt"

Entering emergency mode. Exit the shell to continue.
(...)

:/#

This is normal, as your raw disk image has some inconsistencies(/errors) in its filesystem, due to the residual filesystem activity (logging etc..) that we've talked about in the previous post.

For an LVM-based, XFS filesystem like mine all you have to do is to run this repair command:
# cl-root is my LVM root partition
xfs_repair  /dev/mapper/cl-root

When the above command finishes the slightly corrupted filesystem will be fixed and all you need to do is to reboot your system and you're all set, unless you really want to emulate your online P4V VPS in the details, in which case ..

Stay tuned for the next post of this topic...
VirMach's Buffalo_VPS-9 Holder (Dec. 20 - July 21)
microLXC's Container Holder (july 20 - ?)
VirMach's Phoenix_VPS-9 Holder (Apr. 20 - June 20)
NanoKVM's NAT-VPS Holder (jan. 20 - ?)


Messages In This Thread

Possibly Related Threads…
Thread
Author
Replies
Views
Last Post
2,411
04-07-2017, 12:19 PM
Last Post: Han105
3,291
10-25-2016, 11:35 AM
Last Post: Anik

person_pin_circle Users browsing this thread: 2 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting