loading...

CentOS 7 – Setting up Xen on CentOS 7

Installing Apache On CentOS 8

Xen is an open source solution used to run multiple virtual systems on one machine. It supports both paravirtualization and hardware-assisted full-virtualization. Xen is a very powerful virtualization solution. It offers the capacity to use both virtualization technologies at the same time to always answer the user’s demands.

To create our virtualization environment using Xen, we need to make sure that the Xen Hypervisor will boot just before the machine’s own kernel to have access to as much physical hardware as possible, so it can be used to serve our environment’s virtual machines.

Source: http://www.2virt.com

In this section, we are going to set up Xen4 for CentOS 7. Xen4 is not supported by the default CentOS 7 repository, so we need to add the CentOS Xen repository. But first, we need to make sure that we have some packages installed. These will be needed later during the installation of Xen:


$ sudo yum install bridge-utils SDL net-tools

Then we add the latest Xen repository using YUM:


$ sudo yum install centos-release-xen

In this tutorial, we will be installing Xen Version 4.5, so we need to run the installation command as follows:


$ sudo yum install xen

To verify that the installation is done, we need to list the Xen kernel archive, which is in the /boot folder:


$ ls –l /boot/xen.gz

We should see the following code:


lrwxrwxrwx. 1 root root       12 Aug 23 02:10 /boot/xen.gz -> xen-4.5.1.gz

Now, we move on to the installation of the kernel-xen package. This installation should be executed separately from the Xen installation and after it so that the system boot loader grub can detect the new kernel and get configured correctly:


$ sudo yum install kernel-xen

After having the new kernel installed, we should resolve the SELinux issue. We can try to resolve the issues by determining which modules the SELinux is blocking and resolve that, or if we have a better method to secure our server, we can just disable it. To disable SELinux, we just need to go to its configuration file and disable it:


$ sudo nano /etc/sysconfig/selinux

Then, consider this line:


SELINUX=enforcing

Change it to the following:


SELINUX=disabled

Otherwise, if we need to check the issues, we can follow this. First, we check the log file for the cause of the issue:


$ sudo cat /var/log/messages

Then, we activate the blockage:


$ sudo grep xend /var/log/audit/audit.log | audit2allow -M custom_xen
$ sudo semodule -i custom_xen.pp

And this should resolve the issue. Finally, we can restart the system and boot the new Xen kernel. After the restart, we need to check whether the Xen kernel is correctly installed:


$ sudo xl info

To use Xen, we need to install some tools and packages to make the virtual machines run well. First, we need to make sure that the basic usage packages are installed:


$ sudo yum install bridge-utils tunctl wget vim-enhanced rsync openssh-clients libvirt python-virtinst libvirt-daemon-xen 

Then, we need to configure the network. But before that, we must create the bridge interface:


$ sudo nano /etc/sysconfig/network-scripts/ifcfg-brid0

Next, we add the following lines inside the file that we have just opened using nano and save it:


DEVICE=brid0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes

Then, we make minor changes to the default network interface configuration file to use the bridged interface:


$ sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=XX:XX:XX:XX:XX:XX
ONBOOT=yes
TYPE=Ethernet
IPV6INIT=no
USERCTL=no
BRIDGE=brid0

Note

We need to change the MAC address with the Ethernet interface MAC address. We can check that using ifconfig.

After that, we reboot the system. With this, the bridge network is ready to be used. Then, we download any Linux system for the test. Next, we need to make it an IMG file using the dd command:


$ sudo dd if=/dev/zero of=Centos.img bs=4K count=0 seek=1024K
qemu-img create -f raw Centos.img 8G

Then, we download any Linux system for the test. Moreover, we must create a kick-start file and put it at the same location:


$ sudo nano ks.cfg

Then, we add the following code with the required modification:


kernel = "/boot/vmlinuz-xen-install"
ramdisk = "/boot/initrd-xen-install"
extra = "text"
name = "mailserver"
memory = "256"
disk = [ 'tap:aio:/srv/xen/mailserver.img,xvda,w', ]
vif = [ 'bridge=brid0', ]
vcpus=1
on_reboot = 'destroy'
on_crash = 'destroy'

Finally, we use virt-install to create the VM:


$ sudo virt-install -d -n CentOS7VM1 -r 1024 --vcpus=2 \
--bridge=brid0 --disk ./Centos.img \
--nographics -p -l "./Centos" \
--extra-args="text console=com1 utf8 console=hvc0 ks=./ks.cfg"

Now the virtual machine should start and be able to get an IP from the DHCP server; so we can continue tweaking it and adding the required service.

For Xen usage, we need to use the following commands (we are going to present the most common ones. For more, you can always follow this link https://www.centos.org/docs/5/html/Virtualization-en-US/virt-task-xm-create-manage-doms.html):

  • To connect to the virtual machine:
    
    $ sudo xm console CentOS7VM1
    
  • To shutdown or reboot a machine:
    
    $ sudo xm shutdown CentOS7VM1
    $ sudo xm reboot CentOS7VM1
    
  • To remove (terminate) a machine:
    
    $ sudo xm destroy CentOS7VM1
    
  • To suspend and resume a machine:
    
    $ sudo xm suspend CentOS7VM1
    $ sudo xm resume CentOS7VM1
    
  • To rename a machine
    
    $ sudo xm rename CentOS7VM1 CentOS7VM2
    
  • To pause, and then unpause a machine:
    
    $ sudo xm pause CentOS7VM1
    $ sudo xm unpause CentOS7VM1
    

Comments are closed.

loading...