In this article, I would like to explain how the Kernel-based Virtual Machine (KVM) and the Oracle VirtualBox works within Oracle Linux 7.x as nested virtualization.
The following depicts the scenario as a diagram:
According to the above diagram, first create an instance on the OCI Environment (You can use any version of Oracle Linux ). Then, do the installation for the whole configuration.
Once the installation is done, you could connect via VNC Viewer or xRDP. You can open the Virtual Machine Manager on the Oracle Linux Environment, and create VMs on KVM (Kernel-based Virtual Machine).
Once you have installed the Oracle VirtualBox, you can open the application up and create VMs in that environment as well.
The above concept is called “Nested Virtualization”.
Please follow the below steps:
- Instance Creation on Oracle Cloud Infrastructure (OCI)
As a first step, you need to go to the Oracle Cloud Infrastructure(OCI).
Then click on the “Create Instance” button and add the public key as shown below.
2. The Public Key and Private Key Creation
For the public key and private key creation give the below command in your local machine.
ssh-keygen -t rsa
Then ssh into it.
ssh -i<private_key> opc@<public_ip> (ssh as an opc user)
Once you have done the key creation, move onto the KVM installation!
3. KVM and Other Installations
Install the qemu package and it will provide a graphical interface to manage virtual machines.
sudo yum -y install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer
Install the VNC packages.
sudo yum group list
sudo yum groupinstall “Server with GUI”sudo yum install xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils tigervnc-server -y
Then copy the vncserver@.service file into the vncserver@:1.service file.
sudo cp vncserver@.service vncserver@:1.servicesudo vi vncserver\@\:1.service
Replace <USER> with “opc” (username) in vncserver@:1.service.
Now, set the VNC password for the OPC user, defined in vncserver@:1.service.
Then, install firewalld on the Linux VM.
sudo yum install firewalldsudo systemctl start firewalldsudo systemctl enable firewalld
Configure the firewall to allow the VNC connection.
sudo firewall-cmd --zone=public --add-service vnc-serverfirewall-cmd --zone=public --permanent --add-port=5901/tcp
Configure VNC to autostart.
sudo systemctl daemon-reloadsudo systemctl enable vncserver@:1.servicesudo systemctl start vncserver@:1.service
4. An Ingress Rule Creation
Now go back to OCI and go to the Virtual Cloud Network(VCN) section; then click on Security Lists and create an ingress rule with the below configuration.
Source/CIDR Range: 0.0.0.0/0IP Protocol: TCPSource Port Range: AllDestination Port Range: 5901Allows: TCP traffic for ports: 5901
Reboot the instance.
Then download the VNC viewer application to your local machine. [https://www.realvnc.com/en/connect/download/viewer/]
Open the application and enter the below details:
<public_ip>:<5901>(the port that you configured)
Put the password that you entered earlier [vnc password].
Now you have successfully connected to the Oracle Linux VM!
5. Setup an Ubuntu VM on KVM
Download an Ubuntu ISO file.
Then create a new VM on the virtual machine manager application.
Now you have successfully completed the setup of KVM on Oracle Linux!
6. Setup Xrdp
Install the Xrdp package using the yum command.
yum -y install xrdp tigervnc-server
Once the package installation is done, start the Xrdp service.
systemctl start xrdp
Xrdp now should be listening on port 3389. Confirm it by using netstat.
netstat -antup | grep xrdp
Reboot the system and once again start the xRDP service.
sudo rebootsystemctl enable xrdp
Configure the firewall using the below commands.
firewall-cmd --permanent --add-port=3389/tcpfirewall-cmd --reload
Then, change the root password.
Go back to OCI VCN Security Lists and create an ingress rule as below:
Source/CIDR Range: 0.0.0.0/0IP Protocol: TCPSource Port Range: AllDestination Port Range: 3389Allows: TCP traffic for ports: 3389
Then check it with Remote Desktop Connection software. Put the public IP address under the PC name.
Ignore the security warning and connect with xRDP.
7. Oracle VirtualBox Installation
Open the terminal in your Oracle Linux VM.
Then check the Linux kernel version using the below command. (This step is required.)
Once you check the Linux kernel version, install the correct version of the Kernel with uname-r for the Oracle Virtualbox VM configuration. (This step is also required.)
yum install kernel-uek-devel-$(uname -r)
Then exit the terminal and reboot the instance.
Install the VirtualBox using the below command.
yum install VirtualBox-5.1
Open the Oracle VirtualBox (I have already installed an ubuntu VM and configured it as below).
Click the “New” button and create a VM in the Oracle VirtualBox.
Once you have finished the creation, click “Start”.
The VM will be starting successfully!
Nested virtualization allows you to run a virtual machine (VM) inside another VM while still using hardware acceleration from the host. In this article, I have done the nested virtualization on the Oracle Cloud Infrastructure (OCI).
Thanks for reading, and let me know what you think!