Creating a Ubuntu KVM virtual machine on OpenVZ7 using prlctl
In this article, we describe the process of creating a Ubuntu virtual machine based on the OpenVZ 7 hypervisor with the KVM virtualization type. In our case, we will create a Ubuntu 18.04 (x64) virtual machine. Other Ubuntu virtual machines are created in the same way.
Create a virtual machine (use ubuntu as a distribution1 for Ubuntu 18.04):
prlctl create Ubuntu_18-04 --distribution ubuntu --vmtype vm
Create a virtual cdrom drive and mount the Ubuntu ISO image into it:
prlctl set Ubuntu_18-04 --device-add cdrom --image /root/downloads/Ubuntu_18-04.iso
Allow VNC access:
prlctl set Ubuntu_18-04 --vnc-mode manual --vnc-port 5910 --vnc-passwd YourPassword
Optionally, set a static MAC address:
prlctl set Ubuntu_18-04 --device-set net0 --mac 00:11:41:32:84:55
Set the IP address + CIDR, gateway and name server:
prlctl set Ubuntu_18-04 --device-set net0 --ipadd X.X.X.X/24 --gw X.X.X.X \ --nameserver 8.8.8.8
Set the number of virtual processor cores:
prlctl set Ubuntu_18-04 --cpus 2
Set the RAM size:
prlctl set Ubuntu_18-04 --memsize 4G
Set the size of the drive:
prlctl set Ubuntu_18-04 --diskspace 80G
Optionally, set the input/output limit (MB/s):
prlctl set Ubuntu_18-04 --iolimit 50
Optionally, set the autostart:
prlctl set Ubuntu_18-04 --autostart on
Run the created virtual machine:
prlctl start Ubuntu_18-04
If the following error appears:
Failed to start the VM: The %1 virtual network cannot be found. Try to choose another network. (Details: Network not found: no network with matching name 'Bridged')
then switch your network adapter to router mode by specifying the virtual machine ID in curly brackets2:
prlctl set {2c03f039-0441-4cf4-8e4c-bd859ccefcd9} --device-set net0 --type routed
If the following error appears:
Failed to start the VM: Operation failed. Failed to execute the operation. (Details: internal error: process exited while connecting to monitor: 2020-02-09T19:26:31.816008Z qemu-kvm: -drive file=/root/downloads/Ubuntu_18-04.iso,format=raw,if=none,id=drive-ide0-0-1,readonly=on,cache=none,discard=unmap,aio=native: Could not open '/root/downloads/Ubuntu_18-04.iso': Permission denied)
then change the permissions and the owner of the iso image file:
chown -R user:user /root/downloads/Ubuntu_18-04.iso
chmod 777 /root/downloads/Ubuntu_18-04.iso
Or:
- move the iso file to the /tmp folder
- prlctl set Ubuntu_18-04 --device-del cdrom1 (if there are several cdrom drives, then delete them all3)
- prlctl set Ubuntu_18-04 --device-add cdrom --image /tmp/Ubuntu_18-04.iso
Now you need to connect to the hypervisor via the VNC Viewer, specifying its IP address and VNC port, which we set earlier. Install Ubuntu using the standard installer. If after connecting through the VNC you see the following error:
No bootable device
Most likely your iso file is not bootable. Just change it to another. If the Ubuntu installer does not see the hard disk (virtual), then stop the virtual machine and run the following command2:
prlctl set Ubuntu_18-04 --device-set hdd0 --iface ide
After installing Ubuntu, you can also install OVZ Guest Tools, by stopping the virtual machine before this:
prlctl installtools Ubuntu_18-04
If Ubuntu after installation on your virtual machine does not see the network adapter, stop the virtual machine and run the following command:
prlctl set Ubuntu_18-04 --device-set net0 --adapter-type rtl
This completes the creation of the Ubuntu virtual machine.
1 You can get the list of available distributions using the prlctl set ve_name -d list command
2 To find the virtual machine ID enter the command: prlctl list -a
3 To see the virtual machine configuration (eg device name), use the command: prlctl list Ubuntu_18-04 -i | grep Hardware -A15