If you've ever wanted to setup an additional IPv4 address and create a VM inside of your OVH VPS, it's relatively easy to do! I do this for testing, before I apply a change in production.

First, purchase an additional IPv4 address from OVH ($3 CAD at time of writing, one-time fee).

Next, install the dependencies for libvirt if you haven't already:

# UBUNTU 16.04+
apt-get install qemu-kvm libvirt-bin virtinst bridge-utils cpu-checker --yes
kvm-ok # EXPECT: KVM acceleration can be used
ip addr add $IP_ADDRESS/32 dev $INTERFACE

Next, go ahead and create a disk image (I prefer qcow2 for this), you can run this by executing:

qemu-img create -f qcow2 ./VIRTUAL_MACHINE_NAME.qcow2 8G # replace 8G with hdd size

I keep my qcow images in /var/lib/kvm-drives/, which is backed up hourly. Now, let's create the VM, here's a few commands to get you started.

Debian Stretch

For Stretch, you can run this command:

virt-install \--name $VMNAME \--ram $RAMINGB \--disk path=./VIRTUAL_MACHINE_NAME.qcow2,size=$DISKSIZEINGB \--vcpus 2 \--os-type linux \--os-variant generic \--network bridge=virbr0 \--graphics none \--console pty,target_type=serial \--location 'http://ftp.ca.debian.org/debian/dists/stretch/main/installer-amd64/' \--extra-args 'console=ttyS0,115200n8 serial'

Ubuntu 18.04

For Ubuntu 18.04, you can run this command:

virt-install \--name $VMNAME \--ram $RAMINGB \--disk path=./VIRTUAL_MACHINE_NAME.qcow2,size=$DISKSIZEINGB \--vcpus 2 \--os-type linux \--os-variant generic \--network bridge=virbr0 \--graphics none \--console pty,target_type=serial \--location 'http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/' \--extra-args 'console=ttyS0,115200n8 serial'

For other OSes

You run the same command, just change the --location parameter to the file location.

That's all, install your VM!

That's all you need to do, just run through the installer, and make sure you have network connectivity. You may need to configure the IPv4 address to be static inside the guest VM, if you did not configure it already.

tutorial cloud

Mike

Senior Software Engineer, Labber, Sysadmin. I make things scale rapidly. Optimize everything.

Read More