Difference between revisions of "Book/HelloXenProject/4-Chapter"

From Xen
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Chapter 4: =
+
= Chapter 4: Using Xen Project =
  
= Using Xen Project =
+
== Configuring and Booting Virtual Machines ==  
  
 +
Welcome to chapter 4, I bet this chapter is, the more interested chapter for you and you can learn to run and manage your Virtual Machines via The Xen Project. In this chapter, we show you how you can configure DomU and setting up your network and storage. We knows, You are familiar with Linux but we show you some Linux tools for manage LVM and create your partitions. After this chapter, You can manage Xen Project and your Virtual Machines and Install GNU/Linux and Windows OS on your Xen Project ax DomU. We will speak about a tool with the name “ virt-manager” that is a Graphical tool for managing your Vms.
  
 +
By default, Fedora Server edition not have any Graphical Environment and as you know, The Graphical Environment need a lot of resources and not a good idea for server. So, System administrator don't like to install Graphical Environment and prefer CLI. You may ask yourself, Some Graphical Environment like “XFCE” need low resources but compared with CLI they need more resources.
  
 +
== {{anchor|Toc476606914}} Manage virtual machines with virt-manager ==
  
 +
We want to show you “virt-manager” and it is a graphical program, Thus we need to install a Graphical Environment. Popular Desktops in Fedora are “Gnome” , “KDE” , “XFCE” and “MATE” but you can use other Desktops too.
  
 +
For Install a Graphical Environment use below commands :
  
 +
Gnome :
  
 +
<syntaxhighlight lang="sh"># yum groupinstall gnome</syntaxhighlight>
  
 +
or
  
 +
<syntaxhighlight lang="sh"># yum groupinstall gdm</syntaxhighlight>
  
 +
KDE :
  
 +
<syntaxhighlight lang="sh"># yum groupinstall kde</syntaxhighlight>
  
 +
XFCE :
  
 +
<syntaxhighlight lang="sh"># yum groupinstall xfce</syntaxhighlight>
  
 +
MATE :
  
 +
<syntaxhighlight lang="sh"># yum groupinstall "MATE Desktop”</syntaxhighlight>
  
  
 +
When installing finished just run below command :
  
 +
<syntaxhighlight lang="sh"># startx</syntaxhighlight>
  
 +
And after it you can see your Desktop. Mine is:
  
 +
[[Image:Figure_18_-_MATE_Desktop.png|top|600px|none|thumb|Figure 18 : MATE Desktop.]]
  
  
 +
Open a “Terminal” and type below command for installing “Virt-Manager” :
  
 +
<syntaxhighlight lang="sh"># yum install virt-manager</syntaxhighlight>
  
 +
After it you can run “virt-manager”.
  
 +
Usually, Xen Masters use LVM volumes to store the Xen guest virtual disks and we will explain it in the future and skip it now, But just know that you can use Virtual HDD and real partition for your Guest DomU.
  
 +
The Virt-manager, provide a good GUI and you can create your DomU via it very easy :
  
 +
[[Image:Figure_19-_Virt-Manager_(OpenSUSE).png|top|600px|none|thumb|Figure 19 : Virt-Manager (OpenSUSE).]]
  
 +
[[Image:Figure_20-_Virt-Manager_(Create_Fedora_22_as_DomU_on_OpenSUSE).png|top|600px|none|thumb|Figure 20 : Virt-Manager (Create Fedora 22 as DomU on OpenSUSE).]]
  
 +
As you see, It is easy as ABC and give you this ability to run your own DomU guest via a nice Graphical interface.
  
 +
Note that, If after install Graphical Environment your Xen Project show you an error, Then don't worry and Just Reinstall the Xen Project via below command :
  
 +
<syntaxhighlight lang="sh"># dnf reinstall xen*</syntaxhighlight>
  
 +
After, Everything back to a right point.
  
 +
If you start “Virt-Manager” and see some error like “unable to connect to libvirt” then don't worry, Just type below command :
  
 +
<syntaxhighlight lang="sh"># service libvirtd restart</syntaxhighlight>
  
 +
You as a Linux administrator know that Linux has “/var/log/” directory that record everything that happening in your system. After install Xen, The Xen Project create a directory with the name “xen” under “/var/log” and all Xen errors and...recorded under this directory. If you encounter with any error just see “/var/log/xen/”.
  
 +
OK, It is enough and you are familiar with “Virt-Manager”. Now, It is a good time for speaking about “ Storage and Networking”. Let's Go!
  
 +
== {{anchor|Toc476606915}} Storage and Networking ==
  
 +
The Xen Project can use your real partition on your HDD as a Guest HDD and you can add HDD image also. We say it “Local Storage”. The Local Storage can partitioned via a tool like “LVM” or you can save your HDD image as a file on it. Let me to speak about LVM more.
  
'''''Configuring and Booting Virtual Machines'''''
+
LVM or Logical Volume Manager is a device mapper in Linux. You may ask, What is Device Mapper? OK, The Device Mapper is a framework that provided by The Linux Kernel and its goal is mapping physical block devices onto high-level virtual block devices. Device Mapper passing data from a virtual block device to another block device. The LVM provide logical volume management for the Linux Kernel and a method of allocating space on storage devices. LVM is more flexible that traditional partitioning. When you install Linux, It selected a best method for partitioning by default.
  
Welcome to chapter 4, I bet this chapter is, the more interested chapter for you and you can learn to run and manage your Virtual Machines via The Xen Project. In this chapter, we show you how you can configure DomU and setting up your network and storage. We knows, You are familiar with Linux but we show you some Linux tools for manage LVM and create your partitions. After this chapter, You can manage Xen Project and your Virtual Machines and Install GNU/Linux and Windows OS on your Xen Project ax DomU. We will speak about a tool with the name “ virt-manager” that is a Graphical tool for managing your Vms.
+
You can consider “LVM” as a "dynamic partitions", Its mean that you can create/resize/delete partitions while your Linux is running and you don't need any reboot for influence. LVM have many benefits but some of important of them are :
  
By default, Fedora Server edition not have any Graphical Environment and as you know, The Graphical Environment need a lot of resources and not a good idea for server. So, System administrator don't like to install Graphical Environment and prefer CLI. You may ask yourself, Some Graphical Environment like “XFCE” need low resources but compared with CLI they need more resources.
+
* It can support more than one HDD.
  
 +
* LVM can be created to support RAID. including RAID 1, RAID 5 and RAID 6
  
 +
* It can support HA (High availability) and is a good option for Clusters.
  
 +
* Save space. Small chunks of unused space from several disks can be combined to create a usable volume.
  
 +
With a lot of features, It has some bad things too. For example, the initial set-up of LVM is more complex than just partitioning a disk and you must understand LVM scheme and models.
  
 +
It a good figure that help you to understand LVM easily :
  
== {{anchor|Toc476606914}} <span style="color:#00000a;">Manage virtual machines with virt-manager</span> ==
+
[[Image:Figure_21-_LVM_Scheme..png|top|600px|none|thumb|Figure 21 : LVM Scheme.]]
  
We want to show you “virt-manager” and it is a graphical program, Thus we need to install a Graphical Environment. Popular Desktops in Fedora are “Gnome” , “KDE” , “XFCE” and “MATE” but you can use other Desktops too.
 
  
For Install a Graphical Environment use below commands :
+
I guess you understand it better. I want to show you some Linux Tools that via them you can manage your HDDs.
  
Gnome :
+
The first tool that we cover here is “fdisk” or “cfdisk”. Just type :
  
<nowiki># yum groupinstall gnome</nowiki>
+
<syntaxhighlight lang="sh"># cfdisk</syntaxhighlight>
  
 
or
 
or
  
<nowiki># yum groupinstall gdm</nowiki>
+
<syntaxhighlight lang="sh"># fdisk -l</syntaxhighlight>
  
KDE :
+
I bet you will found “cfdisk” more friendly. The “fdisk -l” command will show you all of your partitions and HDD on your system. For example, For mine is :
  
<nowiki># yum groupinstall kde</nowiki>
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# fdisk -l
  
XFCE :
+
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
  
<nowiki># yum groupinstall xfce</nowiki>
+
Units: sectors of 1 * 512 = 512 bytes
  
MATE :
+
Sector size (logical/physical): 512 bytes / 512 bytes
  
<nowiki># yum groupinstall "MATE Desktop”</nowiki>
+
I/O size (minimum/optimal): 512 bytes / 512 bytes
  
 +
Disklabel type: dos
  
When installing finished just run below command :
+
Disk identifier: 0xed8a6a75
  
<nowiki># startx</nowiki>
+
Device Boot Start End Sectors Size Id Type
  
And after it you can see your Desktop. Mine is:
+
/dev/sda1 2048 662710271 662708224 316G 8e Linux LVM
  
[[Image:Figure_18_-_MATE_Desktop.png|top|600px|none|thumb]]
+
Disk /dev/mapper/fedora-root00: 300 GiB, 322122547200 bytes, 629145600 sectors
  
===== <span style="color:#00000a;">Figure 18 : MATE Desktop.=====
+
Units: sectors of 1 * 512 = 512 bytes
  
 +
Sector size (logical/physical): 512 bytes / 512 bytes
  
Open a “Terminal” and type below command for installing “Virt-Manager” :
+
I/O size (minimum/optimal): 512 bytes / 512 bytes
  
<nowiki># yum install virt-manager</nowiki>
+
Disk /dev/mapper/fedora-swap: 16 GiB, 17179869184 bytes, 33554432 sectors
  
After it you can run “virt-manager”.
+
Units: sectors of 1 * 512 = 512 bytes
  
Usually, Xen Masters use LVM volumes to store the Xen guest virtual disks and we will explain it in the future and skip it now, But just know that you can use Virtual HDD and real partition for your Guest DomU.
+
Sector size (logical/physical): 512 bytes / 512 bytes
  
The Virt-manager, provide a good GUI and you can create your DomU via it very easy :
+
I/O size (minimum/optimal): 512 bytes / 512 bytes
 +
</syntaxhighlight>
  
 +
And “cfdisk” :
  
 +
[[Image:Figure_22-_cfdisk..png|top|600px|none|thumb|Figure 22 : cfdisk.]]
  
 +
OK. The first method that we choice is using your real partition as guest HDD.
  
 +
I added a new HDD to my system and linux detected it as “sdb”. Let me to tell you how Linux detect Device/Drive names. If you look at “/dev/” directory then you will find interesting names. Linux detect IDE Disk as “hd” and SCSI disks as “sd”. The complete scheme is “/dev/xxyn”. The “xx” is “hd” or “sd” as we said and :
  
 +
* Y : It is a letter that indicate the number of Hard Disk. For example, “hda” mean the first IDE disk and “sda” mean the first SCSI Disk.
  
 +
* N : It is a number that indicate the number of partition. Don't forget, The first four partitions (primary or extended) are in range 1..4. Logical partitions start from 5. For example, “/dev/hda2” mean the first IDE Hard Disk and The second primary or extended partition and “/dev/sdb5” mean the first logical partition on second SCSI hard disk.
  
 +
We explained it because we don't like you remove other partitions and lost your data.
  
<div style="text-align:center;">[[Image:Figure_19-_Virt-Manager_(OpenSUSE).png|top|600px|none|thumb]]</div>
+
I added a new HDD to my system and Linus detected it as “sdb”. I use below command for look at my new HDD :
  
===== <span style="color:#00000a;">Figure 19 : Virt-Manager (OpenSUSE).=====
+
<syntaxhighlight lang="sh"># cfdisk /dev/sdb</syntaxhighlight>
  
 +
[[Image:Figure_23-_cfdisk.png|top|600px|none|thumb|Figure 23 : cfdisk.]]
  
 +
Create a partition via “cfdisk” is straightforward and don't need any teach, But don't forget to select “Empty” as your file system. Our suggestion is that don't create any partition and just use “parted” tool as below.
  
 +
I used a tool with the name “parted” as below :
  
 +
<syntaxhighlight lang="sh"># parted /dev/sdb mklabel msdos</syntaxhighlight>
  
 +
It show you a warning message about that all of your information will be destroy. Type “yes” and enter. Then, Write below command :
  
 +
<syntaxhighlight lang="sh"># parted /dev/sdb mkpart primary</syntaxhighlight>
  
 +
after this command, Linux ask you some questions, I selected default file system (ext2) and enter “1” as “Start” and “100%” as “End”.
  
 +
What do you see? Linux created a partition for you with the name “/dev/sdb1”. You can confirm it via below command :
  
 +
<syntaxhighlight lang="sh"># fdisk /dev/sdb -l</syntaxhighlight>
  
 +
[[Image:Figure_24-_fdisk.png|top|600px|none|thumb|Figure 24 : fdisk.]]
  
 +
After it, I want enable “LVM” for this partition and use below command :
  
 +
<syntaxhighlight lang="sh"># parted -s /dev/sdb set 1 lvm on</syntaxhighlight>
  
 +
In above command I used “set 1” that mean partition 1. Let me to see our partitions via “fdisk” command :
  
 +
<syntaxhighlight lang="sh"># fdisk /dev/sdb -l</syntaxhighlight>
  
 +
[[Image:Figure_25-_fdisk_-l.png|top|600px|none|thumb|Figure 25 : fdisk -l.]]
  
<div style="text-align:center;">[[Image:Figure_20-_Virt-Manager_(Create_Fedora_22_as_DomU_on_OpenSUSE).png|top|600px|none|thumb]]</div>
 
  
===== <span style="color:#00000a;">Figure 20 : Virt-Manager (Create Fedora 22 as DomU on OpenSUSE).=====
+
Look carefully, You can see “LVM” at the end of line. It mean that “LVM” enable for our partition.
  
 +
Type below command :
  
As you see, It is easy as ABC and give you this ability to run your own DomU guest via a nice Graphical interface.
+
<syntaxhighlight lang="sh"># pvcreate /dev/sdb1</syntaxhighlight>
  
Note that, If after install Graphical Environment your Xen Project show you an error, Then don't worry and Just Reinstall the Xen Project via below command :
+
<syntaxhighlight lang="sh"># vgcreate Xen /dev/sdb1 -v</syntaxhighlight>
  
<nowiki># dnf reinstall xen*</nowiki>
+
[[Image:Figure_26-_vgcreate.png|top|600px|none|thumb|Figure 26 : vgcreate.]]
  
After, Everything back to a right point.
+
<syntaxhighlight lang="sh"># lvcreate -L 8G -v -n Fedora Xen</syntaxhighlight>
  
If you start “Virt-Manager” and see some error like “unable to connect to libvirt” then don't worry, Just type below command :
+
In above command, You should select your size (We selected 8 Gigabyte) and logical volume name (Fedora) and a name that you typed in the previous command (Xen). The output is :
  
<nowiki># service libvirtd restart</nowiki>
+
[[Image:Figure_27-_lvcreate.png|top|600px|none|thumb|Figure 27 : lvcreate.]]
  
 +
Let me to see our LVM via “vgdisplay” command :
  
You as a Linux administrator know that Linux has “/var/log/” directory that record everything that happening in your system. After install Xen, The Xen Project create a directory with the name “xen” under “/var/log” and all Xen errors and...recorded under this directory. If you encounter with any error just see “/var/log/xen/”.
+
<syntaxhighlight lang="sh"># vgdisplay | more</syntaxhighlight>
  
OK, It is enough and you are familiar with “Virt-Manager”. Now, It is a good time for speaking about “ Storage and Networking”. Let's Go!
+
[[Image:Figure_28-_vgdisplay-1.png|top|600px|none|thumb|Figure 28 : vgdisplay-1.]]
  
 +
[[Image:Figure_29-_vgdisplay-2.png|top|600px|none|thumb|Figure 29 : vgdisplay-2.]]
  
 +
OK, our storage is ready and we just need to create a config file for our VM. Before we dive into config file, Please let us for write something about “Networking”.
  
 +
== {{anchor|Toc476606916}} Networking in Xen ==
  
 +
Create and configure network in real world is a hard job and can be complex in some areas. In VM world it can be complex too and depending on the network diagram. We never explain networking here complete byt we just show you how you can configure a simple network for your VM and your VM able to see external world.
  
 +
It is true that Virtual Machines share your interfaces but it is not true that you must not concern about the security.
  
== {{anchor|Toc476606915}} <span style="color:#00000a;">Storage and Networking</span> ==
+
The Xen Project support some kind of networking that we will show you them here :
  
The Xen Project can use your real partition on your HDD as a Guest HDD and you can add HDD image also. We say it “Local Storage”. The Local Storage can partitioned via a tool like “LVM” or you can save your HDD image as a file on it. Let me to speak about LVM more.
+
Bridge : Dom0 and DomU are connected to each other via a virtual network. It is a default and most common configuration. In this configuration, a software bridge created in the backend domain and the Virtual network connected to your physical network. For bridging you can use two schemes :1) Linux detect your NIC as “eth0” and in the first scheme, Your eth0 renamed to other name (myeth0) and bridge changed to eth0 2) in the second scheme, Your NIC remain eth0 and your bridge is mybr0.
  
LVM or Logical Volume Manager is a device mapper in Linux. You may ask, What is Device Mapper? OK, The Device Mapper is a framework that provided by The Linux Kernel and its goal is mapping physical block devices onto high-level virtual block devices. Device Mapper passing data from a virtual block device to another block device. The LVM provide logical volume management for the Linux Kernel and a method of allocating space on storage devices. LVM is more flexible that traditional partitioning. When you install Linux, It selected a best method for partitioning by default.
+
Names are personalisation and you can select other names.
  
You can consider “LVM” as a "dynamic partitions", Its mean that you can create/resize/delete partitions while your Linux is running and you don't need any reboot for influence. LVM have many benefits but some of important of them are :
+
NAT : Network Address Translation or NAT is kind of routing and each guest have its own IP address. In NAT, Dom0 configured to forward your packets and iptables used to configure your Dom0 Kernel as a IP packet filter. NAT using RFC1918 addresses (http://tools.ietf.org/html/rfc1918).
  
●It can support more than one HDD.
+
Routing : In Routing your Dom0 configured for forward packets and a point-to-point link created between Dom0 and each DomU Virtual NIC. Don't forget, because of nature of routing, each of guest NIC must have static IP address.
  
●LVM can be created to support RAID. including RAID 1, RAID 5 and RAID 6
+
OK, Xen need bridge for running and we want to show that you how you can create a Bridge for The Xen Project.
  
●It can support HA (High availability) and is a good option for Clusters.
+
Depend on your Linux Distro (Dom0) you can use some tools for create a bridge in easy way. For example, On Fedora and Debian you can use “bridge-utils” for configure your Bridge.
  
●Save space. Small chunks of unused space from several disks can be combined to create a usable volume.
+
My Current config are :
  
 +
<syntaxhighlight lang="sh">
 +
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  
With a lot of features, It has some bad things too. For example, the initial set-up of LVM is more complex than just partitioning a disk and you must understand LVM scheme and models.
+
inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255
  
It a good figure that help you to understand LVM easily :
+
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
  
 +
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
  
 +
RX packets 989 bytes 84310 (82.3 KiB)
  
<div style="text-align:center;">[[Image:Figure_21-_LVM_Scheme..png|top|600px|none|thumb]]</div>
+
RX errors 0 dropped 0 overruns 0 frame 0
  
===== <span style="color:#00000a;">Figure 21 : LVM Scheme.=====
+
TX packets 77 bytes 9575 (9.3 KiB)
  
 +
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
I guess you understand it better. I want to show you some Linux Tools that via them you can manage your HDDs.
+
<syntaxhighlight lang="sh">
 +
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  
The first tool that we cover here is “fdisk” or “cfdisk”. Just type :
+
inet 127.0.0.1 netmask 255.0.0.0
  
<nowiki># cfdisk</nowiki>
+
inet6 ::1 prefixlen 128 scopeid 0x10<host>
  
or
+
loop txqueuelen 1 (Local Loopback)
  
<nowiki># fdisk -l</nowiki>
+
RX packets 83 bytes 9332 (9.1 KiB)
  
I bet you will found “cfdisk” more friendly. The “fdisk -l” command will show you all of your partitions and HDD on your system. For example, For mine is :
+
RX errors 0 dropped 0 overruns 0 frame 0
  
[root@localhost ~]# fdisk -l
+
TX packets 83 bytes 9332 (9.1 KiB)
  
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
Units: sectors of 1 * 512 = 512 bytes
+
<syntaxhighlight lang="sh">
 +
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  
Sector size (logical/physical): 512 bytes / 512 bytes
+
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)
  
Disklabel type: dos
+
RX packets 0 bytes 0 (0.0 B)
  
Disk identifier: 0xed8a6a75
+
RX errors 0 dropped 0 overruns 0 frame 0
  
Device Boot Start End Sectors Size Id Type
+
TX packets 0 bytes 0 (0.0 B)
  
/dev/sda1 2048 662710271 662708224 316G 8e Linux LVM
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
Disk /dev/mapper/fedora-root00: 300 GiB, 322122547200 bytes, 629145600 sectors
+
As you see, Fedora detect my NIC as “enp7s0” and its IP address is “172.30.9.20”. I must tell you that it is a static IP and not DHCP. I will tell you something about DHCP too.
  
Units: sectors of 1 * 512 = 512 bytes
+
I want to create a bridge that use this static IP, So I create a file via below command :
  
Sector size (logical/physical): 512 bytes / 512 bytes
+
<syntaxhighlight lang="sh"># touch /etc/sysconfig/network-scripts/ifcfg-br0</syntaxhighlight>
  
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
Then open it via an editor like “nano” and fill it with below information :
  
Disk /dev/mapper/fedora-swap: 16 GiB, 17179869184 bytes, 33554432 sectors
+
<syntaxhighlight lang="sh">
 +
DEVICE=br0
  
Units: sectors of 1 * 512 = 512 bytes
+
TYPE=Bridge
  
Sector size (logical/physical): 512 bytes / 512 bytes
+
BOOTPROTO=none
  
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
ONBOOT=yes
  
 +
IPADDR=172.30.9.20
  
And “cfdisk” :
+
PREFIX=24
  
<div style="text-align:center;">[[Image:Figure_22-_cfdisk..png|top|600px|none|thumb]]</div>
+
GATEWAY=172.30.9.254
  
===== <span style="color:#00000a;">Figure 22 : cfdisk.=====
+
DNS1=172.30.9.1
  
OK. The first method that we choice is using your real partition as guest HDD.
+
DELAY=0
  
I added a new HDD to my system and linux detected it as “sdb”. Let me to tell you how Linux detect Device/Drive names. If you look at “/dev/” directory then you will find interesting names. Linux detect IDE Disk as “hd” and SCSI disks as “sd”. The complete scheme is “/dev/xxyn”. The “xx” is “hd” or “sd” as we said and :
+
NM_CONTROLLED=no
 +
</syntaxhighlight>
  
●Y : It is a letter that indicate the number of Hard Disk. For example, “hda” mean the first IDE disk and “sda” mean the first SCSI Disk.
+
But, If your real NIC use DHCP protocol then you should use below config for Bridge :
  
●N : It is a number that indicate the number of partition. Don't forget, The first four partitions (primary or extended) are in range 1..4. Logical partitions start from 5. For example, “/dev/hda2” mean the first IDE Hard Disk and The second primary or extended partition and “/dev/sdb5” mean the first logical partition on second SCSI hard disk.
+
<syntaxhighlight lang="sh">
 +
DEVICE=br0
  
We explained it because we don't like you remove other partitions and lost your data.
+
TYPE=Bridge
  
I added a new HDD to my system and Linus detected it as “sdb”. I use below command for look at my new HDD :
+
BOOTPROTO=dhcp
  
<nowiki># cfdisk /dev/sdb</nowiki>
+
ONBOOT=yes
  
<div style="text-align:center;">[[Image:Figure_23-_cfdisk.png|top|600px|none|thumb]]</div>
+
DELAY=0
  
===== <span style="color:#00000a;">Figure 23 : cfdisk.=====
+
NM_CONTROLLED=no
 +
</syntaxhighlight>
  
Create a partition via “cfdisk” is straightforward and don't need any teach, But don't forget to select “Empty” as your file system. Our suggestion is that don't create any partition and just use “parted” tool as below.
+
After it, I must change my real NIC configuration, So I open it via an editor :
  
I used a tool with the name “parted” as below :
+
<syntaxhighlight lang="sh"># nano /etc/sysconfig/network-scripts/ifcfg-enp7s0</syntaxhighlight>
  
<nowiki># parted /dev/sdb mklabel msdos</nowiki>
+
<syntaxhighlight lang="sh">
 +
HWADDR=50:E5:49:40:C4:8F
  
It show you a warning message about that all of your information will be destroy. Type “yes” and enter. Then, Write below command :
+
TYPE=Ethernet
  
<nowiki># parted /dev/sdb mkpart primary</nowiki>
+
BOOTPROTO=none
  
after this command, Linux ask you some questions, I selected default file system (ext2) and enter “1” as “Start” and “100%” as “End”.
+
DEFROUTE=yes
  
What do you see? Linux created a partition for you with the name “/dev/sdb1”. You can confirm it via below command :
+
IPV4_FAILURE_FATAL=no
  
<nowiki># fdisk /dev/sdb -l</nowiki>
+
IPV6INIT=yes
  
[[Image:Figure_24-_fdisk.png|top|600px|none|thumb]]
+
IPV6_AUTOCONF=yes
  
===== <span style="color:#00000a;">Figure 24 : fdisk.=====
+
IPV6_DEFROUTE=yes
  
After it, I want enable “LVM” for this partition and use below command :
+
IPV6_FAILURE_FATAL=no
  
<nowiki># parted -s /dev/sdb set 1 lvm on</nowiki>
+
NAME=enp7s0
  
In above command I used “set 1” that mean partition 1. Let me to see our partitions via “fdisk” command :
+
UUID=5e520f04-b32c-4116-b61f-89c190868edc
  
<nowiki># fdisk /dev/sdb -l</nowiki>
+
ONBOOT=yes
  
[[Image:Figure_25-_fdisk_-l.png|top|600px|none|thumb]]
+
#IPADDR=172.30.9.20<
  
===== <span style="color:#00000a;">Figure 25 : fdisk -l.=====
+
#PREFIX=24
  
 +
#GATEWAY=172.30.9.254
  
Look carefully, You can see “LVM” at the end of line. It mean that “LVM” enable for our partition.
+
#DNS1=172.30.9.1
  
Type below command :
+
IPV6_PEERDNS=yes
  
<nowiki># pvcreate /dev/sdb1</nowiki>
+
IPV6_PEERROUTES=yes
  
<nowiki># vgcreate Xen /dev/sdb1 -v</nowiki>
+
IPV6_PRIVACY=no
  
[[Image:Figure_26-_vgcreate.png|top|600px|none|thumb]]
+
NM_CONTROLLED=no
  
===== <span style="color:#00000a;">Figure 26 : vgcreate.=====
+
BRIDGE=br0
 +
</syntaxhighlight>
  
<nowiki># lvcreate -L 8G -v -n Fedora Xen</nowiki>
+
As you see, My current NIC configuration use “BOOTPROTO=none” and its mean Static IP and if it was “DHCP” then you can't see any parts like “IPADDR”, “ PREFIX”, “GATEWAY” and “ DNS1” because all of these parts gaining automatically. Because of I added all of these parts to my Bridge then I must remove these parts from real NIC configuration file and add “NM_CONTROLLED=no” and “BRIDGE=br0” at the end of file. Don't forget, “br0” is my bridge name and you can select any name that you like.
  
In above command, You should select your size (We selected 8 Gigabyte) and logical volume name (Fedora) and a name that you typed in the previous command (Xen). The output is :
+
If my NIC use DHCP protocol then I didn't need any extra works.
  
[[Image:Figure_27-_lvcreate.png|top|600px|none|thumb]]
+
Everything is ready and I must restart my network service for take affect :
  
===== <span style="color:#00000a;">Figure 27 : lvcreate.=====
+
<syntaxhighlight lang="sh"># systemctl restart network.service</syntaxhighlight>
  
Let me to see our LVM via “vgdisplay” command :
+
After it, you can see current configuration via “ifconfig” command as below :
  
<nowiki># vgdisplay | more</nowiki>
+
<syntaxhighlight lang="sh">
 +
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  
[[Image:Figure_28-_vgdisplay-1.png|top|600px|none|thumb]]
+
inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255
  
===== <span style="color:#00000a;">Figure 28 : vgdisplay-1.=====
+
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
  
[[Image:Figure_29-_vgdisplay-2.png|top|600px|none|thumb]]
+
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
  
===== <span style="color:#00000a;">Figure 29 : vgdisplay-2.=====
+
RX packets 846 bytes 62175 (60.7 KiB)
  
 +
RX errors 0 dropped 0 overruns 0 frame 0
  
OK, our storage is ready and we just need to create a config file for our VM. Before we dive into config file, Please let us for write something about “Networking”.
+
TX packets 129 bytes 11550 (11.2 KiB)
  
 +
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
 +
<syntaxhighlight lang="sh">
 +
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  
 +
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
  
== {{anchor|Toc476606916}} <span style="color:#00000a;">Networking in Xen</span> ==
+
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
  
Create and configure network in real world is a hard job and can be complex in some areas. In VM world it can be complex too and depending on the network diagram. We never explain networking here complete byt we just show you how you can configure a simple network for your VM and your VM able to see external world.
+
RX packets 5479 bytes 468651 (457.6 KiB)
  
It is true that Virtual Machines share your interfaces but it is not true that you must not concern about the security.
+
RX errors 0 dropped 0 overruns 0 frame 0
  
The Xen Project support some kind of networking that we will show you them here :
+
TX packets 558 bytes 75815 (74.0 KiB)
  
 +
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
Bridge : Dom0 and DomU are connected to each other via a virtual network. It is a default and most common configuration. In this configuration, a software bridge created in the backend domain and the Virtual network connected to your physical network. For bridging you can use two schemes :1) Linux detect your NIC as “eth0” and in the first scheme, Your eth0 renamed to other name (myeth0) and bridge changed to eth0 2) in the second scheme, Your NIC remain eth0 and your bridge is mybr0.
+
<syntaxhighlight lang="sh">
 +
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  
Names are personalisation and you can select other names.
+
inet 127.0.0.1 netmask 255.0.0.0
  
NAT : Network Address Translation or NAT is kind of routing and each guest have its own IP address. In NAT, Dom0 configured to forward your packets and iptables used to configure your Dom0 Kernel as a IP packet filter. NAT using RFC1918 addresses (http://tools.ietf.org/html/rfc1918).
+
inet6 ::1 prefixlen 128 scopeid 0x10<host>
  
 +
loop txqueuelen 1 (Local Loopback)
  
Routing : In Routing your Dom0 configured for forward packets and a point-to-point link created between Dom0 and each DomU Virtual NIC. Don't forget, because of nature of routing, each of guest NIC must have static IP address.
+
RX packets 83 bytes 9332 (9.1 KiB)
  
 +
RX errors 0 dropped 0 overruns 0 frame 0
  
OK, Xen need bridge for running and we want to show that you how you can create a Bridge for The Xen Project.
+
TX packets 83 bytes 9332 (9.1 KiB)
  
Depend on your Linux Distro (Dom0) you can use some tools for create a bridge in easy way. For example, On Fedora and Debian you can use “bridge-utils” for configure your Bridge.
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
My Current config are :
+
<syntaxhighlight lang="sh">
 +
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  
 +
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
+
ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)
  
inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255
+
RX packets 0 bytes 0 (0.0 B)
 
 
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
 
 
 
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
 
 
 
RX packets 989 bytes 84310 (82.3 KiB)
 
  
 
RX errors 0 dropped 0 overruns 0 frame 0
 
RX errors 0 dropped 0 overruns 0 frame 0
  
TX packets 77 bytes 9575 (9.3 KiB)
+
TX packets 0 bytes 0 (0.0 B)
  
 
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
 +
As you see, A Bridge with the name “br0” created and all information of my real NIC (enp7s0) given to my bridge. So, my Bridge work like my real NIC. Don't forget for each Physical NIC you should create a Bridge.
  
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
+
Our network is ready and we must create a Guest config.
  
inet 127.0.0.1 netmask 255.0.0.0
+
== Installing Windows as HVM domainU Guest==
  
inet6 ::1 prefixlen 128 scopeid 0x10<host>
+
Huh, Are you ready? It is the most exciting part of our book and we to show you how you can install your Guest OS.
  
loop txqueuelen 1 (Local Loopback)
+
We choice Window 7 Enterprise for install as Guest and show you that how you can configure your Xen to use this “.iso” file and start your VM.
  
RX packets 83 bytes 9332 (9.1 KiB)
+
First of all, We must create a config file for our VM. Let me to create it via “touch” command in Linux :
  
RX errors 0 dropped 0 overruns 0 frame 0
+
<syntaxhighlight lang="sh"># touch /etc/xen/windows.cfg</syntaxhighlight>
  
TX packets 83 bytes 9332 (9.1 KiB)
+
Then, I open it via an editor like “nano” as below :
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
<syntaxhighlight lang="sh"># nano /etc/xen/windows.cfg</syntaxhighlight>
  
 +
And fill this file via below information :
  
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
+
<syntaxhighlight lang="sh">
 +
name = "Windows7"
  
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
+
builder = "hvm"
  
ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)
+
vcpus = 4
  
RX packets 0 bytes 0 (0.0 B)
+
memory = "4096"
  
RX errors 0 dropped 0 overruns 0 frame 0
+
maxmex= "8192"
  
TX packets 0 bytes 0 (0.0 B)
+
vif=['bridge=br0']
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r']
  
 +
vnc="1"
  
As you see, Fedora detect my NIC as “enp7s0” and its IP address is “172.30.9.20”. I must tell you that it is a static IP and not DHCP. I will tell you something about DHCP too.
+
vnclisten="172.30.9.20"
  
I want to create a bridge that use this static IP, So I create a file via below command :
+
vncconsole="0"
  
 +
boot="dc"
  
<nowiki># touch /etc/sysconfig/network-scripts/ifcfg-br0</nowiki>
+
stdvga=1
  
Then open it via an editor like “nano” and fill it with below information :
+
videoram=32
  
DEVICE=br0
+
on_poweroff = "destroy"
  
TYPE=Bridge
+
on_reboot = "restart"
  
BOOTPROTO=none
+
on_crash = "restart"
 +
</syntaxhighlight>
  
ONBOOT=yes
+
I must tell you something about this file :
  
IPADDR=172.30.9.20
+
* vif=['bridge=br0'] : Because of we choice “br0” as a name of our Bridge then we must write “'bridge=br0'” ,But if your Bridge name is different then you must write your Bridge name instead of it here.
  
PREFIX=24
+
* disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r'] : If you remember, We want to use our real partition as our Guest partition, Thus it is not a File that act as a real HDD. Because of it, We used “phy” that mean Physical. The “Xen” is our LVM and I choice “Fedora” as a name of my 20 GB partition on LVM. You may selected other name that you must put it here.
  
GATEWAY=172.30.9.254
+
* Vnclisten="172.30.9.20" : Because I use the Xen Project on other server and not on my current PC, I must define the IP address of my Xen Server. My Xen Server IP is “172.30.9.20” and if your situation is like us then you must write your Xen Server IP here but if you run the Xen Project on your PC and not another PC or Server then you must write “vnclisten="0.0.0.0"”. When you select “0.0.0.0” as IP then it is your local host.
  
DNS1=172.30.9.1
+
* boot="dc" : the “d” mean “CDROM” and “c” mean your HDD. It is your Boot order and when you Guest installed you can change it to “boot=”c””. The Xen Project parameters are boot on floppy (a), hard disk (c), Network (n) and CD-ROM (d).
  
DELAY=0
 
  
NM_CONTROLLED=no
+
Let us start our Guest. Just type below command :
  
 +
<syntaxhighlight lang="sh"># xl create /etc/xen/windows.cfg</syntaxhighlight>
  
But, If your real NIC use DHCP protocol then you should use below config for Bridge :
+
and if you have not any error in your syntax then your xen just show “Parsing config from /etc/xen/windows.cfg” and your VM started.
  
 +
After it write below command :
  
DEVICE=br0
+
<syntaxhighlight lang="sh"># xl list</syntaxhighlight>
  
TYPE=Bridge
+
and you can see something like below :
  
BOOTPROTO=dhcp
+
<syntaxhighlight lang="sh">
 +
Name ID Mem VCPUsStateTime(s)
  
ONBOOT=yes
+
Domain-0 0 3659 8 r----- 887.6
  
DELAY=0
+
Windows7 19 4096 4 -b---- 23.1
 +
</syntaxhighlight>
  
NM_CONTROLLED=no
+
As you see, “Windows7” is running and we just need connect to it via “vncviewer”. But you must did something on your Firewall.
  
 +
Linux use “iptables” as Firewall and VNC Port is not opened by default and we must open this port for connect to our VNC remotely. Don't forget, We doing it because our Xen server is on another PC and we must connect to it remotely thus we need open VNC Port. The VNC use Port 5900 and TCP protocol.
  
After it, I must change my real NIC configuration, So I open it via an editor :
+
I use “netstat -nat” command for show our current network connections :
  
<nowiki># nano /etc/sysconfig/network-scripts/ifcfg-enp7s0</nowiki>
+
<syntaxhighlight lang="sh"># netstat -nat
  
HWADDR=50:E5:49:40:C4:8F
+
Active Internet connections (servers and established)
  
TYPE=Ethernet
+
Proto Recv-Q Send-Q Local Address Foreign Address State
  
BOOTPROTO=none
+
tcp 0 0 172.30.9.20:5900 0.0.0.0:* LISTEN
  
DEFROUTE=yes
+
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
  
IPV4_FAILURE_FATAL=no
+
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
  
IPV6INIT=yes
+
tcp 0 0 172.30.9.20:22 172.30.10.18:49824 ESTABLISHED
  
IPV6_AUTOCONF=yes
+
tcp6 0 0 :::9090 :::* LISTEN
  
IPV6_DEFROUTE=yes
+
tcp6 0 0 :::22 :::* LISTEN
 +
</syntaxhighlight>
  
IPV6_FAILURE_FATAL=no
+
As you see, The IP “172.30.9.20” and Port “5900” are ready for connect but we must doing some steps for connect to our VM :
  
NAME=enp7s0
+
1- First of all, Install a tool like “vncviewer” on your Linux Distro.
  
UUID=5e520f04-b32c-4116-b61f-89c190868edc
+
2- Depend on your Linux Distro (Dom0) you must use “iptables” for open VNC Port on Dom0 :
  
ONBOOT=yes
+
<syntaxhighlight lang="sh"># iptables -A INPUT -p tcp --dport 5900 -j ACCEPT</syntaxhighlight>
  
<nowiki>#IPADDR=172.30.9.20</nowiki>
+
<syntaxhighlight lang="sh"># iptables-save</syntaxhighlight>
  
<nowiki>#PREFIX=24</nowiki>
+
After it, The Port “5900” is open on your Dom0 and you can connect to it remotely. You can use “iptables -L” for show your current iptables rules.
  
<nowiki>#GATEWAY=172.30.9.254</nowiki>
+
We ready ready to connect to our Xen Server :
  
<nowiki>#DNS1=172.30.9.1</nowiki>
+
<syntaxhighlight lang="sh"># vncviewer 172.30.9.20:5900</syntaxhighlight>
  
IPV6_PEERDNS=yes
+
And after it, A window displayed and we can do Windows install process:
  
IPV6_PEERROUTES=yes
+
[[Image:Figure_30-_Windows_7_on_Xen.png|top|600px|none|thumb|Figure 30 : Windows 7 on Xen.]]
  
IPV6_PRIVACY=no
+
Sometimes you don't like your VM viewed by others and you want set password for it, For do it use below parameter in your VM config file :
  
NM_CONTROLLED=no
+
<syntaxhighlight lang="sh">
 +
vncpasswd=”Your Password”
 +
</syntaxhighlight>
 +
After it, When you want view your VM via VNC you must enter a password :
  
BRIDGE=br0
+
<syntaxhighlight lang="sh">
 +
vncviewer 172.30.9.20:5900
  
As you see, My current NIC configuration use “BOOTPROTO=none” and its mean Static IP and if it was “DHCP” then you can't see any parts like “IPADDR”, “ PREFIX”, “GATEWAY” and “ DNS1” because all of these parts gaining automatically. Because of I added all of these parts to my Bridge then I must remove these parts from real NIC configuration file and add “NM_CONTROLLED=no” and “BRIDGE=br0” at the end of file. Don't forget, “br0” is my bridge name and you can select any name that you like.
+
Connected to RFB server, using protocol version 3.8
  
If my NIC use DHCP protocol then I didn't need any extra works.
+
Performing standard VNC authentication
  
Everything is ready and I must restart my network service for take affect :
+
Password:
 +
</syntaxhighlight>
  
<nowiki># systemctl restart network.service</nowiki>
+
When you working with Your VM, You may have some problems with your Display and you must consider below Links for Troubleshooting your problems :
  
After it, you can see current configuration via “ifconfig” command as below :
+
[http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_do_I_change_the_resolution_of_Xen_PV_domU_vfb_graphical_VNC_console.3F http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_do_I_change_the_resolution_of_Xen_PV_domU_vfb_graphical_VNC_console.3F]
  
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
+
[http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_can_I_get_resolutions_larger_than_800x600_for_Xen_HVM_guest_graphical_VNC_console.3F http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_can_I_get_resolutions_larger_than_800x600_for_Xen_HVM_guest_graphical_VNC_console.3F]
  
inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255
+
A good note that you must consider it is that you should install “Windows PV Drivers” for your Xen VM. Navigate to “http://www.xenproject.org/downloads/windows-pv-drivers.html” and download .TAR files and extract them, then configure your NIC IP address and see your network and copy these files and install them on your Windows Guest. In below figure you can see that I choice a static IP for my Windows Guest :
  
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
+
[[Image:Figure_31-_Static_IP.png|top|600px|none|thumb|Figure 31 : Static IP.]]
  
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
+
When you create another VM:
  
RX packets 846 bytes 62175 (60.7 KiB)
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# netstat -nat
  
RX errors 0 dropped 0 overruns 0 frame 0
+
Active Internet connections (servers and established)
  
TX packets 129 bytes 11550 (11.2 KiB)
+
Proto Recv-Q Send-Q Local Address Foreign Address State
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
tcp 0 0 172.30.9.20:5900  0.0.0.0:* LISTEN
  
 +
tcp 0 0 172.30.9.20:5901 0.0.0.0:* LISTEN
  
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
+
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
  
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
+
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
  
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
+
tcp 0 0 172.30.9.20:5900 172.30.10.18:33869 ESTABLISHED
  
RX packets 5479 bytes 468651 (457.6 KiB)
+
tcp 0 0 172.30.9.20:22 172.30.10.18:55000 ESTABLISHED
  
RX errors 0 dropped 0 overruns 0 frame 0
+
tcp 0 180 172.30.9.20:22 172.30.10.18:54616 ESTABLISHED
  
TX packets 558 bytes 75815 (74.0 KiB)
+
tcp6 0 0 :::9090 :::* LISTEN
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
tcp6 0 0 :::22 :::* LISTEN
 +
</syntaxhighlight>
  
 +
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xl list
  
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
+
Name ID Mem VCPUsStateTime(s)
  
inet 127.0.0.1 netmask 255.0.0.0
+
Domain-0 0 1590 8 r----- 192.7
  
inet6 ::1 prefixlen 128 scopeid 0x10<host>
+
Windows7 9 4096 4 -b---- 21.0
  
loop txqueuelen 1 (Local Loopback)
+
linux 10 2048 1 r----- 64.8
 +
</syntaxhighlight>
  
RX packets 83 bytes 9332 (9.1 KiB)
+
If you pay attention to the output of “ifconfig” command then you will see a default Bridge with the name “virbr0”. We can use this Bridge for add other NIC to our VM. For example, We need more than one NIC on our VM.
  
RX errors 0 dropped 0 overruns 0 frame 0
+
For adding more than one NIC you can use :
  
TX packets 83 bytes 9332 (9.1 KiB)
+
<syntaxhighlight lang="sh">
 +
vif=['bridge=br0','mac=00:16:17:a5:6y:89,bridge=virbr0']
 +
</syntaxhighlight>
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
The “mac” defined the MAC address for our NIC.
  
 +
We can use our first Bridge(br0) for adding more than NIC too but we should add a MAC address fpr each NIC :
  
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
+
<syntaxhighlight lang="sh">
 +
vif=['bridge=br0,mac=00:13:r6:45:g6:9o','mac=00:16:17:a5:6y:89,bridge=br0']
 +
</syntaxhighlight>
  
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
+
In above example, We used the Bridge br0 for adding two NICs but we can't create another Bridge(br1) and attach it other Physical NIC and use it here.
  
ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)
+
== Share storage between VMS==
  
RX packets 0 bytes 0 (0.0 B)
+
In some situation, You may want to use another HDD or other Vms HDD in a VM. It is so easy and you can write the name of your other HDD in “disk” in the config file :
  
RX errors 0 dropped 0 overruns 0 frame 0
+
<syntaxhighlight lang="sh">
 +
disk=['phy:/dev/Xen/Fedora,hda,w','phy:/dev/Xen/linux,hdb,w','file:/home/mohsen/Windows7.iso,hdc:cdrom,r']
 +
</syntaxhighlight>
  
TX packets 0 bytes 0 (0.0 B)
+
In above example, my main HDD is “Fedora” and I mount another HDD (linux) as “hdb”. When I fire my “vm” then I can see other HDD in my vm. If you noted, Then you can see “w” and “r” word at the end of my lines. What are these? The “w” mean “read-write” and “r” mean “read-only”.
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
== {{anchor|Toc476606917}} VM States in The Xen Project ==
  
 +
When you run a VM through Xen and run “xl list” then you can see a column with the name “State” and a word that changed sometimes. What does this word mean?
  
As you see, A Bridge with the name “br0” created and all information of my real NIC (enp7s0) given to my bridge. So, my Bridge work like my real NIC. Don't forget for each Physical NIC you should create a Bridge.
+
For example, I run “xl list” and the output is as below :
  
Our network is ready and we must create a Guest config.
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xl list
  
 +
Name ID Mem VCPUsStateTime(s)
  
 +
Domain-0 0 1590 8 r----- 1211.3
  
 +
OpenSUSE 44 2048 1 r----- 4.6
 +
</syntaxhighlight>
  
 +
I will tel you something about these words :
  
 +
* r - running
  
'''''Installing Windows as HVM domainU Guest'''''
+
The domain is currently running.
  
Huh, Are you ready? It is the most exciting part of our book and we to show you how you can install your Guest OS.
+
* b - blocked
  
We choice Window 7 Enterprise for install as Guest and show you that how you can configure your Xen to use this “.iso” file and start your VM.
+
The domain is blocked, and not running or runnable. This happened when the domain is waiting on IO or going to sleep because there was nothing else for it to do.
  
First of all, We must create a config file for our VM. Let me to create it via “touch” command in Linux :
+
* p - paused
  
<nowiki># touch /etc/xen/windows.cfg</nowiki>
+
The domain has been paused, and may administrator paused it via “xl pause” command. When a VM paused, The domain will still consume allocated resources like memory, but will not be eligible for scheduling by the Xen hypervisor.
  
 +
* s - shutdown
  
Then, I open it via an editor like “nano” as below :
+
The guest has requested to be shutdown, rebooted or suspended.
  
 +
* c - crashed
  
<nowiki># nano /etc/xen/windows.cfg</nowiki>
+
The domain has crashed. It may if the domain has been configured not to restart on crash.
  
 +
* d - dying
  
And fill this file via below information :
+
The domain is in process of dying, but hasn't completely shutdown or crashed.
  
 +
In below example, my “OpenSUSE” VM is running and established :
  
name = "Windows7"
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xl list
  
builder = "hvm"
+
Name ID Mem VCPUsStateTime(s)
  
vcpus = 4
+
Domain-0 0 1590 8 r----- 1245.3
  
memory = "4096"
+
OpenSUSE 44 2048 2 -b---- 127.4
 +
</syntaxhighlight>
  
maxmex= "8192"
+
Then, I run below command for “Pause” it :
  
vif=['bridge=br0']
+
<syntaxhighlight lang="sh"># xl pause OpenSUSE</syntaxhighlight>
  
disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r']
+
and my current state is:
  
vnc="1"
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xl list
  
vnclisten="172.30.9.20"
+
Name ID Mem VCPUsStateTime(s)
  
vncconsole="0"
+
Domain-0 0 1590 8 r----- 1248.0
  
boot="dc"
+
OpenSUSE 44 2048 2 --p--- 127.5
 +
</syntaxhighlight>
  
stdvga=1
+
For “unpause” a VM you can use below command :
  
videoram=32
+
<syntaxhighlight lang="sh"># xl unpause OpenSUSE
  
on_poweroff = "destroy"
+
[root@localhost ~]# xl list
  
on_reboot = "restart"
+
Name ID Mem VCPUsStateTime(s)
  
on_crash = "restart"
+
Domain-0 0 1590 8 r----- 1257.0
  
 +
OpenSUSE 44 2048 2 -b---- 128.3
 +
</syntaxhighlight>
  
I must tell you something about this file :
+
Add USB Devices to your VM
  
●vif=['bridge=br0'] : Because of we choice “br0” as a name of our Bridge then we must write “'bridge=br0'” ,But if your Bridge name is different then you must write your Bridge name instead of it here.
+
Sometime you may want to add a USB device to your VM. Linux has a command with the name “lsudb” that show your USB controllers on your Server :
  
●disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r'] : If you remember, We want to use our real partition as our Guest partition, Thus it is not a File that act as a real HDD. Because of it, We used “phy” that mean Physical. The “Xen” is our LVM and I choice “Fedora” as a name of my 20 GB partition on LVM. You may selected other name that you must put it here.
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lsusb
  
●Vnclisten="172.30.9.20" : Because I use the Xen Project on other server and not on my current PC, I must define the IP address of my Xen Server. My Xen Server IP is “172.30.9.20” and if your situation is like us then you must write your Xen Server IP here but if you run the Xen Project on your PC and not another PC or Server then you must write “vnclisten="0.0.0.0"”. When you select “0.0.0.0” as IP then it is your local host.
+
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  
●boot="dc" : the “d” mean “CDROM” and “c” mean your HDD. It is your Boot order and when you Guest installed you can change it to “boot=”c””. The Xen Project parameters are boot on floppy (a), hard disk (c), Network (n) and CD-ROM (d).
+
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
 +
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
 +
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
 +
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
Let us start our Guest. Just type below command :
+
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
<nowiki># xl create /etc/xen/windows.cfg</nowiki>
+
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
  
and if you have not any error in your syntax then your xen just show “Parsing config from /etc/xen/windows.cfg” and your VM started.
+
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  
After it write below command :
+
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
</syntaxhighlight>
  
<nowiki># xl list</nowiki>
+
As you see, My Server has USB 2.0 and USB 3,0 controllers. I plugged a HP Pendrive to my server and run command again :
  
and you can see something like below :
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lsusb
  
Name ID Mem VCPUsStateTime(s)
+
Bus 002 Device 003: ID 03f0:5607 Hewlett-Packard
  
Domain-0 0 3659 8 r----- 887.6
+
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  
Windows7 19 4096 4 -b---- 23.1
+
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
 +
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
As you see, “Windows7” is running and we just need connect to it via “vncviewer”. But you must did something on your Firewall.
+
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
Linux use “iptables” as Firewall and VNC Port is not opened by default and we must open this port for connect to our VNC remotely. Don't forget, We doing it because our Xen server is on another PC and we must connect to it remotely thus we need open VNC Port. The VNC use Port 5900 and TCP protocol.
+
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
I use “netstat -nat” command for show our current network connections :
+
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
 +
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
  
<nowiki># netstat -nat</nowiki>
+
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  
Active Internet connections (servers and established)
+
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
</syntaxhighlight>
  
Proto Recv-Q Send-Q Local Address Foreign Address State
+
What happened? As you see, “Hewlett-Packard “ added to my list. If you look at the output more then you see some numbers behind the device name. What are these? These are vendor and product numbers are in “[vendor]:[product]” form.
  
tcp 0 0 172.30.9.20:5900 0.0.0.0:* LISTEN
+
For example, My Pendrive from HP company has “03f0:5607” and If you navigate to the “http://www.linux-usb.org/usb.ids” and search “ 03f0” then you can see that it is a vendor number for HP company.
  
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
+
A good web site for search and find the devices models is “http://www.the-sz.com/products/usbid/”. You can browse it and enter the device “vendor” and “product” numbers and click on search then you can see the model of your device :
  
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
+
[[Image:Figure_32-_USB_ID_Database.png|top|600px|none|thumb|Figure 32 : USB ID Database.]]
  
tcp 0 0 172.30.9.20:22 172.30.10.18:49824 ESTABLISHED
 
  
tcp6 0 0 :::9090 :::* LISTEN
+
OK, We want add out Pendrive to our VM and copy and paste some files from/to it from our VM.
  
tcp6 0 0 :::22 :::* LISTEN
+
Fist of all, You must open your VM cofing file via an editor like “nano” :
  
 +
<syntaxhighlight lang="sh"># nano /etc/xen/linux.cg</syntaxhighlight>
  
As you see, The IP “172.30.9.20” and Port “5900” are ready for connect but we must doing some steps for connect to our VM :
+
Then add below lines to your config file :
  
1- First of all, Install a tool like “vncviewer” on your Linux Distro.
+
<syntaxhighlight lang="sh">
 +
usb="1"
  
2- Depend on your Linux Distro (Dom0) you must use “iptables” for open VNC Port on Dom0 :
+
usbdevice=['host:03f0:5607']
 +
</syntaxhighlight>
  
<nowiki># iptables -A INPUT -p tcp --dport 5900 -j ACCEPT</nowiki>
+
The “usb=”1”” cause enable USB controller and via “usbdevice” you can select your USB device for appear in VM. As you see, My HP Pendrive “vendor” and “product” numbers are “03f0:5607” and I written “usbdevice=['host:03f0:5607']” to my config file.
  
<nowiki># iptables-save</nowiki>
+
After it, When I start my VM then I can see my Pendrive that mounted in my VM. In below Figure, You can see that my HP Pendrive mounted in OpenSUSE Linux :
  
After it, The Port “5900” is open on your Dom0 and you can connect to it remotely. You can use “iptables -L” for show your current iptables rules.
+
[[Image:Figure_33-_USB_Mounted.png|top|600px|none|thumb|Figure 33: USB Mounted.]]
  
We ready ready to connect to our Xen Server :
+
== {{anchor|Toc476606918}} Use Physical CD/DVD ROM ==
  
<nowiki># vncviewer 172.30.9.20:5900</nowiki>
+
It is True that installing OS from ISO files is more faster and better but sometime for some problems you can't use the .ISO file for install OS. For example, Your Dom0 not have enough space or you have CD or DVD of your OS. The Xen Project let you to use your Physical CD/DVD ROM for install OS.
  
And after it, A window displayed and we can do Windows install process:
+
Linux detect all devices as file, Thus your CD/DVD ROM is a file too. You can run “lsblk” command to find your CD/DVD ROM device :
  
[[Image:Figure_30-_Windows_7_on_Xen.png|top|600px|none|thumb]]
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lsblk
  
===== <span style="color:#00000a;">Figure 30 : Windows 7 on Xen.=====
+
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  
 +
sda 8:0 0 931.5G 0 disk
  
Sometimes you don't like your VM viewed by others and you want set password for it, For do it use below parameter in your VM config file :
+
├─sda1 8:1 0 316G 0 part
  
vncpasswd=”Your Password”
+
│ ├─fedora-root00 253:0 0 300G 0 lvm /
  
After it, When you want view your VM via VNC you must enter a password :
+
│ └─fedora-swap 253:1 0 16G 0 lvm [SWAP]
  
vncviewer 172.30.9.20:5900
+
└─sda2 8:2 0 615.5G 0 part
  
Connected to RFB server, using protocol version 3.8
+
├─Xen-Fedora 253:2 0 20G 0 lvm
  
Performing standard VNC authentication
+
└─Xen-linux 253:3 0 20G 0 lvm
  
Password:
+
sdb 8:16 1 15.1G 0 disk
  
 +
sr0 11:0 1 158.5M 0 rom
 +
</syntaxhighlight>
  
When you working with Your VM, You may have some problems with your Display and you must consider below Links for Troubleshooting your problems :
+
As you see, Linux detected my DVD ROM as “sr0”, Thus my DVD is “/dev/sr0” and I can use it. If I want my VM boot via Physical CD/DVD ROM then I just add below line to my VM config :
  
[http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_do_I_change_the_resolution_of_Xen_PV_domU_vfb_graphical_VNC_console.3F http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_do_I_change_the_resolution_of_Xen_PV_domU_vfb_graphical_VNC_console.3F]
+
<syntaxhighlight lang="sh">
 +
disk=['phy:/dev/sr0,hdc:cdrom,r']
 +
</syntaxhighlight>
  
[http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_can_I_get_resolutions_larger_than_800x600_for_Xen_HVM_guest_graphical_VNC_console.3F http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_can_I_get_resolutions_larger_than_800x600_for_Xen_HVM_guest_graphical_VNC_console.3F]
+
If you remember, Int he previous config we used “disk=['file:/home/mohsen/opensuse.iso,hdc:cdrom,r']” and “file” was for .ISO file but for Physical devices we use “Phy” instead of “file”. After it, My VM booted via Physical DVD ROM.
  
A good note that you must consider it is that you should install “Windows PV Drivers” for your Xen VM. Navigate to “http://www.xenproject.org/downloads/windows-pv-drivers.html” and download .TAR files and extract them, then configure your NIC IP address and see your network and copy these files and install them on your Windows Guest. In below figure you can see that I choice a static IP for my Windows Guest :
+
If DVD Drive not detected automatically then use below command :
  
 +
<syntaxhighlight lang="sh"># eject</syntaxhighlight>
  
[[Image:|top]]
+
This command eject DVD from the Guest and if you change CD or DVD then for detect the insertion use below command :
  
<div style="text-align:center;">Figure 31: Static IP</div>
+
<syntaxhighlight lang="sh"># eject -t</syntaxhighlight>
  
 +
== {{anchor|Toc476606919}} Create a VM via .img ==
  
When you create another VM:
+
We showed you how you can create a VM via “LVM” but sometime for some reasons you don't like to create a LVM and like to boot your VM via an image. We will show you it. It is so easy and just need some steps.
  
[root@localhost ~]# netstat -nat
+
First of all, Please let me to create a directory via “mkdir” for our Virtual HDD :
  
Active Internet connections (servers and established)
+
<syntaxhighlight lang="sh"># mkdir Windows</syntaxhighlight>
  
Proto Recv-Q Send-Q Local Address Foreign Address State
+
change to “Windows” directory via “cd” command :
  
tcp 0 0 172.30.9.20:5900  0.0.0.0:* LISTEN
+
<syntaxhighlight lang="sh"># cd Windows/</syntaxhighlight>
  
tcp 0 0 172.30.9.20:5901 0.0.0.0:* LISTEN
+
And run below command for create a Virtual HDD about 40GB :
  
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
+
<syntaxhighlight lang="sh"># dd if=/dev/zero of=windows.img bs=1M count=40000</syntaxhighlight>
  
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
+
<syntaxhighlight lang="sh">
 +
[root@localhost Windows]# dd if=/dev/zero of=windows.img bs=1M count=40000
  
tcp 0 0 172.30.9.20:5900 172.30.10.18:33869 ESTABLISHED
+
40000+0 records in
  
tcp 0 0 172.30.9.20:22 172.30.10.18:55000 ESTABLISHED
+
40000+0 records out
  
tcp 0 180 172.30.9.20:22 172.30.10.18:54616 ESTABLISHED
+
41943040000 bytes (42 GB) copied, 332.735 s, 126 MB/s
 +
</syntaxhighlight>
  
tcp6 0 0 :::9090 :::* LISTEN
+
If you list files and directory via “ls” command then you will see something like below :
  
tcp6 0 0 :::22 :::* LISTEN
+
<syntaxhighlight lang="sh">
 +
[root@localhost Windows]# ls
  
 +
windows.img
 +
</syntaxhighlight>
  
[root@localhost ~]# xl list
+
As you see, A file with the name “windows.img” created for us. Now, We must change VM config file for use this file as Virtual HDD.
  
Name ID Mem VCPUsStateTime(s)
+
Open your VM config file via an editor like “Nano” and add below line as your HDD :
  
Domain-0 0 1590 8 r----- 192.7
+
<syntaxhighlight lang="sh">
 +
disk=['file:/home/mohsen/Windows/windows.img,hda,w']
 +
</syntaxhighlight>
  
Windows7 9 4096 4 -b---- 21.0
+
As you see, We used “file” instead of “phy”.
  
linux 10 2048 1 r----- 64.8
+
You must note that if you install Windows 10 and see below error the don't worry, It is because of your Windows date and you must use updated .ISO file :
  
 +
[[Image:Figure_34-_Windows_10_Error..png|top|600px|none|thumb|Figure 34 : Windows 10 Error.]]
  
If you pay attention to the output of “ifconfig” command then you will see a default Bridge with the name “virbr0”. We can use this Bridge for add other NIC to our VM. For example, We need more than one NIC on our VM.
+
== {{anchor|Toc476606920}} VGA Passthrough ==
  
For adding more than one NIC you can use :
+
A good feature and trick in Virtualization is VGA Passthrough. I don't know why someone need it but they have their reason for it. For example, Someone need run Graphical application under Vms and these application need a real VGA and can't work with a standard VGA Or some people like to Play Games :)
  
vif=['bridge=br0','mac=00:16:17:a5:6y:89,bridge=virbr0']
+
The Xen Project offer you this feature and you can use your real VGA in your VM but with some limitation. For example, Your CPU must support IOMMU.
  
 +
Xen 4.0.0 is the first version Xen that support VGA graphics adapter passthrough. With this feature you can give the Guest Full control of graphic adapter and have Full 3D support in a VM. For enable this feature, Xen need IOMMU (Intel VT-d) support from the motherboard chipset. VT-d Pass-Through is a technique in Xen that give DomU this ability to access PCI using the IOMMU. An important note that you must consider is that “Only devices with FLR capabilities are supported” and otherwise you will see an Error. To check your PCI device for FLR feature you can run “lspci -w” on Dom0 and if in the output you see “FLReset-” then your device not supported and if you see “FLReset+” then it is OK.
  
The “mac” defined the MAC address for our NIC.
+
We use Fedora and “-w” parameter not exist and thus we must use below commands :
  
We can use our first Bridge(br0) for adding more than NIC too but we should add a MAC address fpr each NIC :
+
First of all, Run below command to see a list of Hardware :
  
vif=['bridge=br0,mac=00:13:r6:45:g6:9o','mac=00:16:17:a5:6y:89,bridge=br0']
+
<syntaxhighlight lang="sh"># lspci</syntaxhighlight>
  
 +
Then run :
  
In above example, We used the Bridge br0 for adding two NICs but we can't create another Bridge(br1) and attach it other Physical NIC and use it here.
+
<syntaxhighlight lang="sh"># lspci -vv -s PCI ID | grep FLR</syntaxhighlight>
  
 +
For example :
  
'''''Share storage between VMS'''''
+
<syntaxhighlight lang="sh"># lspci -vv -s 00:02.0 | grep FLR</syntaxhighlight>
  
In some situation, You may want to use another HDD or other Vms HDD in a VM. It is so easy and you can write the name of your other HDD in “disk” in the config file :
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lspci -vv -s 00:02.0 | grep FLR
  
disk=['phy:/dev/Xen/Fedora,hda,w','phy:/dev/Xen/linux,hdb,w','file:/home/mohsen/Windows7.iso,hdc:cdrom,r']
+
AFCap: TP+ FLR+
  
 +
AFCtrl: FLR-
 +
</syntaxhighlight>
  
In above example, my main HDD is “Fedora” and I mount another HDD (linux) as “hdb”. When I fire my “vm” then I can see other HDD in my vm. If you noted, Then you can see “w” and “r” word at the end of my lines. What are these? The “w” mean “read-write” and “r” mean “read-only”.
+
OK, We consider that your device support FLR and I will tell you that how you can attach it.
  
 +
First of all, Execute below command :
  
== {{anchor|Toc476606917}} <span style="color:#00000a;">VM States in The Xen Project</span> ==
+
<syntaxhighlight lang="sh"># modprobe xen-pciback</syntaxhighlight>
  
When you run a VM through Xen and run “xl list” then you can see a column with the name “State” and a word that changed sometimes. What does this word mean?
+
Create a file via “touch” command and fill it with below information :
  
For example, I run “xl list” and the output is as below :
+
<syntaxhighlight lang="sh">
 +
remove_device () {
  
[root@localhost ~]# xl list
+
BDF=$1
  
Name ID Mem VCPUsStateTime(s)
+
# Unbind a PCI function from its driver as necessary
  
Domain-0 0 1590 8 r----- 1211.3
+
[ ! -e /sys/bus/pci/devices/$BDF/driver/unbind ] || \
  
OpenSUSE 44 2048 1 r----- 4.6
+
echo -n $BDF > /sys/bus/pci/devices/$BDF/driver/unbind
  
 +
# Add a new slot to the PCI Backend's list
  
I will tel you something about these words :
+
echo -n $BDF > /sys/bus/pci/drivers/pciback/new_slot
  
●r - running
+
# Now that the backend is watching for the slot, bind to it
  
The domain is currently running.
+
echo -n $BDF > /sys/bus/pci/drivers/pciback/bind
  
●b - blocked
+
}
  
The domain is blocked, and not running or runnable. This happened when the domain is waiting on IO or going to sleep because there was nothing else for it to do.
+
remove_device "Your PCI ID"
 +
# For example : remove_device "0000:01:00.1"
  
●p - paused
+
</syntaxhighlight>
  
The domain has been paused, and may administrator paused it via “xl pause” command. When a VM paused, The domain will still consume allocated resources like memory, but will not be eligible for scheduling by the Xen hypervisor.
+
Save the file and run this script via “sh yourfilename”.
  
●s - shutdown
+
After it, You must edit your VM config file. Open you config file via an editor like “Nano” :
  
The guest has requested to be shutdown, rebooted or suspended.
+
<syntaxhighlight lang="sh"># nano /etc/xen/windows.cfg</syntaxhighlight>
  
●c - crashed
+
Then add below line to your config file :
  
The domain has crashed. It may if the domain has been configured not to restart on crash.
+
pci=['Your PCI ID','Your PCI ID']
  
●d - dying
+
<syntaxhighlight lang="sh"># For example : pci=['01:00.1','00:1a.0']</syntaxhighlight>
  
The domain is in process of dying, but hasn't completely shutdown or crashed.
 
  
 +
Then run your VM and your PCI device will attached to your VM.
  
In below example, my “OpenSUSE” VM is running and established :
+
== {{anchor|Toc476606921}} Swap ==
  
[root@localhost ~]# xl list
+
Before we speak about Swap in Linux, Let me to tell something about “Paging”. The Paging is a scheme of memory management that your system use it for store and retrieves data from it. Why its named paging? It is because the OS retrieves data from a secondary storage in specific size that called pages. It is an important part of Virtual memory that implemented in modern OS and let you to run Applications that are larger than your Physical memory.
  
Name ID Mem VCPUsStateTime(s)
+
What is the Swap? Swap space usually is a disk partition but can be a file too. When you installing Linux, you can define a partition as Swap space but it can be done later too. The Swap space is recommended for users that have less than 1 GB of RAM. It is a area on your HDD which is part of your Virtual Memory. The Swap space used when your system sense that need more Physical memory for active processes and after it, Inactive pages on your Physical memory moving the Swap space and your Physical memory freed and have more free space for others. You must note that The Swap space exist on your HDD and the speed of HDDs are slower then Physical memory. It is true that HDD with new technologies like SSD has more speed but don't consider the Swap space as a replacement for the Physical memory. For define a Swap space you must define it twice of Physical memory. For example, If you have 4GB RAM then your Swap should be 8GB.
  
Domain-0 0 1590 8 r----- 1245.3
+
For check the Swap space of your system use below command :
  
OpenSUSE 44 2048 2 -b---- 127.4
 
  
 +
<syntaxhighlight lang="sh"># swapon --show</syntaxhighlight>
  
Then, I run below command for “Pause” it :
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# swapon --show
  
<nowiki># xl pause OpenSUSE</nowiki>
+
NAME TYPE SIZE USED PRIO
  
and my current state is:
+
/dev/dm-1 partition 16G 0B -1
  
[root@localhost ~]# xl list
+
[root@localhost ~]#
 +
</syntaxhighlight>
  
Name ID Mem VCPUsStateTime(s)
+
As you see, My system has 16GB Swap space.
  
Domain-0 0 1590 8 r----- 1248.0
+
You can use “free -h” command too :
  
OpenSUSE 44 2048 2 --p--- 127.5
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# free -h
  
 +
total used free shared buff/cache available
  
For “unpause” a VM you can use below command :
+
Mem: 7.5G 186M 7.0G 4.4M 325M 7.2G
  
<nowiki># xl unpause OpenSUSE</nowiki>
+
Swap: 15G 0B 15G
  
[root@localhost ~]# xl list
+
[root@localhost ~]#
 +
</syntaxhighlight>
  
Name ID Mem VCPUsStateTime(s)
+
If you install the Linux as your VM then you may like to define an extended Swap space for it. It is true that you can use your Virtual HDD as a Swap space but you can define another HDD as Swap too.
  
Domain-0 0 1590 8 r----- 1257.0
+
First of all, We use “dd” command for create an image :
  
OpenSUSE 44 2048 2 -b---- 128.3
+
<syntaxhighlight lang="sh"># dd if=/dev/zero of=linuxswap.swap bs=1024 count=”Your size”</syntaxhighlight>
  
 +
For example :
  
Add USB Devices to your VM
+
<syntaxhighlight lang="sh">
 +
[root@localhost mohsen]# dd if=/dev/zero of=linuxswap.swap bs=1024 count=4096000
  
Sometime you may want to add a USB device to your VM. Linux has a command with the name “lsudb” that show your USB controllers on your Server :
+
4096000+0 records in
  
[root@localhost ~]# lsusb
+
4096000+0 records out
  
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
+
4194304000 bytes (4.2 GB) copied, 32.8729 s, 128 MB/s
 +
</syntaxhighlight>
  
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
Then :
  
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
<syntaxhighlight lang="sh">
 +
[root@localhost mohsen]# mkswap linuxswap.swap
  
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
mkswap: linuxswap.swap: insecure permissions 0644, 0600 suggested.
  
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
Setting up swapspace version 1, size = 3.9 GiB (4194299904 bytes)
  
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
no label, UUID=f2464b51-c7ef-4990-8cb6-8d50d151b52e
 +
</syntaxhighlight>
  
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
+
Now, It is a good time for attach our Swap space to our VM. Open your VM config file via an editor like “nano” and add below line to your VM config file :
  
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
+
<syntaxhighlight lang="sh">
 +
file:/YourPath/linuxswap.swap,hdb,w
 +
</syntaxhighlight>
  
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
The complete line is something like :
  
 +
<syntaxhighlight lang="sh">
 +
disk=['phy:/dev/Xen/linux,hda,w','file:/home/mohsen/linuxswap.swap,hdb,w']
 +
</syntaxhighlight>
  
As you see, My Server has USB 2.0 and USB 3,0 controllers. I plugged a HP Pendrive to my server and run command again :
+
Now, Start your VM and when your VM is booted then your Swap space is “hdb” and your just need to enable it. You can use below command to enable your Swap in your VM :
  
[root@localhost ~]# lsusb
+
<syntaxhighlight lang="sh"># swapon /dev/hdb</syntaxhighlight>
  
Bus 002 Device 003: ID 03f0:5607 Hewlett-Packard
+
[[Image:Figure_35-_Swap_Space.png|top|600px|none|thumb|Figure 35 : Swap Space.]]
  
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
 
  
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
As you see, My Linux had 2GB of Swap and after it my Linux VM has 5.9GB Swap Space.
  
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
For mount it automatically via boot just doing following steps :
  
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
1- Open “fstab” file from “/etc/fstab” via an editor like “nano”.
  
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
2- add below line :
  
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
/dev/XXX none swap defaults 0 0
  
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
+
<syntaxhighlight lang="sh"># For example : /dev/hdb none swap defaults 0 0</syntaxhighlight>
  
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
 
  
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
3- Save file and reboot your system.
  
  
What happened? As you see, “Hewlett-Packard “ added to my list. If you look at the output more then you see some numbers behind the device name. What are these? These are vendor and product numbers are in “[vendor]:[product]” form.
+
== {{anchor|Toc476606922}} Using Xen-Tools ==
  
For example, My Pendrive from HP company has “03f0:5607” and If you navigate to the “http://www.linux-usb.org/usb.ids” and search “ 03f0” then you can see that it is a vendor number for HP company.
+
What is Xen-Tools? It is a collection of Perl Scripts that allow you to create a new guest Xen domain. It is compatible with Debian more but nowadays can support Ubuntu, CentOS and others. OK, Let start!
  
A good web site for search and find the devices models is “http://www.the-sz.com/products/usbid/”. You can browse it and enter the device “vendor” and “product” numbers and click on search then you can see the model of your device :
+
Go to “http://xen-tools.org/” and download the Xen-Tools. After it, For install “Xen-Tools” we must install some packages on CentOS. Run following command :
  
<div style="text-align:center;">[[Image:|top]]</div>
+
<syntaxhighlight lang="sh"># yum install debootstrap perl-Text-Template perl-Config-IniFiles perl-File-Slurp perl-File-Which perl-Data-Dumper</syntaxhighlight>
  
<div style="text-align:center;margin-left:1in;margin-right:0in;">Figure 32: USB ID Database</div>
+
After it go to the location that downloaded file is there and use “gunzip” and “tar” command for extract it. Then use “cd” command for change the current location and when you are in “Xen-Tools” directory run “make install” command. You will see something like below :
  
 +
<syntaxhighlight lang="sh">
 +
[root@localhost xen-tools-4.6.2]# make install
  
OK, We want add out Pendrive to our VM and copy and paste some files from/to it from our VM.
+
for i in hooks/*/*-*; do chmod 755 $i; done
  
Fist of all, You must open your VM cofing file via an editor like “nano” :
+
chmod 755 hooks/common.sh
  
<nowiki># nano /etc/xen/linux.cg</nowiki>
+
chmod 644 etc/*.conf
  
Then add below lines to your config file :
+
chmod 644 etc/xm.tmpl
  
usb="1"
+
chmod 644 etc/xm-nfs.tmpl
  
usbdevice=['host:03f0:5607']
+
chmod 644 misc/*
  
 +
mkdir -p /usr/bin
  
The “usb=”1”” cause enable USB controller and via “usbdevice” you can select your USB device for appear in VM. As you see, My HP Pendrive “vendor” and “product” numbers are “03f0:5607” and I written “usbdevice=['host:03f0:5607']” to my config file.
+
cp bin/xen-create-image /usr/bin
  
After it, When I start my VM then I can see my Pendrive that mounted in my VM. In below Figure, You can see that my HP Pendrive mounted in OpenSUSE Linux :
+
cp bin/xen-create-nfs /usr/bin
  
 +
cp bin/xt-customize-image /usr/bin
  
<div style="text-align:center;">[[Image:|top]]</div>
+
cp bin/xt-install-image /usr/bin
  
<div style="text-align:center;">Figure 33: USB Mounted</div>
+
cp bin/xt-create-xen-config /usr/bin
  
 +
cp bin/xen-delete-image /usr/bin
  
 +
cp bin/xen-list-images /usr/bin
  
 +
cp bin/xen-update-image /usr/bin
  
== {{anchor|Toc476606918}} <span style="color:#00000a;">Use Physical CD/DVD ROM</span> ==
+
cp bin/xt-guess-suite-and-mirror /usr/bin
  
It is True that installing OS from ISO files is more faster and better but sometime for some problems you can't use the .ISO file for install OS. For example, Your Dom0 not have enough space or you have CD or DVD of your OS. The Xen Project let you to use your Physical CD/DVD ROM for install OS.
+
chmod 755 /usr/bin/xen-create-image
  
Linux detect all devices as file, Thus your CD/DVD ROM is a file too. You can run “lsblk” command to find your CD/DVD ROM device :
+
chmod 755 /usr/bin/xen-create-nfs
  
[root@localhost ~]# lsblk
+
chmod 755 /usr/bin/xt-customize-image
  
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
+
chmod 755 /usr/bin/xt-install-image
  
sda 8:0 0 931.5G 0 disk
+
chmod 755 /usr/bin/xt-create-xen-config
  
├─sda1 8:1 0 316G 0 part
+
chmod 755 /usr/bin/xen-delete-image
  
│ ├─fedora-root00 253:0 0 300G 0 lvm /
+
chmod 755 /usr/bin/xen-list-images
  
│ └─fedora-swap 253:1 0 16G 0 lvm [SWAP]
+
chmod 755 /usr/bin/xen-update-image
  
└─sda2 8:2 0 615.5G 0 part
+
chmod 755 /usr/bin/xt-guess-suite-and-mirror
  
├─Xen-Fedora 253:2 0 20G 0 lvm
+
mkdir -p /etc/xen-tools
  
└─Xen-linux 253:3 0 20G 0 lvm
+
if [ -d /etc/xen-tools/hook.d ]; then mv /etc/xen-tools/hook.d/ /etc/xen-tools/hook.d.obsolete ; fi
  
sdb 8:16 1 15.1G 0 disk
+
mkdir -p /etc/xen-tools/skel/
  
sr0 11:0 1 158.5M 0 rom
+
mkdir -p /etc/xen-tools/role.d/
  
 +
mkdir -p /etc/xen-tools/partitions.d/
  
As you see, Linux detected my DVD ROM as “sr0”, Thus my DVD is “/dev/sr0” and I can use it. If I want my VM boot via Physical CD/DVD ROM then I just add below line to my VM config :
+
cp etc/*.conf /etc/xen-tools/
  
disk=['phy:/dev/sr0,hdc:cdrom,r']
+
cp etc/xm.tmpl /etc/xen-tools/
  
 +
cp etc/xm-nfs.tmpl /etc/xen-tools/
  
If you remember, Int he previous config we used “disk=['file:/home/mohsen/opensuse.iso,hdc:cdrom,r']” and “file” was for .ISO file but for Physical devices we use “Phy” instead of “file”. After it, My VM booted via Physical DVD ROM.
+
cp partitions/*-* /etc/xen-tools/partitions.d/
  
If DVD Drive not detected automatically then use below command :
+
mkdir -p /usr/share/bash-completion/completions/
  
<nowiki># eject</nowiki>
+
cp misc/xen-tools.bash-completion /usr/share/bash-completion/completions/xen-tools
  
This command eject DVD from the Guest and if you change CD or DVD then for detect the insertion use below command :
+
mkdir -p /etc/initramfs-tools/conf.d/
  
<nowiki># eject -t</nowiki>
+
cp misc/xen-tools.initramfs-tools /etc/initramfs-tools/conf.d/xen-tools
  
 +
for i in roles/* ; do if [ -f $i ]; then cp $i /etc/xen-tools/role.d; fi ; done
  
 +
for i in /usr/share/xen-tools/*.d; do if [ -L "$i" ]; then rm -vf "$i"; fi; done
  
 +
mkdir -p /usr/share/xen-tools/centos-4.d/
  
=== {{anchor|Toc476606919}} <span style="color:#00000a;">Create a VM via .img</span> ===
+
mkdir -p /usr/share/xen-tools/centos-5.d/
  
We showed you how you can create a VM via “LVM” but sometime for some reasons you don't like to create a LVM and like to boot your VM via an image. We will show you it. It is so easy and just need some steps.
+
mkdir -p /usr/share/xen-tools/centos-6.d/
  
First of all, Please let me to create a directory via “mkdir” for our Virtual HDD :
+
mkdir -p /usr/share/xen-tools/fedora-core-6.d/
  
<nowiki># mkdir Windows</nowiki>
+
cp -R hooks/centos-4/*-* /usr/share/xen-tools/centos-4.d
  
change to “Windows” directory via “cd” command :
+
cp -R hooks/centos-5/*-* /usr/share/xen-tools/centos-5.d
  
<nowiki># cd Windows/</nowiki>
+
cp -R hooks/centos-6/*-* /usr/share/xen-tools/centos-6.d
  
And run below command for create a Virtual HDD about 40GB :
+
cp -R hooks/fedora-core-6/*-* /usr/share/xen-tools/fedora-core-6.d
  
<nowiki># dd if=/dev/zero of=windows.img bs=1M count=40000</nowiki>
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-4.d
  
[root@localhost Windows]# dd if=/dev/zero of=windows.img bs=1M count=40000
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-5.d
  
40000+0 records in
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-7.d
  
40000+0 records out
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-8.d
  
41943040000 bytes (42 GB) copied, 332.735 s, 126 MB/s
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-9.d
  
 +
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-10.d
  
If you list files and directory via “ls” command then you will see something like below :
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-11.d
  
[root@localhost Windows]# ls
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-12.d
  
windows.img
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-13.d
  
 +
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-14.d
  
As you see, A file with the name “windows.img” created for us. Now, We must change VM config file for use this file as Virtual HDD.
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-15.d
  
Open your VM config file via an editor like “Nano” and add below line as your HDD :
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-16.d
  
disk=['file:/home/mohsen/Windows/windows.img,hda,w']
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-17.d
  
As you see, We used “file” instead of “phy”.
+
mkdir -p /usr/share/xen-tools/debian.d/
  
 +
cp -R hooks/debian/*-* /usr/share/xen-tools/debian.d
  
You must note that if you install Windows 10 and see below error the don't worry, It is because of your Windows date and you must use updated .ISO file :
+
cd /usr/share/xen-tools/ && ln -s debian.d sarge.d
  
<div style="text-align:center;">[[Image:|top]]</div>
+
cd /usr/share/xen-tools/ && ln -s debian.d etch.d
  
<div style="text-align:center;">Figure 34: Windows 10 Error.</div>
+
cd /usr/share/xen-tools/ && ln -s debian.d lenny.d
  
 +
cd /usr/share/xen-tools/ && ln -s debian.d squeeze.d
  
 +
cd /usr/share/xen-tools/ && ln -s debian.d wheezy.d
  
 +
cd /usr/share/xen-tools/ && ln -s debian.d jessie.d
  
=== {{anchor|Toc476606920}} <span style="color:#00000a;">VGA Passthrough</span> ===
+
cd /usr/share/xen-tools/ && ln -s debian.d stretch.d
  
A good feature and trick in Virtualization is VGA Passthrough. I don't know why someone need it but they have their reason for it. For example, Someone need run Graphical application under Vms and these application need a real VGA and can't work with a standard VGA Or some people like to Play Games :)
+
cd /usr/share/xen-tools/ && ln -s debian.d sid.d
  
The Xen Project offer you this feature and you can use your real VGA in your VM but with some limitation. For example, Your CPU must support IOMMU.
+
cd /usr/share/xen-tools/ && ln -s debian.d unstable.d
  
Xen 4.0.0 is the first version Xen that support VGA graphics adapter passthrough. With this feature you can give the Guest Full control of graphic adapter and have Full 3D support in a VM. For enable this feature, Xen need IOMMU (Intel VT-d) support from the motherboard chipset. VT-d Pass-Through is a technique in Xen that give DomU this ability to access PCI using the IOMMU. An important note that you must consider is that “Only devices with FLR capabilities are supported” and otherwise you will see an Error. To check your PCI device for FLR feature you can run “lspci -w” on Dom0 and if in the output you see “FLReset-” then your device not supported and if you see “FLReset+” then it is OK.
+
cd /usr/share/xen-tools/ && ln -s debian.d testing.d
  
We use Fedora and “-w” parameter not exist and thus we must use below commands :
+
cd /usr/share/xen-tools/ && ln -s debian.d stable.d
  
First of all, Run below command to see a list of Hardware :
+
cd /usr/share/xen-tools/ && ln -s debian.d oldstable.d
  
 +
cd /usr/share/xen-tools/ && ln -s debian.d oldoldstable.d
  
<nowiki># lspci</nowiki>
+
mkdir -p /usr/share/xen-tools/gentoo.d/
  
Then run :
+
cp -R hooks/gentoo/*-* /usr/share/xen-tools/gentoo.d
  
<nowiki># lspci -vv -s PCI ID | grep FLR</nowiki>
+
mkdir -p /usr/share/xen-tools/dapper.d/
  
For example :
+
cp -R hooks/dapper/*-* /usr/share/xen-tools/dapper.d/
  
<nowiki># lspci -vv -s 00:02.0 | grep FLR</nowiki>
+
mkdir -p /usr/share/xen-tools/edgy.d/
  
[root@localhost ~]# lspci -vv -s 00:02.0 | grep FLR
+
cp -R hooks/edgy/*-* /usr/share/xen-tools/edgy.d/
  
AFCap: TP+ FLR+
+
cd /usr/share/xen-tools/ && ln -s edgy.d feisty.d
  
AFCtrl: FLR-
+
cd /usr/share/xen-tools/ && ln -s edgy.d gutsy.d
  
 +
cd /usr/share/xen-tools/ && ln -s edgy.d hardy.d
  
OK, We consider that your device support FLR and I will tell you that how you can attach it.
+
mkdir -p /usr/share/xen-tools/intrepid.d/
  
First of all, Execute below command :
+
cp -R hooks/intrepid/*-* /usr/share/xen-tools/intrepid.d/
  
<nowiki># modprobe xen-pciback</nowiki>
+
cd /usr/share/xen-tools/ && ln -s intrepid.d jaunty.d
  
Create a file via “touch” command and fill it with below information :
+
mkdir -p /usr/share/xen-tools/karmic.d/
  
remove_device () {
+
cp -R hooks/karmic/*-* /usr/share/xen-tools/karmic.d/
  
BDF=$1
+
cd /usr/share/xen-tools/ && ln -s karmic.d lucid.d
  
<nowiki># Unbind a PCI function from its driver as necessary</nowiki>
+
cd /usr/share/xen-tools/ && ln -s karmic.d maverick.d
  
[ ! -e /sys/bus/pci/devices/$BDF/driver/unbind ] || \
+
cd /usr/share/xen-tools/ && ln -s karmic.d natty.d
  
echo -n $BDF > /sys/bus/pci/devices/$BDF/driver/unbind
+
cd /usr/share/xen-tools/ && ln -s karmic.d oneiric.d
  
<nowiki># Add a new slot to the PCI Backend's list</nowiki>
+
cd /usr/share/xen-tools/ && ln -s karmic.d precise.d
  
echo -n $BDF > /sys/bus/pci/drivers/pciback/new_slot
+
cd /usr/share/xen-tools/ && ln -s karmic.d quantal.d
  
<nowiki># Now that the backend is watching for the slot, bind to it</nowiki>
+
cd /usr/share/xen-tools/ && ln -s karmic.d raring.d
  
echo -n $BDF > /sys/bus/pci/drivers/pciback/bind
+
cd /usr/share/xen-tools/ && ln -s karmic.d saucy.d
  
}
+
cd /usr/share/xen-tools/ && ln -s karmic.d trusty.d
  
 +
cd /usr/share/xen-tools/ && ln -s karmic.d utopic.d
  
remove_device "Your PCI ID"
+
cd /usr/share/xen-tools/ && ln -s karmic.d vivid.d
  
<nowiki># For example : remove_device "0000:01:00.1"</nowiki>
+
cd /usr/share/xen-tools/ && ln -s karmic.d wily.d
  
 +
cd /usr/share/xen-tools/ && ln -s karmic.d xenial.d
  
Save the file and run this script via “sh yourfilename”.
+
cp hooks/common.sh /usr/share/xen-tools
  
After it, You must edit your VM config file. Open you config file via an editor like “Nano” :
+
cp -r hooks/common /usr/share/xen-tools
  
<nowiki># nano /etc/xen/windows.cfg</nowiki>
+
mkdir -p /usr/share/perl5/Xen/Tools
  
Then add below line to your config file :
+
cp ./lib/Xen/Tools/*.pm /usr/share/perl5/Xen/Tools
  
pci=['Your PCI ID','Your PCI ID']
+
mkdir -p man
  
<nowiki># For example : pci=['01:00.1','00:1a.0']</nowiki>
+
cd bin; for i in *-*[!y]; do pod2man --release=4.6.2 --official --section=8 $i ../man/$i.8; done
  
 +
for i in man/*.8; do gzip --force -9 $i; done
  
Then run your VM and your PCI device will attached to your VM.
+
mkdir -p /usr/share/man/man8/
  
 +
cp man/*.8.gz /usr/share/man/man8/
 +
</syntaxhighlight>
  
 +
OK, “Xen-Tools” installed successfully and you can use it.
  
 +
For install under Debian Dom0 just run :
  
 +
<syntaxhighlight lang="sh"># apt-get install xen-tools</syntaxhighlight>
  
 +
Let me to run “xen-create-image” and see what happen :
  
== {{anchor|Toc476606921}} <span style="color:#00000a;">Swap</span> ==
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xen-create-image
  
Before we speak about Swap in Linux, Let me to tell something about “Paging”. The Paging is a scheme of memory management that your system use it for store and retrieves data from it. Why its named paging? It is because the OS retrieves data from a secondary storage in specific size that called pages. It is an important part of Virtual memory that implemented in modern OS and let you to run Applications that are larger than your Physical memory.
+
Can't locate Env.pm in @INC (you may need to install the Env module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/bin/xen-create-image line 802.
  
What is the Swap? Swap space usually is a disk partition but can be a file too. When you installing Linux, you can define a partition as Swap space but it can be done later too. The Swap space is recommended for users that have less than 1 GB of RAM. It is a area on your HDD which is part of your Virtual Memory. The Swap space used when your system sense that need more Physical memory for active processes and after it, Inactive pages on your Physical memory moving the Swap space and your Physical memory freed and have more free space for others. You must note that The Swap space exist on your HDD and the speed of HDDs are slower then Physical memory. It is true that HDD with new technologies like SSD has more speed but don't consider the Swap space as a replacement for the Physical memory. For define a Swap space you must define it twice of Physical memory. For example, If you have 4GB RAM then your Swap should be 8GB.
+
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 802.
 +
</syntaxhighlight>
  
For check the Swap space of your system use below command :
+
OK, It is an error and can solved via install “perl-Env” package :
  
 +
<syntaxhighlight lang="sh"># yum install perl-Env</syntaxhighlight>
  
<nowiki># swapon --show</nowiki>
+
If after install “perl-Env” you got other errors then :
  
[root@localhost ~]# swapon --show
+
1- yum install cpan
  
NAME TYPE SIZE USED PRIO
+
2- Then use “cpan” with the package that you see. For example :
  
/dev/dm-1 partition 16G 0B -1
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xen-create-image
  
[root@localhost ~]#
+
Can't locate Term/UI.pm in @INC (you may need to install the Term::UI module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/bin/xen-create-image line 814.
  
 +
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 814.
 +
</syntaxhighlight>
  
As you see, My system has 16GB Swap space.
+
As you see, I got an error about a package with the name “Term::UI module” then I use below command for install it :
  
You can use “free -h” command too :
+
<syntaxhighlight lang="sh"># cpan Term::UI module</syntaxhighlight>
  
[root@localhost ~]# free -h
+
You may need to doing it for some packages but after it you are ready for work with “Xen-tools”.
  
total used free shared buff/cache available
+
OK, I consider you installed all modules and “Xen-tools” is ready for work.
  
Mem: 7.5G 186M 7.0G 4.4M 325M 7.2G
+
I run “xen-create-image” :
  
Swap: 15G 0B 15G
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xen-create-image
  
[root@localhost ~]#
+
Couldn't find a useful entry in the sources.list files of the Dom0. Tried:
  
 +
/etc/apt/sources.list
  
If you install the Linux as your VM then you may like to define an extended Swap space for it. It is true that you can use your Virtual HDD as a Swap space but you can define another HDD as Swap too.
+
The '--hostname' argument is mandatory.
  
First of all, We use “dd” command for create an image :
+
[root@localhost ~]#
 +
</syntaxhighlight>
  
<nowiki># dd if=/dev/zero of=linuxswap.swap bs=1024 count=”Your size”</nowiki>
+
It is a tool for automate creating. The syntax is straightforward and you can see more options just with “--help” option.
  
For example :
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xen-create-image --size=4Gb --swap=512Mb --ip=172.30.9.21 --netmask=255.255.255.0 --gateway=172.30.9.254 --dir=/home/mohsen --hostname=linux.via.xentools –dist=jessie --kernel /boot/vmlinuz-4.2.3-300.fc23.x86_64 --initrd /boot/initrd-plymouth.img --role gdm
  
[root@localhost mohsen]# dd if=/dev/zero of=linuxswap.swap bs=1024 count=4096000
+
[root@localhost mohsen]# xen-create-image --size=4Gb --swap=512Mb --ip=172.30.9.21 --netmask=255.255.255.0 --gateway=172.30.9.254 --dir=/home/mohsen --hostname=linux.via.xentools --dist=jessie --kernel /boot/vmlinuz-4.2.3-300.fc23.x86_64 --initrd /boot/initrd-plymouth.img --role gdm
  
4096000+0 records in
+
Couldn't find a useful entry in the sources.list files of the Dom0. Tried:
  
4096000+0 records out
+
/etc/apt/sources.list
  
4194304000 bytes (4.2 GB) copied, 32.8729 s, 128 MB/s
 
  
 +
General Information
  
Then :
+
--------------------
  
[root@localhost mohsen]# mkswap linuxswap.swap
+
Hostname : linux.via.xentools
  
mkswap: linuxswap.swap: insecure permissions 0644, 0600 suggested.
+
Distribution : jessie
  
Setting up swapspace version 1, size = 3.9 GiB (4194299904 bytes)
+
Mirror : http://httpredir.debian.org/debian
  
no label, UUID=f2464b51-c7ef-4990-8cb6-8d50d151b52e
+
Partitions : swap 512Mb (swap)
  
 +
/ 4Gb (ext3)
  
Now, It is a good time for attach our Swap space to our VM. Open your VM config file via an editor like “nano” and add below line to your VM config file :
+
Image type : sparse
  
file:/YourPath/linuxswap.swap,hdb,w
+
Memory size : 128M
  
 +
Kernel path : /boot/vmlinuz-4.4.7-300.fc23.x86_64
  
The complete line is something like :
+
Initrd path : /boot/initrd.img-4.4.7-300.fc23.x86_64
  
disk=['phy:/dev/Xen/linux,hda,w','file:/home/mohsen/linuxswap.swap,hdb,w']
 
  
 +
Networking Information
  
Now, Start your VM and when your VM is booted then your Swap space is “hdb” and your just need to enable it. You can use below command to enable your Swap in your VM :
+
----------------------
  
<nowiki># swapon /dev/hdb</nowiki>
+
IP Address 1 : 172.30.9.21 [MAC: 00:16:3E:52:EF:69]
  
 +
Netmask : 255.255.255.0
  
<div style="text-align:center;">[[Image:|top]]</div>
+
Gateway : 172.30.9.254
  
<div style="text-align:center;">Figure 35: Swap Space</div>
 
  
 +
Creating partition image: /home/mohsen/domains/linux.via.xentools/swap.img
  
As you see, My Linux had 2GB of Swap and after it my Linux VM has 5.9GB Swap Space.
+
Done
  
For mount it automatically via boot just doing following steps :
 
  
1- Open “fstab” file from “/etc/fstab” via an editor like “nano”.
+
Creating swap on /home/mohsen/domains/linux.via.xentools/swap.img
  
2- add below line :
+
Done
  
/dev/XXX none swap defaults 0 0
 
  
<nowiki># For example : /dev/hdb none swap defaults 0 0</nowiki>
+
Creating partition image: /home/mohsen/domains/linux.via.xentools/disk.img
  
 +
Done
  
3- Save file and reboot your system.
 
  
 +
Creating ext3 filesystem on /home/mohsen/domains/linux.via.xentools/disk.img
  
== {{anchor|Toc476606922}} <span style="color:#00000a;">Using Xen-Tools</span> ==
+
Done
  
What is Xen-Tools? It is a collection of Perl Scripts that allow you to create a new guest Xen domain. It is compatible with Debian more but nowadays can support Ubuntu, CentOS and others. OK, Let start!
+
Installation method: debootstrap
  
Go to “http://xen-tools.org/” and download the Xen-Tools. After it, For install “Xen-Tools” we must install some packages on CentOS. Run following command :
 
  
<nowiki># yum install debootstrap perl-Text-Template perl-Config-IniFiles perl-File-Slurp perl-File-Which perl-Data-Dumper</nowiki>
+
Running hooks
  
After it go to the location that downloaded file is there and use “gunzip” and “tar” command for extract it. Then use “cd” command for change the current location and when you are in “Xen-Tools” directory run “make install” command. You will see something like below :
+
Done
  
  
[root@localhost xen-tools-4.6.2]# make install
+
No role scripts were specified. Skipping
  
for i in hooks/*/*-*; do chmod 755 $i; done
 
  
chmod 755 hooks/common.sh
+
Creating Xen configuration file
  
chmod 644 etc/*.conf
+
Done
  
chmod 644 etc/xm.tmpl
 
  
chmod 644 etc/xm-nfs.tmpl
+
No role scripts were specified. Skipping
  
chmod 644 misc/*
+
Setting up root password
  
mkdir -p /usr/bin
+
Generating a password for the new guest.
  
cp bin/xen-create-image /usr/bin
+
All done
  
cp bin/xen-create-nfs /usr/bin
 
  
cp bin/xt-customize-image /usr/bin
 
  
cp bin/xt-install-image /usr/bin
 
  
cp bin/xt-create-xen-config /usr/bin
+
Logfile produced at:
  
cp bin/xen-delete-image /usr/bin
+
/var/log/xen-tools/linux.via.xentools.log
  
cp bin/xen-list-images /usr/bin
 
  
cp bin/xen-update-image /usr/bin
+
Installation Summary
  
cp bin/xt-guess-suite-and-mirror /usr/bin
+
---------------------
  
chmod 755 /usr/bin/xen-create-image
+
Hostname : linux.via.xentools
  
chmod 755 /usr/bin/xen-create-nfs
+
Distribution : jessie
  
chmod 755 /usr/bin/xt-customize-image
+
MAC Address : 00:16:3E:52:EF:69
  
chmod 755 /usr/bin/xt-install-image
+
IP Address(es) : 172.30.9.21
  
chmod 755 /usr/bin/xt-create-xen-config
+
SSH Fingerprint : SHA256:oRLrvjgRgIcJkVeuQKJRQEKM656GVD9t4EQOmgrAr0k (DSA)
  
chmod 755 /usr/bin/xen-delete-image
+
SSH Fingerprint : SHA256:vynLLpUihRZ14l7zExPh8CDcGg/PgVjCs2RVe9QbD64 (RSA)
  
chmod 755 /usr/bin/xen-list-images
+
Root Password : z8gCMQGvyumHiQFSjWV9iXd
 +
</syntaxhighlight>
  
chmod 755 /usr/bin/xen-update-image
+
Everything is Done and if you look at “/etc/xen/” then you see a config file with the name of “--hostname” opting. For example, our “--hostname” was “ linux.via.xentools” and a file created with “ linux.via.xentools” under “/etc/xen”. Just run :
  
chmod 755 /usr/bin/xt-guess-suite-and-mirror
+
<syntaxhighlight lang="sh"># xl create /etc/xen/linux.via.xentools.cfg</syntaxhighlight>
  
mkdir -p /etc/xen-tools
+
You can change “dist” parameter and for Linux Distros that supported, Please look at “/usr/share/xen-tools/”.
  
if [ -d /etc/xen-tools/hook.d ]; then mv /etc/xen-tools/hook.d/ /etc/xen-tools/hook.d.obsolete ; fi
+
<syntaxhighlight lang="sh">
 +
[root@localhost boot]# xl create /etc/xen/linux.via.xentools.cfg
  
mkdir -p /etc/xen-tools/skel/
+
Parsing config from /etc/xen/linux.via.xentools.cfg
  
mkdir -p /etc/xen-tools/role.d/
+
libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge online [-1] exited with error status 1
  
mkdir -p /etc/xen-tools/partitions.d/
+
libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
  
cp etc/*.conf /etc/xen-tools/
+
libxl: error: libxl_create.c:1362:domcreate_attach_vtpms: unable to add nic devices
  
cp etc/xm.tmpl /etc/xen-tools/
+
libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge offline [-1] exited with error status 1
  
cp etc/xm-nfs.tmpl /etc/xen-tools/
+
libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
  
cp partitions/*-* /etc/xen-tools/partitions.d/
+
libxl: info: libxl.c:1698:devices_destroy_cb: forked pid 24683 for destroy of domain 15
 +
</syntaxhighlight>
  
mkdir -p /usr/share/bash-completion/completions/
+
What happened? As you see, By default it need a Bridge with the name “xenbr0” but we defined our bridges as “br0” thus we must define it in our config file.
  
cp misc/xen-tools.bash-completion /usr/share/bash-completion/completions/xen-tools
+
Open your config file that generated by “Xen-Tools” via an editor like “nano” and add below lines to it :
  
mkdir -p /etc/initramfs-tools/conf.d/
+
<syntaxhighlight lang="sh">
 +
interface=['br0']
  
cp misc/xen-tools.initramfs-tools /etc/initramfs-tools/conf.d/xen-tools
+
vif = [ 'ip=172.30.9.21 ,mac=00:16:3E:52:EF:69, bridge=br0' ]
  
for i in roles/* ; do if [ -f $i ]; then cp $i /etc/xen-tools/role.d; fi ; done
+
vnc="1"
  
for i in /usr/share/xen-tools/*.d; do if [ -L "$i" ]; then rm -vf "$i"; fi; done
+
vnclisten="172.30.9.20"
 +
</syntaxhighlight>
  
mkdir -p /usr/share/xen-tools/centos-4.d/
+
I bold the parts that you must adding to your config file.
  
mkdir -p /usr/share/xen-tools/centos-5.d/
+
For More information about the Xen-Tools you can read the man page of it via below link :
  
mkdir -p /usr/share/xen-tools/centos-6.d/
+
http://man.cx/xen-create-image
  
mkdir -p /usr/share/xen-tools/fedora-core-6.d/
 
  
cp -R hooks/centos-4/*-* /usr/share/xen-tools/centos-4.d
+
== {{anchor|Toc476606923}} Monitoring Xen project ==
  
cp -R hooks/centos-5/*-* /usr/share/xen-tools/centos-5.d
+
We want talk to you about monitoring the Xen Project. I bet it is so important and you can see what happened on your Xen host. Fortunately, The Xen Project and Linux provide some tools for it and we will show you something about it.
  
cp -R hooks/centos-6/*-* /usr/share/xen-tools/centos-6.d
+
A default tools that provided by Xen project is “XenMon”. It is a useful tool that you can use it for monitoring the performance of Xen Dom0 and finding which domains use highest I/O or processing. You can start this tool via XenMon.py command :
  
cp -R hooks/fedora-core-6/*-* /usr/share/xen-tools/fedora-core-6.d
+
[[Image:Figure_36-_Xenmon.png|top|600px|none|thumb|Figure 36 : Xenmon.py.]]
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-4.d
+
As you see, The XenMon provide two columns. The left hand show you statistics that captured over the preceding 10 seconds and on the right hand you can see the data for the last 1 second.
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-5.d
+
The first row (Gotten) is the amount of time that each domain spent as executing. The second row (Blocked) show the statistics for idle time and the finally row (Waited) show you the amount of time the domain has been in a wait state.
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-7.d
+
As you on the top of console, By default the XenMon display information for CPU 0and if you have more than one Physical CPU the you can use “p” and “n” keys for move forward to other CPUs. For quit from the XenMon Environment you can use “q” key and XenMon show you the summary of data like below :
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-8.d
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xenmon.py
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-9.d
+
ms_per_sample = 100
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-10.d
+
Initialized with 8 cpu's
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-11.d
+
CPU Frequency = 3392.37
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-12.d
+
Event counts:
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-13.d
+
104856299Other
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-14.d
+
00000000Add Domain
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-15.d
+
00000000Remove Domain
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-16.d
+
00002256Sleep
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-17.d
+
03238839Wake
  
mkdir -p /usr/share/xen-tools/debian.d/
+
01477357Block
  
cp -R hooks/debian/*-* /usr/share/xen-tools/debian.d
+
06431042Switch
  
cd /usr/share/xen-tools/ && ln -s debian.d sarge.d
+
00000000Timer Func
  
cd /usr/share/xen-tools/ && ln -s debian.d etch.d
+
06431042Switch Prev
  
cd /usr/share/xen-tools/ && ln -s debian.d lenny.d
+
06431042Switch Next
  
cd /usr/share/xen-tools/ && ln -s debian.d squeeze.d
+
00000000Page Map
  
cd /usr/share/xen-tools/ && ln -s debian.d wheezy.d
+
00000000Page Unmap
  
cd /usr/share/xen-tools/ && ln -s debian.d jessie.d
+
00000000Page Transfer
  
cd /usr/share/xen-tools/ && ln -s debian.d stretch.d
+
processed 128867877 total records in 761 seconds (169340 per second)
  
cd /usr/share/xen-tools/ && ln -s debian.d sid.d
+
woke up 22863 times in 761 seconds (30 per second)
  
cd /usr/share/xen-tools/ && ln -s debian.d unstable.d
+
[root@localhost ~]#
 +
</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s debian.d testing.d
+
We recommended to look at “xenmon.py --help” command and you can see a bunch of useful parameters. For example, You just like to see the information about the first CPU then you can use “xenmon.py --cpu=1” or you just like to see the information about I/O count for each domain then you can use “xenmon.py –iocount”. The XenMon can accept The combination of parameters :
  
cd /usr/share/xen-tools/ && ln -s debian.d stable.d
+
<syntaxhighlight lang="sh"># xenmon.py --iocount --cpu=1 --allocated</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s debian.d oldstable.d
+
Another useful tool is “xentop”. You as a Linux administrator are familiar with “top” command in Linux Environment.
  
cd /usr/share/xen-tools/ && ln -s debian.d oldoldstable.d
+
<syntaxhighlight lang="sh"># xentop</syntaxhighlight>
  
mkdir -p /usr/share/xen-tools/gentoo.d/
+
[[Image:Figure_37-_Xentop.png|top|600px|none|thumb|Figure 37 : Xentop.]]
  
cp -R hooks/gentoo/*-* /usr/share/xen-tools/gentoo.d
+
The “Xentop” command is “top” command that dedicated for the Xen Project. When you run this command, You can see a bunch of useful features at the end of window. For example, Press “n” key for display information about the networks and packets that are sent and received.
  
mkdir -p /usr/share/xen-tools/dapper.d/
+
I will show you other useful tools that some of them are installed by default and some of them must be installed by yourself.
  
cp -R hooks/dapper/*-* /usr/share/xen-tools/dapper.d/
 
  
mkdir -p /usr/share/xen-tools/edgy.d/
+
1-''' VmStat'''
  
cp -R hooks/edgy/*-* /usr/share/xen-tools/edgy.d/
+
It is a useful command that display statistics of virtual memory, kernerl threads, disks, system processes, I/O blocks, interrupts, CPU activity and...
  
cd /usr/share/xen-tools/ && ln -s edgy.d feisty.d
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# vmstat
  
cd /usr/share/xen-tools/ && ln -s edgy.d gutsy.d
+
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  
cd /usr/share/xen-tools/ && ln -s edgy.d hardy.d
+
r b swpd free buff cache si so bi bo in cs us sy id wa st
  
mkdir -p /usr/share/xen-tools/intrepid.d/
+
0 2 60 130248 36912 3107996 0 0 7 7 20 9 0 0 100 0 0
 +
</syntaxhighlight>
  
cp -R hooks/intrepid/*-* /usr/share/xen-tools/intrepid.d/
+
2-''' Tcpdump'''
  
cd /usr/share/xen-tools/ && ln -s intrepid.d jaunty.d
+
It is good tool for network packet analyzer or packets sniffer and I bet if you work with it then it become a popular tool in your list. It provide good options for capture packets in a file.
  
mkdir -p /usr/share/xen-tools/karmic.d/
+
<syntaxhighlight lang="sh"># tcpdump -i enp7s0
  
cp -R hooks/karmic/*-* /usr/share/xen-tools/karmic.d/
+
05:24:08.332952 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997228:1997456, ack 417, win 309, options [nop,nop,TS val 187046219 ecr 3827389], length 228
  
cd /usr/share/xen-tools/ && ln -s karmic.d lucid.d
+
05:24:08.333148 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997456:1997684, ack 417, win 309, options [nop,nop,TS val 187046219 ecr 3827389], length 228
  
cd /usr/share/xen-tools/ && ln -s karmic.d maverick.d
+
05:24:08.333345 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997684:1997912, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228
  
cd /usr/share/xen-tools/ && ln -s karmic.d natty.d
+
05:24:08.333542 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997912:1998140, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228
  
cd /usr/share/xen-tools/ && ln -s karmic.d oneiric.d
+
05:24:08.333738 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1998140:1998368, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228
  
cd /usr/share/xen-tools/ && ln -s karmic.d precise.d
+
05:24:08.333895 IP 172.30.10.18.54923 > localhost.localdomain.ssh: Flags [.], ack 1998368, win 1995, options [nop,nop,TS val 3827394 ecr 187046201], length 0
  
cd /usr/share/xen-tools/ && ln -s karmic.d quantal.d
+
05:24:08.333949 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1998368:1998596, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827394], length 228
  
cd /usr/share/xen-tools/ && ln -s karmic.d raring.d
+
^C05:24:08.334048 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [.], ack 521, win 309, options [nop,nop,TS val 187046220 ecr 3827394], length 0
  
cd /usr/share/xen-tools/ && ln -s karmic.d saucy.d
 
  
cd /usr/share/xen-tools/ && ln -s karmic.d trusty.d
+
9184 packets captured
  
cd /usr/share/xen-tools/ && ln -s karmic.d utopic.d
+
9194 packets received by filter
  
cd /usr/share/xen-tools/ && ln -s karmic.d vivid.d
+
7 packets dropped by kernel
 +
</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s karmic.d wily.d
+
3-''' Htop'''
  
cd /usr/share/xen-tools/ && ln -s karmic.d xenial.d
+
It is a useful tool for monitor Linux process in real time. It is not installed by default and you can install it via “yum” or “dnf”.
  
cp hooks/common.sh /usr/share/xen-tools
 
  
cp -r hooks/common /usr/share/xen-tools
+
<syntaxhighlight lang="sh"># htop</syntaxhighlight>
  
mkdir -p /usr/share/perl5/Xen/Tools
+
[[Image:Figure_38-_Htop.png|top|600px|none|thumb|Figure 38 : Htop.]]
  
cp ./lib/Xen/Tools/*.pm /usr/share/perl5/Xen/Tools
 
  
mkdir -p man
+
4-''' IPTraf'''
  
cd bin; for i in *-*[!y]; do pod2man --release=4.6.2 --official --section=8 $i ../man/$i.8; done
+
It is a Real Time IP LAN Monitoring and can help you for collect useful information across the network. It is not installed by default and you must install it via “yum” or “dnf”.
  
for i in man/*.8; do gzip --force -9 $i; done
+
<syntaxhighlight lang="sh"># iptraf-ng</syntaxhighlight>
  
mkdir -p /usr/share/man/man8/
+
[[Image:Figure_39-_IPTraf.png|top|600px|none|thumb|Figure 39 : IPTraf.]]
  
cp man/*.8.gz /usr/share/man/man8/
 
  
 +
5- '''Nmon'''
  
OK, “Xen-Tools” installed successfully and you can use it.
+
Nmon or Nigel’s performance Monitor is a tool that used to monitor all Linux resources like CPU, Memory, Network and… It is not installed by default and you must use “yum” or “dnf” for install it.
  
For install under Debian Dom0 just run :
+
[[Image:Figure_40-_Nmon.png|top|600px|none|thumb|Figure 40 : Nmon.]]
  
<nowiki># apt-get install xen-tools</nowiki>
+
== {{anchor|Toc476606924}} XCP / XenServer ==
  
Let me to run “xen-create-image” and see what happen :
+
XCP means “Xen Cloud Platform” which has been replaced by XenServer from Xenserver.org. It is a Virtualization solution that provide out-of-the box virtualization and cloud computing. The XCP provide some features as below :
  
[root@localhost ~]# xen-create-image
+
* Provide a way to manage Pools.
  
Can't locate Env.pm in @INC (you may need to install the Env module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/bin/xen-create-image line 802.
+
* Support of advantage storage.
  
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 802.
+
* Support of SLA and mutli-tenancy.
  
 +
The XCP has two flavors : 1) XCP ISO 2) XCP-XAPI Packages. The first one is like XenServer and come with same drivers and the second one is a package that exist in some Linux Distros. A good comparison exist at [http://wiki.xenproject.org/wiki/Xen_/_XCP_/_XCP_on_Linux_Overview http://wiki.xenproject.org/wiki/Xen_/_XCP_/_XCP_on_Linux_Overview] .
  
OK, It is an error and can solved via install “perl-Env” package :
+
Unfortunately, “XAPI” not exist for Fedora anymore and if you look at [https://fedoraproject.org/wiki/Features/XAPI https://fedoraproject.org/wiki/Features/XAPI] then you see “Targeted release: Fedora 17”, But don't worry we use a trick for install it.
  
<nowiki># yum install perl-Env</nowiki>
+
Download “XenServer” .iso file from “http://xenserver.org/open-source-virtualization-download.html” and move it to your Xen Project Server. You can use “scp” command for do it. For example :
  
If after install “perl-Env” you got other errors then :
+
<syntaxhighlight lang="sh"># scp XenServer-7.0.0-main.iso root@172.30.9.20:/home/mohsen/</syntaxhighlight>
  
1- yum install cpan
+
After it, We must mount this .iso file thus create a directory with the name “cd” under “/mnt/” directory :
  
2- Then use “cpan” with the package that you see. For example :
 
  
[root@localhost ~]# xen-create-image
+
<syntaxhighlight lang="sh"># mkdir </syntaxhighlight>cd /mnt
  
Can't locate Term/UI.pm in @INC (you may need to install the Term::UI module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/bin/xen-create-image line 814.
+
Then use below command to mount .iso file to /mnt/cd” directory :
  
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 814.
+
<syntaxhighlight lang="sh"># mount -o loop /home/mohsen/XenServer-7.0.0-main.iso /mnt/cd</syntaxhighlight>
  
 +
Then change to “/mnt/cd” directory via “cd” command :
  
As you see, I got an error about a package with the name “Term::UI module” then I use below command for install it :
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# cd /mnt/cd/
  
<nowiki># cpan Term::UI module</nowiki>
+
[root@localhost cd]# ls
  
You may need to doing it for some packages but after it you are ready for work with “Xen-tools”.
+
boot client_install EFI EULA install.img LICENSES Packages Read_Me_First.html repodata
 +
</syntaxhighlight>
  
OK, I consider you installed all modules and “Xen-tools” is ready for work.
+
You can see a directory with the name “ Packages” and move to it via “cd” command. After it you can find “XAPI” package here :
  
I run “xen-create-image” :
+
<syntaxhighlight lang="sh">
 +
[root@localhost Packages]# ls xapi-xe*
  
[root@localhost ~]# xen-create-image
+
xapi-xe-1.9.57-8535.x86_64.rpm
 +
</syntaxhighlight>
  
Couldn't find a useful entry in the sources.list files of the Dom0. Tried:
+
Then use “rpm” command to install it as below :
  
/etc/apt/sources.list
+
<syntaxhighlight lang="sh">
 +
[root@localhost Packages]# rpm -Uvh xapi-xe-1.9.57-8535.x86_64.rpm
  
The '--hostname' argument is mandatory.
+
Preparing... ################################# [100%]
 
 
[root@localhost ~]#
 
 
 
 
 
It is a tool for automate creating. The syntax is straightforward and you can see more options just with “--help” option.
 
 
 
[root@localhost ~]# xen-create-image --size=4Gb --swap=512Mb --ip=172.30.9.21 --netmask=255.255.255.0 --gateway=172.30.9.254 --dir=/home/mohsen --hostname=linux.via.xentools –dist=jessie --kernel /boot/vmlinuz-4.2.3-300.fc23.x86_64 --initrd /boot/initrd-plymouth.img --role gdm
 
 
 
 
 
[root@localhost mohsen]# xen-create-image --size=4Gb --swap=512Mb --ip=172.30.9.21 --netmask=255.255.255.0 --gateway=172.30.9.254 --dir=/home/mohsen --hostname=linux.via.xentools --dist=jessie --kernel /boot/vmlinuz-4.2.3-300.fc23.x86_64 --initrd /boot/initrd-plymouth.img --role gdm
 
 
 
Couldn't find a useful entry in the sources.list files of the Dom0. Tried:
 
 
 
/etc/apt/sources.list
 
 
 
 
 
General Information
 
 
 
<nowiki>--------------------</nowiki>
 
 
 
Hostname : linux.via.xentools
 
 
 
Distribution : jessie
 
 
 
Mirror : http://httpredir.debian.org/debian
 
 
 
Partitions : swap 512Mb (swap)
 
 
 
/ 4Gb (ext3)
 
 
 
Image type : sparse
 
 
 
Memory size : 128M
 
 
 
Kernel path : /boot/vmlinuz-4.4.7-300.fc23.x86_64
 
 
 
Initrd path : /boot/initrd.img-4.4.7-300.fc23.x86_64
 
 
 
 
 
Networking Information
 
 
 
<nowiki>----------------------</nowiki>
 
 
 
IP Address 1 : 172.30.9.21 [MAC: 00:16:3E:52:EF:69]
 
 
 
Netmask : 255.255.255.0
 
 
 
Gateway : 172.30.9.254
 
 
 
 
 
Creating partition image: /home/mohsen/domains/linux.via.xentools/swap.img
 
 
 
Done
 
 
 
 
 
Creating swap on /home/mohsen/domains/linux.via.xentools/swap.img
 
 
 
Done
 
 
 
 
 
Creating partition image: /home/mohsen/domains/linux.via.xentools/disk.img
 
 
 
Done
 
 
 
 
 
Creating ext3 filesystem on /home/mohsen/domains/linux.via.xentools/disk.img
 
 
 
Done
 
 
 
Installation method: debootstrap
 
 
 
 
 
Running hooks
 
 
 
Done
 
 
 
 
 
No role scripts were specified. Skipping
 
 
 
 
 
Creating Xen configuration file
 
 
 
Done
 
 
 
 
 
No role scripts were specified. Skipping
 
 
 
Setting up root password
 
 
 
Generating a password for the new guest.
 
 
 
All done
 
 
 
 
 
 
 
 
 
Logfile produced at:
 
 
 
/var/log/xen-tools/linux.via.xentools.log
 
 
 
 
 
Installation Summary
 
 
 
<nowiki>---------------------</nowiki>
 
 
 
Hostname : linux.via.xentools
 
 
 
Distribution : jessie
 
 
 
MAC Address : 00:16:3E:52:EF:69
 
 
 
IP Address(es) : 172.30.9.21
 
 
 
SSH Fingerprint : SHA256:oRLrvjgRgIcJkVeuQKJRQEKM656GVD9t4EQOmgrAr0k (DSA)
 
 
 
SSH Fingerprint : SHA256:vynLLpUihRZ14l7zExPh8CDcGg/PgVjCs2RVe9QbD64 (RSA)
 
 
 
Root Password : z8gCMQGvyumHiQFSjWV9iXd
 
 
 
 
 
Everything is Done and if you look at “/etc/xen/” then you see a config file with the name of “--hostname” opting. For example, our “--hostname” was “ linux.via.xentools” and a file created with “ linux.via.xentools” under “/etc/xen”. Just run :
 
 
 
<nowiki># xl create /etc/xen/linux.via.xentools.cfg</nowiki>
 
 
 
You can change “dist” parameter and for Linux Distros that supported, Please look at “/usr/share/xen-tools/”.
 
 
 
[root@localhost boot]# xl create /etc/xen/linux.via.xentools.cfg
 
 
 
Parsing config from /etc/xen/linux.via.xentools.cfg
 
 
 
libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge online [-1] exited with error status 1
 
 
 
libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
 
 
 
libxl: error: libxl_create.c:1362:domcreate_attach_vtpms: unable to add nic devices
 
 
 
libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge offline [-1] exited with error status 1
 
 
 
libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
 
 
 
libxl: info: libxl.c:1698:devices_destroy_cb: forked pid 24683 for destroy of domain 15
 
 
 
 
 
What happened? As you see, By default it need a Bridge with the name “xenbr0” but we defined our bridges as “br0” thus we must define it in our config file.
 
 
 
Open your config file that generated by “Xen-Tools” via an editor like “nano” and add below lines to it :
 
 
 
 
 
interface=['br0']
 
 
 
vif <nowiki>= [ 'ip=172.30.9.21 ,mac=00:16:3E:52:EF:69, bridge=br0' ]</nowiki>
 
 
 
vnc="1"
 
 
 
vnclisten="172.30.9.20"
 
 
 
 
 
I bold the parts that you must adding to your config file.
 
 
 
For More information about the Xen-Tools you can read the man page of it via below link :
 
 
 
http://man.cx/xen-create-image
 
 
 
 
 
 
 
 
 
== {{anchor|Toc476606923}} <span style="color:#00000a;">Monitoring Xen project</span> ==
 
 
 
We want talk to you about monitoring the Xen Project. I bet it is so important and you can see what happened on your Xen host. Fortunately, The Xen Project and Linux provide some tools for it and we will show you something about it.
 
 
 
A default tools that provided by Xen project is “XenMon”. It is a useful tool that you can use it for monitoring the performance of Xen Dom0 and finding which domains use highest I/O or processing. You can start this tool via XenMon.py command :
 
 
 
 
 
<div style="text-align:center;">[[Image:|top]]</div>
 
 
 
<div style="text-align:center;">Figure 36: Xenmon.py</div>
 
 
 
As you see, The XenMon provide two columns. The left hand show you statistics that captured over the preceding 10 seconds and on the right hand you can see the data for the last 1 second.
 
 
 
The first row (Gotten) is the amount of time that each domain spent as executing. The second row (Blocked) show the statistics for idle time and the finally row (Waited) show you the amount of time the domain has been in a wait state.
 
 
 
As you on the top of console, By default the XenMon display information for CPU 0and if you have more than one Physical CPU the you can use “p” and “n” keys for move forward to other CPUs. For quit from the XenMon Environment you can use “q” key and XenMon show you the summary of data like below :
 
 
 
 
 
[root@localhost ~]# xenmon.py
 
 
 
ms_per_sample = 100
 
 
 
Initialized with 8 cpu's
 
 
 
CPU Frequency = 3392.37
 
 
 
Event counts:
 
 
 
104856299Other
 
 
 
00000000Add Domain
 
 
 
00000000Remove Domain
 
 
 
00002256Sleep
 
 
 
03238839Wake
 
 
 
01477357Block
 
 
 
06431042Switch
 
 
 
00000000Timer Func
 
 
 
06431042Switch Prev
 
 
 
06431042Switch Next
 
 
 
00000000Page Map
 
 
 
00000000Page Unmap
 
 
 
00000000Page Transfer
 
 
 
processed 128867877 total records in 761 seconds (169340 per second)
 
 
 
woke up 22863 times in 761 seconds (30 per second)
 
 
 
[root@localhost ~]#
 
 
 
We recommended to look at “xenmon.py --help” command and you can see a bunch of useful parameters. For example, You just like to see the information about the first CPU then you can use “xenmon.py --cpu=1” or you just like to see the information about I/O count for each domain then you can use “xenmon.py –iocount”. The XenMon can accept The combination of parameters :
 
 
 
<nowiki># xenmon.py --iocount --cpu=1 --allocated</nowiki>
 
 
 
Another useful tool is “xentop”. You as a Linux administrator are familiar with “top” command in Linux Environment.
 
 
 
<nowiki># xentop</nowiki>
 
 
 
<div style="margin-left:1in;margin-right:0in;">[[Image:|top]]</div>
 
 
 
<div style="margin-left:2in;margin-right:0in;">Figure 37: Xentop</div>
 
 
 
The “Xentop” command is “top” command that dedicated for the Xen Project. When you run this command, You can see a bunch of useful features at the end of window. For example, Press “n” key for display information about the networks and packets that are sent and received.
 
 
 
I will show you other useful tools that some of them are installed by default and some of them must be installed by yourself.
 
 
 
 
 
1-''' <span style="color:#1f4d78;"><span style="color:#00000a;">VmStat'''</span></span>
 
 
 
It is a useful command that display statistics of virtual memory, kernerl threads, disks, system processes, I/O blocks, interrupts, CPU activity and...
 
 
 
[root@localhost ~]# vmstat
 
 
 
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 
 
 
r b swpd free buff cache si so bi bo in cs us sy id wa st
 
 
 
0 2 60 130248 36912 3107996 0 0 7 7 20 9 0 0 100 0 0
 
 
 
 
 
2-''' <span style="color:#1f4d78;"><span style="color:#00000a;">Tcpdump'''</span></span>
 
 
 
It is good tool for network packet analyzer or packets sniffer and I bet if you work with it then it become a popular tool in your list. It provide good options for capture packets in a file.
 
 
 
<nowiki># tcpdump -i enp7s0</nowiki>
 
 
 
05:24:08.332952 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997228:1997456, ack 417, win 309, options [nop,nop,TS val 187046219 ecr 3827389], length 228
 
 
 
05:24:08.333148 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997456:1997684, ack 417, win 309, options [nop,nop,TS val 187046219 ecr 3827389], length 228
 
 
 
05:24:08.333345 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997684:1997912, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228
 
 
 
05:24:08.333542 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997912:1998140, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228
 
 
 
05:24:08.333738 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1998140:1998368, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228
 
 
 
05:24:08.333895 IP 172.30.10.18.54923 > localhost.localdomain.ssh: Flags [.], ack 1998368, win 1995, options [nop,nop,TS val 3827394 ecr 187046201], length 0
 
 
 
05:24:08.333949 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1998368:1998596, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827394], length 228
 
 
 
^C05:24:08.334048 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [.], ack 521, win 309, options [nop,nop,TS val 187046220 ecr 3827394], length 0
 
 
 
 
 
9184 packets captured
 
 
 
9194 packets received by filter
 
 
 
7 packets dropped by kernel
 
 
 
3-''' <span style="color:#1f4d78;"><span style="color:#00000a;">Htop'''</span></span>
 
 
 
It is a useful tool for monitor Linux process in real time. It is not installed by default and you can install it via “yum” or “dnf”.
 
 
 
 
 
<nowiki># htop</nowiki>
 
 
 
<div style="text-align:center;">[[Image:|top]]</div>
 
 
 
<div style="text-align:center;">Figure 38: Htop</div>
 
 
 
 
 
4-''' <span style="color:#1f4d78;"><span style="color:#00000a;">IPTraf'''</span></span>
 
 
 
It is a Real Time IP LAN Monitoring and can help you for collect useful information across the network. It is not installed by default and you must install it via “yum” or “dnf”.
 
 
 
<nowiki># iptraf-ng</nowiki>
 
 
 
[[Image:|top]]
 
 
 
<div style="text-align:center;">Figure 39: IPTraf</div>
 
 
 
 
 
5- <span style="color:#1f4d78;"><span style="color:#00000a;">'''Nmon'''</span></span>
 
 
 
Nmon or Nigel’s performance Monitor is a tool that used to monitor all Linux resources like CPU, Memory, Network and… It is not installed by default and you must use “yum” or “dnf” for install it.
 
 
 
[[Image:|top]]
 
 
 
<div style="margin-left:1.5in;margin-right:0in;">Figure 40: Nmon</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
== {{anchor|Toc476606924}} <span style="color:#00000a;">XCP</span> ==
 
 
 
XCP means “Xen Cloud Platform” that is a Virtualization solution that provide out-of-the box virtualization and cloud computing. The XCP provide some features as below :
 
 
 
●Provide a way to manage Pools.
 
 
 
●Support of advantage storage.
 
 
 
●Support of SLA and mutli-tenancy.
 
 
 
 
 
The XCP has two flavors : 1) XCP ISO 2) XCP-XAPI Packages. The first one is like XenServer and come with same drivers and the second one is a package that exist in some Linux Distros. A good comparison exist at [http://wiki.xenproject.org/wiki/Xen_/_XCP_/_XCP_on_Linux_Overview http://wiki.xenproject.org/wiki/Xen_/_XCP_/_XCP_on_Linux_Overview] .
 
 
 
Unfortunately, “XAPI” not exist for Fedora anymore and if you look at [https://fedoraproject.org/wiki/Features/XAPI https://fedoraproject.org/wiki/Features/XAPI] then you see “Targeted release: Fedora 17”, But don't worry we use a trick for install it.
 
 
 
Download “XenServer” .iso file from “http://xenserver.org/open-source-virtualization-download.html” and move it to your Xen Project Server. You can use “scp” command for do it. For example :
 
 
 
<nowiki># scp XenServer-7.0.0-main.iso root@172.30.9.20:/home/mohsen/</nowiki>
 
 
 
After it, We must mount this .iso file thus create a directory with the name “cd” under “/mnt/” directory :
 
 
 
 
 
<nowiki># mkdir </nowiki>cd /mnt
 
 
 
Then use below command to mount .iso file to “/mnt/cd” directory :
 
 
 
<nowiki># mount -o loop /home/mohsen/XenServer-7.0.0-main.iso /mnt/cd</nowiki>
 
 
 
Then change to “/mnt/cd” directory via “cd” command :
 
 
 
[root@localhost ~]# cd /mnt/cd/
 
 
 
[root@localhost cd]# ls
 
 
 
boot client_install EFI EULA install.img LICENSES Packages Read_Me_First.html repodata
 
 
 
 
 
You can see a directory with the name “ Packages” and move to it via “cd” command. After it you can find “XAPI” package here :
 
 
 
[root@localhost Packages]# ls xapi-xe*
 
 
 
xapi-xe-1.9.57-8535.x86_64.rpm
 
 
 
 
 
Then use “rpm” command to install it as below :
 
 
 
 
 
[root@localhost Packages]# rpm -Uvh xapi-xe-1.9.57-8535.x86_64.rpm
 
 
 
Preparing... <nowiki>################################# [100%]</nowiki>
 
  
 
Updating / installing...
 
Updating / installing...
  
1:xapi-xe-1.9.57-8535 <nowiki>################################# [100%]</nowiki>
+
1:xapi-xe-1.9.57-8535 ################################# [100%]
 
+
</syntaxhighlight>
  
 
After it you can see that we installed “xe” successfully and can use it :
 
After it you can see that we installed “xe” successfully and can use it :
  
 +
<syntaxhighlight lang="sh">
 
[root@localhost Packages]# xe
 
[root@localhost Packages]# xe
  
Line 1,921: Line 1,793:
  
 
xe help -s <server> -p <port>
 
xe help -s <server> -p <port>
 +
</syntaxhighlight>
  
 
You may ask why we did it, We did it because you can control a Citrix XenServer host from your Xen Project or your Linux client. We will tell something about Citrix XenServer in the next chapter.
 
You may ask why we did it, We did it because you can control a Citrix XenServer host from your Xen Project or your Linux client. We will tell something about Citrix XenServer in the next chapter.
Line 1,929: Line 1,802:
  
 
3- For more information about VGA Passthrough Please look at : [http://wiki.xen.org/wiki/Xen_VGA_Passthrough http://wiki.xen.org/wiki/Xen_VGA_Passthrough] , [http://wiki.xen.org/wiki/VTdHowTo http://wiki.xen.org/wiki/VTdHowTo] , [http://wiki.xen.org/wiki/XenGT http://wiki.xen.org/wiki/XenGT] , [https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/ https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/] and [http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf]
 
3- For more information about VGA Passthrough Please look at : [http://wiki.xen.org/wiki/Xen_VGA_Passthrough http://wiki.xen.org/wiki/Xen_VGA_Passthrough] , [http://wiki.xen.org/wiki/VTdHowTo http://wiki.xen.org/wiki/VTdHowTo] , [http://wiki.xen.org/wiki/XenGT http://wiki.xen.org/wiki/XenGT] , [https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/ https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/] and [http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf]
 +
 +
[[Category:Users]] [[Category:HelloXenProjectBook]]

Latest revision as of 13:25, 27 September 2017

Chapter 4: Using Xen Project

Configuring and Booting Virtual Machines

Welcome to chapter 4, I bet this chapter is, the more interested chapter for you and you can learn to run and manage your Virtual Machines via The Xen Project. In this chapter, we show you how you can configure DomU and setting up your network and storage. We knows, You are familiar with Linux but we show you some Linux tools for manage LVM and create your partitions. After this chapter, You can manage Xen Project and your Virtual Machines and Install GNU/Linux and Windows OS on your Xen Project ax DomU. We will speak about a tool with the name “ virt-manager” that is a Graphical tool for managing your Vms.

By default, Fedora Server edition not have any Graphical Environment and as you know, The Graphical Environment need a lot of resources and not a good idea for server. So, System administrator don't like to install Graphical Environment and prefer CLI. You may ask yourself, Some Graphical Environment like “XFCE” need low resources but compared with CLI they need more resources.

Manage virtual machines with virt-manager

We want to show you “virt-manager” and it is a graphical program, Thus we need to install a Graphical Environment. Popular Desktops in Fedora are “Gnome” , “KDE” , “XFCE” and “MATE” but you can use other Desktops too.

For Install a Graphical Environment use below commands :

Gnome :

# yum groupinstall gnome

or

# yum groupinstall gdm

KDE :

# yum groupinstall kde

XFCE :

# yum groupinstall xfce

MATE :

# yum groupinstall "MATE Desktop”


When installing finished just run below command :

# startx

And after it you can see your Desktop. Mine is:

Figure 18 : MATE Desktop.


Open a “Terminal” and type below command for installing “Virt-Manager” :

# yum install virt-manager

After it you can run “virt-manager”.

Usually, Xen Masters use LVM volumes to store the Xen guest virtual disks and we will explain it in the future and skip it now, But just know that you can use Virtual HDD and real partition for your Guest DomU.

The Virt-manager, provide a good GUI and you can create your DomU via it very easy :

Figure 19 : Virt-Manager (OpenSUSE).
Figure 20 : Virt-Manager (Create Fedora 22 as DomU on OpenSUSE).

As you see, It is easy as ABC and give you this ability to run your own DomU guest via a nice Graphical interface.

Note that, If after install Graphical Environment your Xen Project show you an error, Then don't worry and Just Reinstall the Xen Project via below command :

# dnf reinstall xen*

After, Everything back to a right point.

If you start “Virt-Manager” and see some error like “unable to connect to libvirt” then don't worry, Just type below command :

# service libvirtd restart

You as a Linux administrator know that Linux has “/var/log/” directory that record everything that happening in your system. After install Xen, The Xen Project create a directory with the name “xen” under “/var/log” and all Xen errors and...recorded under this directory. If you encounter with any error just see “/var/log/xen/”.

OK, It is enough and you are familiar with “Virt-Manager”. Now, It is a good time for speaking about “ Storage and Networking”. Let's Go!

Storage and Networking

The Xen Project can use your real partition on your HDD as a Guest HDD and you can add HDD image also. We say it “Local Storage”. The Local Storage can partitioned via a tool like “LVM” or you can save your HDD image as a file on it. Let me to speak about LVM more.

LVM or Logical Volume Manager is a device mapper in Linux. You may ask, What is Device Mapper? OK, The Device Mapper is a framework that provided by The Linux Kernel and its goal is mapping physical block devices onto high-level virtual block devices. Device Mapper passing data from a virtual block device to another block device. The LVM provide logical volume management for the Linux Kernel and a method of allocating space on storage devices. LVM is more flexible that traditional partitioning. When you install Linux, It selected a best method for partitioning by default.

You can consider “LVM” as a "dynamic partitions", Its mean that you can create/resize/delete partitions while your Linux is running and you don't need any reboot for influence. LVM have many benefits but some of important of them are :

  • It can support more than one HDD.
  • LVM can be created to support RAID. including RAID 1, RAID 5 and RAID 6
  • It can support HA (High availability) and is a good option for Clusters.
  • Save space. Small chunks of unused space from several disks can be combined to create a usable volume.

With a lot of features, It has some bad things too. For example, the initial set-up of LVM is more complex than just partitioning a disk and you must understand LVM scheme and models.

It a good figure that help you to understand LVM easily :

Figure 21 : LVM Scheme.


I guess you understand it better. I want to show you some Linux Tools that via them you can manage your HDDs.

The first tool that we cover here is “fdisk” or “cfdisk”. Just type :

# cfdisk

or

# fdisk -l

I bet you will found “cfdisk” more friendly. The “fdisk -l” command will show you all of your partitions and HDD on your system. For example, For mine is :

[root@localhost ~]# fdisk -l

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0xed8a6a75

Device Boot Start End Sectors Size Id Type

/dev/sda1 2048 662710271 662708224 316G 8e Linux LVM

Disk /dev/mapper/fedora-root00: 300 GiB, 322122547200 bytes, 629145600 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/fedora-swap: 16 GiB, 17179869184 bytes, 33554432 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

And “cfdisk” :

Figure 22 : cfdisk.

OK. The first method that we choice is using your real partition as guest HDD.

I added a new HDD to my system and linux detected it as “sdb”. Let me to tell you how Linux detect Device/Drive names. If you look at “/dev/” directory then you will find interesting names. Linux detect IDE Disk as “hd” and SCSI disks as “sd”. The complete scheme is “/dev/xxyn”. The “xx” is “hd” or “sd” as we said and :

  • Y : It is a letter that indicate the number of Hard Disk. For example, “hda” mean the first IDE disk and “sda” mean the first SCSI Disk.
  • N : It is a number that indicate the number of partition. Don't forget, The first four partitions (primary or extended) are in range 1..4. Logical partitions start from 5. For example, “/dev/hda2” mean the first IDE Hard Disk and The second primary or extended partition and “/dev/sdb5” mean the first logical partition on second SCSI hard disk.

We explained it because we don't like you remove other partitions and lost your data.

I added a new HDD to my system and Linus detected it as “sdb”. I use below command for look at my new HDD :

# cfdisk /dev/sdb
Figure 23 : cfdisk.

Create a partition via “cfdisk” is straightforward and don't need any teach, But don't forget to select “Empty” as your file system. Our suggestion is that don't create any partition and just use “parted” tool as below.

I used a tool with the name “parted” as below :

# parted /dev/sdb mklabel msdos

It show you a warning message about that all of your information will be destroy. Type “yes” and enter. Then, Write below command :

# parted /dev/sdb mkpart primary

after this command, Linux ask you some questions, I selected default file system (ext2) and enter “1” as “Start” and “100%” as “End”.

What do you see? Linux created a partition for you with the name “/dev/sdb1”. You can confirm it via below command :

# fdisk /dev/sdb -l
Figure 24 : fdisk.

After it, I want enable “LVM” for this partition and use below command :

# parted -s /dev/sdb set 1 lvm on

In above command I used “set 1” that mean partition 1. Let me to see our partitions via “fdisk” command :

# fdisk /dev/sdb -l
Figure 25 : fdisk -l.


Look carefully, You can see “LVM” at the end of line. It mean that “LVM” enable for our partition.

Type below command :

# pvcreate /dev/sdb1
# vgcreate Xen /dev/sdb1 -v
Figure 26 : vgcreate.
# lvcreate -L 8G -v -n Fedora Xen

In above command, You should select your size (We selected 8 Gigabyte) and logical volume name (Fedora) and a name that you typed in the previous command (Xen). The output is :

Figure 27 : lvcreate.

Let me to see our LVM via “vgdisplay” command :

# vgdisplay | more
Figure 28 : vgdisplay-1.
Figure 29 : vgdisplay-2.

OK, our storage is ready and we just need to create a config file for our VM. Before we dive into config file, Please let us for write something about “Networking”.

Networking in Xen

Create and configure network in real world is a hard job and can be complex in some areas. In VM world it can be complex too and depending on the network diagram. We never explain networking here complete byt we just show you how you can configure a simple network for your VM and your VM able to see external world.

It is true that Virtual Machines share your interfaces but it is not true that you must not concern about the security.

The Xen Project support some kind of networking that we will show you them here :

Bridge : Dom0 and DomU are connected to each other via a virtual network. It is a default and most common configuration. In this configuration, a software bridge created in the backend domain and the Virtual network connected to your physical network. For bridging you can use two schemes :1) Linux detect your NIC as “eth0” and in the first scheme, Your eth0 renamed to other name (myeth0) and bridge changed to eth0 2) in the second scheme, Your NIC remain eth0 and your bridge is mybr0.

Names are personalisation and you can select other names.

NAT : Network Address Translation or NAT is kind of routing and each guest have its own IP address. In NAT, Dom0 configured to forward your packets and iptables used to configure your Dom0 Kernel as a IP packet filter. NAT using RFC1918 addresses (http://tools.ietf.org/html/rfc1918).

Routing : In Routing your Dom0 configured for forward packets and a point-to-point link created between Dom0 and each DomU Virtual NIC. Don't forget, because of nature of routing, each of guest NIC must have static IP address.

OK, Xen need bridge for running and we want to show that you how you can create a Bridge for The Xen Project.

Depend on your Linux Distro (Dom0) you can use some tools for create a bridge in easy way. For example, On Fedora and Debian you can use “bridge-utils” for configure your Bridge.

My Current config are :

enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255

inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>

ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)

RX packets 989 bytes 84310 (82.3 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 77 bytes 9575 (9.3 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

loop txqueuelen 1 (Local Loopback)

RX packets 83 bytes 9332 (9.1 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 83 bytes 9332 (9.1 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500

inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255

ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

As you see, Fedora detect my NIC as “enp7s0” and its IP address is “172.30.9.20”. I must tell you that it is a static IP and not DHCP. I will tell you something about DHCP too.

I want to create a bridge that use this static IP, So I create a file via below command :

# touch /etc/sysconfig/network-scripts/ifcfg-br0

Then open it via an editor like “nano” and fill it with below information :

DEVICE=br0

TYPE=Bridge

BOOTPROTO=none

ONBOOT=yes

IPADDR=172.30.9.20

PREFIX=24

GATEWAY=172.30.9.254

DNS1=172.30.9.1

DELAY=0

NM_CONTROLLED=no

But, If your real NIC use DHCP protocol then you should use below config for Bridge :

DEVICE=br0

TYPE=Bridge

BOOTPROTO=dhcp

ONBOOT=yes

DELAY=0

NM_CONTROLLED=no

After it, I must change my real NIC configuration, So I open it via an editor :

# nano /etc/sysconfig/network-scripts/ifcfg-enp7s0
HWADDR=50:E5:49:40:C4:8F

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=enp7s0

UUID=5e520f04-b32c-4116-b61f-89c190868edc

ONBOOT=yes

#IPADDR=172.30.9.20<

#PREFIX=24

#GATEWAY=172.30.9.254

#DNS1=172.30.9.1

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_PRIVACY=no

NM_CONTROLLED=no

BRIDGE=br0

As you see, My current NIC configuration use “BOOTPROTO=none” and its mean Static IP and if it was “DHCP” then you can't see any parts like “IPADDR”, “ PREFIX”, “GATEWAY” and “ DNS1” because all of these parts gaining automatically. Because of I added all of these parts to my Bridge then I must remove these parts from real NIC configuration file and add “NM_CONTROLLED=no” and “BRIDGE=br0” at the end of file. Don't forget, “br0” is my bridge name and you can select any name that you like.

If my NIC use DHCP protocol then I didn't need any extra works.

Everything is ready and I must restart my network service for take affect :

# systemctl restart network.service

After it, you can see current configuration via “ifconfig” command as below :

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255

inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>

ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)

RX packets 846 bytes 62175 (60.7 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 129 bytes 11550 (11.2 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>

ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)

RX packets 5479 bytes 468651 (457.6 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 558 bytes 75815 (74.0 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

loop txqueuelen 1 (Local Loopback)

RX packets 83 bytes 9332 (9.1 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 83 bytes 9332 (9.1 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500

inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255

ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

As you see, A Bridge with the name “br0” created and all information of my real NIC (enp7s0) given to my bridge. So, my Bridge work like my real NIC. Don't forget for each Physical NIC you should create a Bridge.

Our network is ready and we must create a Guest config.

Installing Windows as HVM domainU Guest

Huh, Are you ready? It is the most exciting part of our book and we to show you how you can install your Guest OS.

We choice Window 7 Enterprise for install as Guest and show you that how you can configure your Xen to use this “.iso” file and start your VM.

First of all, We must create a config file for our VM. Let me to create it via “touch” command in Linux :

# touch /etc/xen/windows.cfg

Then, I open it via an editor like “nano” as below :

# nano /etc/xen/windows.cfg

And fill this file via below information :

name = "Windows7"

builder = "hvm"

vcpus = 4

memory = "4096"

maxmex= "8192"

vif=['bridge=br0']

disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r']

vnc="1"

vnclisten="172.30.9.20"

vncconsole="0" 

boot="dc"

stdvga=1

videoram=32

on_poweroff = "destroy"

on_reboot = "restart"

on_crash = "restart"

I must tell you something about this file :

  • vif=['bridge=br0'] : Because of we choice “br0” as a name of our Bridge then we must write “'bridge=br0'” ,But if your Bridge name is different then you must write your Bridge name instead of it here.
  • disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r'] : If you remember, We want to use our real partition as our Guest partition, Thus it is not a File that act as a real HDD. Because of it, We used “phy” that mean Physical. The “Xen” is our LVM and I choice “Fedora” as a name of my 20 GB partition on LVM. You may selected other name that you must put it here.
  • Vnclisten="172.30.9.20" : Because I use the Xen Project on other server and not on my current PC, I must define the IP address of my Xen Server. My Xen Server IP is “172.30.9.20” and if your situation is like us then you must write your Xen Server IP here but if you run the Xen Project on your PC and not another PC or Server then you must write “vnclisten="0.0.0.0"”. When you select “0.0.0.0” as IP then it is your local host.
  • boot="dc" : the “d” mean “CDROM” and “c” mean your HDD. It is your Boot order and when you Guest installed you can change it to “boot=”c””. The Xen Project parameters are boot on floppy (a), hard disk (c), Network (n) and CD-ROM (d).


Let us start our Guest. Just type below command :

# xl create /etc/xen/windows.cfg

and if you have not any error in your syntax then your xen just show “Parsing config from /etc/xen/windows.cfg” and your VM started.

After it write below command :

# xl list

and you can see something like below :

Name ID Mem VCPUsStateTime(s)

Domain-0 0 3659 8 r----- 887.6

Windows7 19 4096 4 -b---- 23.1

As you see, “Windows7” is running and we just need connect to it via “vncviewer”. But you must did something on your Firewall.

Linux use “iptables” as Firewall and VNC Port is not opened by default and we must open this port for connect to our VNC remotely. Don't forget, We doing it because our Xen server is on another PC and we must connect to it remotely thus we need open VNC Port. The VNC use Port 5900 and TCP protocol.

I use “netstat -nat” command for show our current network connections :

# netstat -nat

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State 

tcp 0 0 172.30.9.20:5900 0.0.0.0:* LISTEN 

tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 

tcp 0 0 172.30.9.20:22 172.30.10.18:49824 ESTABLISHED

tcp6 0 0 :::9090 :::* LISTEN 

tcp6 0 0 :::22 :::* LISTEN

As you see, The IP “172.30.9.20” and Port “5900” are ready for connect but we must doing some steps for connect to our VM :

1- First of all, Install a tool like “vncviewer” on your Linux Distro.

2- Depend on your Linux Distro (Dom0) you must use “iptables” for open VNC Port on Dom0 :

# iptables -A INPUT -p tcp --dport 5900 -j ACCEPT
# iptables-save

After it, The Port “5900” is open on your Dom0 and you can connect to it remotely. You can use “iptables -L” for show your current iptables rules.

We ready ready to connect to our Xen Server :

# vncviewer 172.30.9.20:5900

And after it, A window displayed and we can do Windows install process:

Figure 30 : Windows 7 on Xen.

Sometimes you don't like your VM viewed by others and you want set password for it, For do it use below parameter in your VM config file :

vncpasswd=”Your Password”

After it, When you want view your VM via VNC you must enter a password :

vncviewer 172.30.9.20:5900

Connected to RFB server, using protocol version 3.8

Performing standard VNC authentication

Password:

When you working with Your VM, You may have some problems with your Display and you must consider below Links for Troubleshooting your problems :

http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_do_I_change_the_resolution_of_Xen_PV_domU_vfb_graphical_VNC_console.3F

http://wiki.xenproject.org/wiki/Xen_Common_Problems#How_can_I_get_resolutions_larger_than_800x600_for_Xen_HVM_guest_graphical_VNC_console.3F

A good note that you must consider it is that you should install “Windows PV Drivers” for your Xen VM. Navigate to “http://www.xenproject.org/downloads/windows-pv-drivers.html” and download .TAR files and extract them, then configure your NIC IP address and see your network and copy these files and install them on your Windows Guest. In below figure you can see that I choice a static IP for my Windows Guest :

Figure 31 : Static IP.

When you create another VM:

[root@localhost ~]# netstat -nat

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State 

tcp 0 0 172.30.9.20:5900  0.0.0.0:* LISTEN 

tcp 0 0 172.30.9.20:5901 0.0.0.0:* LISTEN 

tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 

tcp 0 0 172.30.9.20:5900 172.30.10.18:33869 ESTABLISHED

tcp 0 0 172.30.9.20:22 172.30.10.18:55000 ESTABLISHED

tcp 0 180 172.30.9.20:22 172.30.10.18:54616 ESTABLISHED

tcp6 0 0 :::9090 :::* LISTEN 

tcp6 0 0 :::22 :::* LISTEN
[root@localhost ~]# xl list

Name ID Mem VCPUsStateTime(s)

Domain-0 0 1590 8 r----- 192.7

Windows7 9 4096 4 -b---- 21.0

linux 10 2048 1 r----- 64.8

If you pay attention to the output of “ifconfig” command then you will see a default Bridge with the name “virbr0”. We can use this Bridge for add other NIC to our VM. For example, We need more than one NIC on our VM.

For adding more than one NIC you can use :

vif=['bridge=br0','mac=00:16:17:a5:6y:89,bridge=virbr0']

The “mac” defined the MAC address for our NIC.

We can use our first Bridge(br0) for adding more than NIC too but we should add a MAC address fpr each NIC :

vif=['bridge=br0,mac=00:13:r6:45:g6:9o','mac=00:16:17:a5:6y:89,bridge=br0']

In above example, We used the Bridge br0 for adding two NICs but we can't create another Bridge(br1) and attach it other Physical NIC and use it here.

Share storage between VMS

In some situation, You may want to use another HDD or other Vms HDD in a VM. It is so easy and you can write the name of your other HDD in “disk” in the config file :

disk=['phy:/dev/Xen/Fedora,hda,w','phy:/dev/Xen/linux,hdb,w','file:/home/mohsen/Windows7.iso,hdc:cdrom,r']

In above example, my main HDD is “Fedora” and I mount another HDD (linux) as “hdb”. When I fire my “vm” then I can see other HDD in my vm. If you noted, Then you can see “w” and “r” word at the end of my lines. What are these? The “w” mean “read-write” and “r” mean “read-only”.

VM States in The Xen Project

When you run a VM through Xen and run “xl list” then you can see a column with the name “State” and a word that changed sometimes. What does this word mean?

For example, I run “xl list” and the output is as below :

[root@localhost ~]# xl list

Name ID Mem VCPUsStateTime(s)

Domain-0 0 1590 8 r----- 1211.3

OpenSUSE 44 2048 1 r----- 4.6

I will tel you something about these words :

  • r - running

The domain is currently running.

  • b - blocked

The domain is blocked, and not running or runnable. This happened when the domain is waiting on IO or going to sleep because there was nothing else for it to do.

  • p - paused

The domain has been paused, and may administrator paused it via “xl pause” command. When a VM paused, The domain will still consume allocated resources like memory, but will not be eligible for scheduling by the Xen hypervisor.

  • s - shutdown

The guest has requested to be shutdown, rebooted or suspended.

  • c - crashed

The domain has crashed. It may if the domain has been configured not to restart on crash.

  • d - dying

The domain is in process of dying, but hasn't completely shutdown or crashed.

In below example, my “OpenSUSE” VM is running and established :

[root@localhost ~]# xl list

Name ID Mem VCPUsStateTime(s)

Domain-0 0 1590 8 r----- 1245.3

OpenSUSE 44 2048 2 -b---- 127.4

Then, I run below command for “Pause” it :

# xl pause OpenSUSE

and my current state is:

[root@localhost ~]# xl list

Name ID Mem VCPUsStateTime(s)

Domain-0 0 1590 8 r----- 1248.0

OpenSUSE 44 2048 2 --p--- 127.5

For “unpause” a VM you can use below command :

# xl unpause OpenSUSE

[root@localhost ~]# xl list

Name ID Mem VCPUsStateTime(s)

Domain-0 0 1590 8 r----- 1257.0

OpenSUSE 44 2048 2 -b---- 128.3

Add USB Devices to your VM

Sometime you may want to add a USB device to your VM. Linux has a command with the name “lsudb” that show your USB controllers on your Server :

[root@localhost ~]# lsusb

Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter

Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

As you see, My Server has USB 2.0 and USB 3,0 controllers. I plugged a HP Pendrive to my server and run command again :

[root@localhost ~]# lsusb

Bus 002 Device 003: ID 03f0:5607 Hewlett-Packard

Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter

Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

What happened? As you see, “Hewlett-Packard “ added to my list. If you look at the output more then you see some numbers behind the device name. What are these? These are vendor and product numbers are in “[vendor]:[product]” form.

For example, My Pendrive from HP company has “03f0:5607” and If you navigate to the “http://www.linux-usb.org/usb.ids” and search “ 03f0” then you can see that it is a vendor number for HP company.

A good web site for search and find the devices models is “http://www.the-sz.com/products/usbid/”. You can browse it and enter the device “vendor” and “product” numbers and click on search then you can see the model of your device :

Figure 32 : USB ID Database.


OK, We want add out Pendrive to our VM and copy and paste some files from/to it from our VM.

Fist of all, You must open your VM cofing file via an editor like “nano” :

# nano /etc/xen/linux.cg

Then add below lines to your config file :

usb="1"

usbdevice=['host:03f0:5607']

The “usb=”1”” cause enable USB controller and via “usbdevice” you can select your USB device for appear in VM. As you see, My HP Pendrive “vendor” and “product” numbers are “03f0:5607” and I written “usbdevice=['host:03f0:5607']” to my config file.

After it, When I start my VM then I can see my Pendrive that mounted in my VM. In below Figure, You can see that my HP Pendrive mounted in OpenSUSE Linux :

Figure 33: USB Mounted.

Use Physical CD/DVD ROM

It is True that installing OS from ISO files is more faster and better but sometime for some problems you can't use the .ISO file for install OS. For example, Your Dom0 not have enough space or you have CD or DVD of your OS. The Xen Project let you to use your Physical CD/DVD ROM for install OS.

Linux detect all devices as file, Thus your CD/DVD ROM is a file too. You can run “lsblk” command to find your CD/DVD ROM device :

[root@localhost ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 931.5G 0 disk

├─sda1 8:1 0 316G 0 part

│ ├─fedora-root00 253:0 0 300G 0 lvm /

│ └─fedora-swap 253:1 0 16G 0 lvm [SWAP]

└─sda2 8:2 0 615.5G 0 part

├─Xen-Fedora 253:2 0 20G 0 lvm 

└─Xen-linux 253:3 0 20G 0 lvm 

sdb 8:16 1 15.1G 0 disk

sr0 11:0 1 158.5M 0 rom

As you see, Linux detected my DVD ROM as “sr0”, Thus my DVD is “/dev/sr0” and I can use it. If I want my VM boot via Physical CD/DVD ROM then I just add below line to my VM config :

disk=['phy:/dev/sr0,hdc:cdrom,r']

If you remember, Int he previous config we used “disk=['file:/home/mohsen/opensuse.iso,hdc:cdrom,r']” and “file” was for .ISO file but for Physical devices we use “Phy” instead of “file”. After it, My VM booted via Physical DVD ROM.

If DVD Drive not detected automatically then use below command :

# eject

This command eject DVD from the Guest and if you change CD or DVD then for detect the insertion use below command :

# eject -t

Create a VM via .img

We showed you how you can create a VM via “LVM” but sometime for some reasons you don't like to create a LVM and like to boot your VM via an image. We will show you it. It is so easy and just need some steps.

First of all, Please let me to create a directory via “mkdir” for our Virtual HDD :

# mkdir Windows

change to “Windows” directory via “cd” command :

# cd Windows/

And run below command for create a Virtual HDD about 40GB :

# dd if=/dev/zero of=windows.img bs=1M count=40000
[root@localhost Windows]# dd if=/dev/zero of=windows.img bs=1M count=40000

40000+0 records in

40000+0 records out

41943040000 bytes (42 GB) copied, 332.735 s, 126 MB/s

If you list files and directory via “ls” command then you will see something like below :

[root@localhost Windows]# ls

windows.img

As you see, A file with the name “windows.img” created for us. Now, We must change VM config file for use this file as Virtual HDD.

Open your VM config file via an editor like “Nano” and add below line as your HDD :

disk=['file:/home/mohsen/Windows/windows.img,hda,w']

As you see, We used “file” instead of “phy”.

You must note that if you install Windows 10 and see below error the don't worry, It is because of your Windows date and you must use updated .ISO file :

Figure 34 : Windows 10 Error.

VGA Passthrough

A good feature and trick in Virtualization is VGA Passthrough. I don't know why someone need it but they have their reason for it. For example, Someone need run Graphical application under Vms and these application need a real VGA and can't work with a standard VGA Or some people like to Play Games :)

The Xen Project offer you this feature and you can use your real VGA in your VM but with some limitation. For example, Your CPU must support IOMMU.

Xen 4.0.0 is the first version Xen that support VGA graphics adapter passthrough. With this feature you can give the Guest Full control of graphic adapter and have Full 3D support in a VM. For enable this feature, Xen need IOMMU (Intel VT-d) support from the motherboard chipset. VT-d Pass-Through is a technique in Xen that give DomU this ability to access PCI using the IOMMU. An important note that you must consider is that “Only devices with FLR capabilities are supported” and otherwise you will see an Error. To check your PCI device for FLR feature you can run “lspci -w” on Dom0 and if in the output you see “FLReset-” then your device not supported and if you see “FLReset+” then it is OK.

We use Fedora and “-w” parameter not exist and thus we must use below commands :

First of all, Run below command to see a list of Hardware :

# lspci

Then run :

# lspci -vv -s PCI ID | grep FLR

For example :

# lspci -vv -s 00:02.0 | grep FLR
[root@localhost ~]# lspci -vv -s 00:02.0 | grep FLR

AFCap: TP+ FLR+

AFCtrl: FLR-

OK, We consider that your device support FLR and I will tell you that how you can attach it.

First of all, Execute below command :

# modprobe xen-pciback

Create a file via “touch” command and fill it with below information :

remove_device () {

BDF=$1

# Unbind a PCI function from its driver as necessary

[ ! -e /sys/bus/pci/devices/$BDF/driver/unbind ] || \

echo -n $BDF > /sys/bus/pci/devices/$BDF/driver/unbind

# Add a new slot to the PCI Backend's list

echo -n $BDF > /sys/bus/pci/drivers/pciback/new_slot

# Now that the backend is watching for the slot, bind to it

echo -n $BDF > /sys/bus/pci/drivers/pciback/bind

}

remove_device "Your PCI ID"
# For example : remove_device "0000:01:00.1"

Save the file and run this script via “sh yourfilename”.

After it, You must edit your VM config file. Open you config file via an editor like “Nano” :

# nano /etc/xen/windows.cfg

Then add below line to your config file :

pci=['Your PCI ID','Your PCI ID']

# For example : pci=['01:00.1','00:1a.0']


Then run your VM and your PCI device will attached to your VM.

Swap

Before we speak about Swap in Linux, Let me to tell something about “Paging”. The Paging is a scheme of memory management that your system use it for store and retrieves data from it. Why its named paging? It is because the OS retrieves data from a secondary storage in specific size that called pages. It is an important part of Virtual memory that implemented in modern OS and let you to run Applications that are larger than your Physical memory.

What is the Swap? Swap space usually is a disk partition but can be a file too. When you installing Linux, you can define a partition as Swap space but it can be done later too. The Swap space is recommended for users that have less than 1 GB of RAM. It is a area on your HDD which is part of your Virtual Memory. The Swap space used when your system sense that need more Physical memory for active processes and after it, Inactive pages on your Physical memory moving the Swap space and your Physical memory freed and have more free space for others. You must note that The Swap space exist on your HDD and the speed of HDDs are slower then Physical memory. It is true that HDD with new technologies like SSD has more speed but don't consider the Swap space as a replacement for the Physical memory. For define a Swap space you must define it twice of Physical memory. For example, If you have 4GB RAM then your Swap should be 8GB.

For check the Swap space of your system use below command :


# swapon --show
[root@localhost ~]# swapon --show

NAME TYPE SIZE USED PRIO

/dev/dm-1 partition 16G 0B -1

[root@localhost ~]#

As you see, My system has 16GB Swap space.

You can use “free -h” command too :

[root@localhost ~]# free -h

total used free shared buff/cache available

Mem: 7.5G 186M 7.0G 4.4M 325M 7.2G

Swap: 15G 0B 15G

[root@localhost ~]#

If you install the Linux as your VM then you may like to define an extended Swap space for it. It is true that you can use your Virtual HDD as a Swap space but you can define another HDD as Swap too.

First of all, We use “dd” command for create an image :

# dd if=/dev/zero of=linuxswap.swap bs=1024 count=”Your size”

For example :

[root@localhost mohsen]# dd if=/dev/zero of=linuxswap.swap bs=1024 count=4096000

4096000+0 records in

4096000+0 records out

4194304000 bytes (4.2 GB) copied, 32.8729 s, 128 MB/s

Then :

[root@localhost mohsen]# mkswap linuxswap.swap

mkswap: linuxswap.swap: insecure permissions 0644, 0600 suggested.

Setting up swapspace version 1, size = 3.9 GiB (4194299904 bytes)

no label, UUID=f2464b51-c7ef-4990-8cb6-8d50d151b52e

Now, It is a good time for attach our Swap space to our VM. Open your VM config file via an editor like “nano” and add below line to your VM config file :

file:/YourPath/linuxswap.swap,hdb,w

The complete line is something like :

disk=['phy:/dev/Xen/linux,hda,w','file:/home/mohsen/linuxswap.swap,hdb,w']

Now, Start your VM and when your VM is booted then your Swap space is “hdb” and your just need to enable it. You can use below command to enable your Swap in your VM :

# swapon /dev/hdb
Figure 35 : Swap Space.


As you see, My Linux had 2GB of Swap and after it my Linux VM has 5.9GB Swap Space.

For mount it automatically via boot just doing following steps :

1- Open “fstab” file from “/etc/fstab” via an editor like “nano”.

2- add below line :

/dev/XXX none swap defaults 0 0

# For example : /dev/hdb none swap defaults 0 0


3- Save file and reboot your system.


Using Xen-Tools

What is Xen-Tools? It is a collection of Perl Scripts that allow you to create a new guest Xen domain. It is compatible with Debian more but nowadays can support Ubuntu, CentOS and others. OK, Let start!

Go to “http://xen-tools.org/” and download the Xen-Tools. After it, For install “Xen-Tools” we must install some packages on CentOS. Run following command :

# yum install debootstrap perl-Text-Template perl-Config-IniFiles perl-File-Slurp perl-File-Which perl-Data-Dumper

After it go to the location that downloaded file is there and use “gunzip” and “tar” command for extract it. Then use “cd” command for change the current location and when you are in “Xen-Tools” directory run “make install” command. You will see something like below :

[root@localhost xen-tools-4.6.2]# make install

for i in hooks/*/*-*; do chmod 755 $i; done

chmod 755 hooks/common.sh

chmod 644 etc/*.conf

chmod 644 etc/xm.tmpl

chmod 644 etc/xm-nfs.tmpl

chmod 644 misc/*

mkdir -p /usr/bin

cp bin/xen-create-image /usr/bin

cp bin/xen-create-nfs /usr/bin

cp bin/xt-customize-image /usr/bin

cp bin/xt-install-image /usr/bin

cp bin/xt-create-xen-config /usr/bin

cp bin/xen-delete-image /usr/bin

cp bin/xen-list-images /usr/bin

cp bin/xen-update-image /usr/bin

cp bin/xt-guess-suite-and-mirror /usr/bin

chmod 755 /usr/bin/xen-create-image

chmod 755 /usr/bin/xen-create-nfs

chmod 755 /usr/bin/xt-customize-image

chmod 755 /usr/bin/xt-install-image

chmod 755 /usr/bin/xt-create-xen-config

chmod 755 /usr/bin/xen-delete-image

chmod 755 /usr/bin/xen-list-images

chmod 755 /usr/bin/xen-update-image

chmod 755 /usr/bin/xt-guess-suite-and-mirror

mkdir -p /etc/xen-tools

if [ -d /etc/xen-tools/hook.d ]; then mv /etc/xen-tools/hook.d/ /etc/xen-tools/hook.d.obsolete ; fi

mkdir -p /etc/xen-tools/skel/

mkdir -p /etc/xen-tools/role.d/

mkdir -p /etc/xen-tools/partitions.d/

cp etc/*.conf /etc/xen-tools/

cp etc/xm.tmpl /etc/xen-tools/

cp etc/xm-nfs.tmpl /etc/xen-tools/

cp partitions/*-* /etc/xen-tools/partitions.d/

mkdir -p /usr/share/bash-completion/completions/

cp misc/xen-tools.bash-completion /usr/share/bash-completion/completions/xen-tools

mkdir -p /etc/initramfs-tools/conf.d/

cp misc/xen-tools.initramfs-tools /etc/initramfs-tools/conf.d/xen-tools

for i in roles/* ; do if [ -f $i ]; then cp $i /etc/xen-tools/role.d; fi ; done

for i in /usr/share/xen-tools/*.d; do if [ -L "$i" ]; then rm -vf "$i"; fi; done

mkdir -p /usr/share/xen-tools/centos-4.d/

mkdir -p /usr/share/xen-tools/centos-5.d/

mkdir -p /usr/share/xen-tools/centos-6.d/

mkdir -p /usr/share/xen-tools/fedora-core-6.d/

cp -R hooks/centos-4/*-* /usr/share/xen-tools/centos-4.d

cp -R hooks/centos-5/*-* /usr/share/xen-tools/centos-5.d

cp -R hooks/centos-6/*-* /usr/share/xen-tools/centos-6.d

cp -R hooks/fedora-core-6/*-* /usr/share/xen-tools/fedora-core-6.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-4.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-5.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-7.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-8.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-9.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-10.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-11.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-12.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-13.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-14.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-15.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-16.d

cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-17.d

mkdir -p /usr/share/xen-tools/debian.d/

cp -R hooks/debian/*-* /usr/share/xen-tools/debian.d

cd /usr/share/xen-tools/ && ln -s debian.d sarge.d

cd /usr/share/xen-tools/ && ln -s debian.d etch.d

cd /usr/share/xen-tools/ && ln -s debian.d lenny.d

cd /usr/share/xen-tools/ && ln -s debian.d squeeze.d

cd /usr/share/xen-tools/ && ln -s debian.d wheezy.d

cd /usr/share/xen-tools/ && ln -s debian.d jessie.d

cd /usr/share/xen-tools/ && ln -s debian.d stretch.d

cd /usr/share/xen-tools/ && ln -s debian.d sid.d

cd /usr/share/xen-tools/ && ln -s debian.d unstable.d

cd /usr/share/xen-tools/ && ln -s debian.d testing.d

cd /usr/share/xen-tools/ && ln -s debian.d stable.d

cd /usr/share/xen-tools/ && ln -s debian.d oldstable.d

cd /usr/share/xen-tools/ && ln -s debian.d oldoldstable.d

mkdir -p /usr/share/xen-tools/gentoo.d/

cp -R hooks/gentoo/*-* /usr/share/xen-tools/gentoo.d

mkdir -p /usr/share/xen-tools/dapper.d/

cp -R hooks/dapper/*-* /usr/share/xen-tools/dapper.d/

mkdir -p /usr/share/xen-tools/edgy.d/

cp -R hooks/edgy/*-* /usr/share/xen-tools/edgy.d/

cd /usr/share/xen-tools/ && ln -s edgy.d feisty.d

cd /usr/share/xen-tools/ && ln -s edgy.d gutsy.d

cd /usr/share/xen-tools/ && ln -s edgy.d hardy.d

mkdir -p /usr/share/xen-tools/intrepid.d/

cp -R hooks/intrepid/*-* /usr/share/xen-tools/intrepid.d/

cd /usr/share/xen-tools/ && ln -s intrepid.d jaunty.d

mkdir -p /usr/share/xen-tools/karmic.d/

cp -R hooks/karmic/*-* /usr/share/xen-tools/karmic.d/

cd /usr/share/xen-tools/ && ln -s karmic.d lucid.d

cd /usr/share/xen-tools/ && ln -s karmic.d maverick.d

cd /usr/share/xen-tools/ && ln -s karmic.d natty.d

cd /usr/share/xen-tools/ && ln -s karmic.d oneiric.d

cd /usr/share/xen-tools/ && ln -s karmic.d precise.d

cd /usr/share/xen-tools/ && ln -s karmic.d quantal.d

cd /usr/share/xen-tools/ && ln -s karmic.d raring.d

cd /usr/share/xen-tools/ && ln -s karmic.d saucy.d

cd /usr/share/xen-tools/ && ln -s karmic.d trusty.d

cd /usr/share/xen-tools/ && ln -s karmic.d utopic.d

cd /usr/share/xen-tools/ && ln -s karmic.d vivid.d

cd /usr/share/xen-tools/ && ln -s karmic.d wily.d

cd /usr/share/xen-tools/ && ln -s karmic.d xenial.d

cp hooks/common.sh /usr/share/xen-tools

cp -r hooks/common /usr/share/xen-tools

mkdir -p /usr/share/perl5/Xen/Tools

cp ./lib/Xen/Tools/*.pm /usr/share/perl5/Xen/Tools

mkdir -p man

cd bin; for i in *-*[!y]; do pod2man --release=4.6.2 --official --section=8 $i ../man/$i.8; done

for i in man/*.8; do gzip --force -9 $i; done

mkdir -p /usr/share/man/man8/

cp man/*.8.gz /usr/share/man/man8/

OK, “Xen-Tools” installed successfully and you can use it.

For install under Debian Dom0 just run :

# apt-get install xen-tools

Let me to run “xen-create-image” and see what happen :

[root@localhost ~]# xen-create-image

Can't locate Env.pm in @INC (you may need to install the Env module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/bin/xen-create-image line 802.

BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 802.

OK, It is an error and can solved via install “perl-Env” package :

# yum install perl-Env

If after install “perl-Env” you got other errors then :

1- yum install cpan

2- Then use “cpan” with the package that you see. For example :

[root@localhost ~]# xen-create-image

Can't locate Term/UI.pm in @INC (you may need to install the Term::UI module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/bin/xen-create-image line 814.

BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 814.

As you see, I got an error about a package with the name “Term::UI module” then I use below command for install it :

# cpan Term::UI module

You may need to doing it for some packages but after it you are ready for work with “Xen-tools”.

OK, I consider you installed all modules and “Xen-tools” is ready for work.

I run “xen-create-image” :

[root@localhost ~]# xen-create-image

Couldn't find a useful entry in the sources.list files of the Dom0. Tried:

/etc/apt/sources.list

The '--hostname' argument is mandatory.

[root@localhost ~]#

It is a tool for automate creating. The syntax is straightforward and you can see more options just with “--help” option.

[root@localhost ~]# xen-create-image --size=4Gb --swap=512Mb --ip=172.30.9.21 --netmask=255.255.255.0 --gateway=172.30.9.254 --dir=/home/mohsen --hostname=linux.via.xentools –dist=jessie --kernel /boot/vmlinuz-4.2.3-300.fc23.x86_64 --initrd /boot/initrd-plymouth.img --role gdm

[root@localhost mohsen]# xen-create-image --size=4Gb --swap=512Mb --ip=172.30.9.21 --netmask=255.255.255.0 --gateway=172.30.9.254 --dir=/home/mohsen --hostname=linux.via.xentools --dist=jessie --kernel /boot/vmlinuz-4.2.3-300.fc23.x86_64 --initrd /boot/initrd-plymouth.img --role gdm

Couldn't find a useful entry in the sources.list files of the Dom0. Tried:

/etc/apt/sources.list


General Information

--------------------

Hostname : linux.via.xentools

Distribution : jessie

Mirror : http://httpredir.debian.org/debian

Partitions : swap 512Mb (swap)

/ 4Gb (ext3)

Image type : sparse

Memory size : 128M

Kernel path : /boot/vmlinuz-4.4.7-300.fc23.x86_64

Initrd path : /boot/initrd.img-4.4.7-300.fc23.x86_64


Networking Information

----------------------

IP Address 1 : 172.30.9.21 [MAC: 00:16:3E:52:EF:69]

Netmask : 255.255.255.0

Gateway : 172.30.9.254


Creating partition image: /home/mohsen/domains/linux.via.xentools/swap.img

Done


Creating swap on /home/mohsen/domains/linux.via.xentools/swap.img

Done


Creating partition image: /home/mohsen/domains/linux.via.xentools/disk.img

Done


Creating ext3 filesystem on /home/mohsen/domains/linux.via.xentools/disk.img

Done

Installation method: debootstrap


Running hooks

Done


No role scripts were specified. Skipping


Creating Xen configuration file

Done


No role scripts were specified. Skipping

Setting up root password

Generating a password for the new guest.

All done




Logfile produced at:

 /var/log/xen-tools/linux.via.xentools.log


Installation Summary

---------------------

Hostname : linux.via.xentools

Distribution : jessie

MAC Address : 00:16:3E:52:EF:69

IP Address(es) : 172.30.9.21

SSH Fingerprint : SHA256:oRLrvjgRgIcJkVeuQKJRQEKM656GVD9t4EQOmgrAr0k (DSA)

SSH Fingerprint : SHA256:vynLLpUihRZ14l7zExPh8CDcGg/PgVjCs2RVe9QbD64 (RSA)

Root Password : z8gCMQGvyumHiQFSjWV9iXd

Everything is Done and if you look at “/etc/xen/” then you see a config file with the name of “--hostname” opting. For example, our “--hostname” was “ linux.via.xentools” and a file created with “ linux.via.xentools” under “/etc/xen”. Just run :

# xl create /etc/xen/linux.via.xentools.cfg

You can change “dist” parameter and for Linux Distros that supported, Please look at “/usr/share/xen-tools/”.

[root@localhost boot]# xl create /etc/xen/linux.via.xentools.cfg

Parsing config from /etc/xen/linux.via.xentools.cfg

libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge online [-1] exited with error status 1

libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0

libxl: error: libxl_create.c:1362:domcreate_attach_vtpms: unable to add nic devices

libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge offline [-1] exited with error status 1

libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0

libxl: info: libxl.c:1698:devices_destroy_cb: forked pid 24683 for destroy of domain 15

What happened? As you see, By default it need a Bridge with the name “xenbr0” but we defined our bridges as “br0” thus we must define it in our config file.

Open your config file that generated by “Xen-Tools” via an editor like “nano” and add below lines to it :

interface=['br0']

vif = [ 'ip=172.30.9.21 ,mac=00:16:3E:52:EF:69, bridge=br0' ]

vnc="1"

vnclisten="172.30.9.20"

I bold the parts that you must adding to your config file.

For More information about the Xen-Tools you can read the man page of it via below link :

http://man.cx/xen-create-image


Monitoring Xen project

We want talk to you about monitoring the Xen Project. I bet it is so important and you can see what happened on your Xen host. Fortunately, The Xen Project and Linux provide some tools for it and we will show you something about it.

A default tools that provided by Xen project is “XenMon”. It is a useful tool that you can use it for monitoring the performance of Xen Dom0 and finding which domains use highest I/O or processing. You can start this tool via XenMon.py command :

Figure 36 : Xenmon.py.

As you see, The XenMon provide two columns. The left hand show you statistics that captured over the preceding 10 seconds and on the right hand you can see the data for the last 1 second.

The first row (Gotten) is the amount of time that each domain spent as executing. The second row (Blocked) show the statistics for idle time and the finally row (Waited) show you the amount of time the domain has been in a wait state.

As you on the top of console, By default the XenMon display information for CPU 0and if you have more than one Physical CPU the you can use “p” and “n” keys for move forward to other CPUs. For quit from the XenMon Environment you can use “q” key and XenMon show you the summary of data like below :

[root@localhost ~]# xenmon.py

ms_per_sample = 100

Initialized with 8 cpu's

CPU Frequency = 3392.37

Event counts:

104856299Other

00000000Add Domain

00000000Remove Domain

00002256Sleep

03238839Wake

01477357Block

06431042Switch

00000000Timer Func

06431042Switch Prev

06431042Switch Next

00000000Page Map

00000000Page Unmap

00000000Page Transfer

processed 128867877 total records in 761 seconds (169340 per second)

woke up 22863 times in 761 seconds (30 per second)

[root@localhost ~]#

We recommended to look at “xenmon.py --help” command and you can see a bunch of useful parameters. For example, You just like to see the information about the first CPU then you can use “xenmon.py --cpu=1” or you just like to see the information about I/O count for each domain then you can use “xenmon.py –iocount”. The XenMon can accept The combination of parameters :

# xenmon.py --iocount --cpu=1 --allocated

Another useful tool is “xentop”. You as a Linux administrator are familiar with “top” command in Linux Environment.

# xentop
Figure 37 : Xentop.

The “Xentop” command is “top” command that dedicated for the Xen Project. When you run this command, You can see a bunch of useful features at the end of window. For example, Press “n” key for display information about the networks and packets that are sent and received.

I will show you other useful tools that some of them are installed by default and some of them must be installed by yourself.


1- VmStat

It is a useful command that display statistics of virtual memory, kernerl threads, disks, system processes, I/O blocks, interrupts, CPU activity and...

[root@localhost ~]# vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

0 2 60 130248 36912 3107996 0 0 7 7 20 9 0 0 100 0 0

2- Tcpdump

It is good tool for network packet analyzer or packets sniffer and I bet if you work with it then it become a popular tool in your list. It provide good options for capture packets in a file.

# tcpdump -i enp7s0

05:24:08.332952 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997228:1997456, ack 417, win 309, options [nop,nop,TS val 187046219 ecr 3827389], length 228

05:24:08.333148 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997456:1997684, ack 417, win 309, options [nop,nop,TS val 187046219 ecr 3827389], length 228

05:24:08.333345 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997684:1997912, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228

05:24:08.333542 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1997912:1998140, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228

05:24:08.333738 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1998140:1998368, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827389], length 228

05:24:08.333895 IP 172.30.10.18.54923 > localhost.localdomain.ssh: Flags [.], ack 1998368, win 1995, options [nop,nop,TS val 3827394 ecr 187046201], length 0

05:24:08.333949 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [P.], seq 1998368:1998596, ack 417, win 309, options [nop,nop,TS val 187046220 ecr 3827394], length 228

^C05:24:08.334048 IP localhost.localdomain.ssh > 172.30.10.18.54923: Flags [.], ack 521, win 309, options [nop,nop,TS val 187046220 ecr 3827394], length 0


9184 packets captured

9194 packets received by filter

7 packets dropped by kernel

3- Htop

It is a useful tool for monitor Linux process in real time. It is not installed by default and you can install it via “yum” or “dnf”.


# htop
Figure 38 : Htop.


4- IPTraf

It is a Real Time IP LAN Monitoring and can help you for collect useful information across the network. It is not installed by default and you must install it via “yum” or “dnf”.

# iptraf-ng
Figure 39 : IPTraf.


5- Nmon

Nmon or Nigel’s performance Monitor is a tool that used to monitor all Linux resources like CPU, Memory, Network and… It is not installed by default and you must use “yum” or “dnf” for install it.

Figure 40 : Nmon.

XCP / XenServer

XCP means “Xen Cloud Platform” which has been replaced by XenServer from Xenserver.org. It is a Virtualization solution that provide out-of-the box virtualization and cloud computing. The XCP provide some features as below :

  • Provide a way to manage Pools.
  • Support of advantage storage.
  • Support of SLA and mutli-tenancy.

The XCP has two flavors : 1) XCP ISO 2) XCP-XAPI Packages. The first one is like XenServer and come with same drivers and the second one is a package that exist in some Linux Distros. A good comparison exist at http://wiki.xenproject.org/wiki/Xen_/_XCP_/_XCP_on_Linux_Overview .

Unfortunately, “XAPI” not exist for Fedora anymore and if you look at https://fedoraproject.org/wiki/Features/XAPI then you see “Targeted release: Fedora 17”, But don't worry we use a trick for install it.

Download “XenServer” .iso file from “http://xenserver.org/open-source-virtualization-download.html” and move it to your Xen Project Server. You can use “scp” command for do it. For example :

# scp XenServer-7.0.0-main.iso root@172.30.9.20:/home/mohsen/

After it, We must mount this .iso file thus create a directory with the name “cd” under “/mnt/” directory :


# mkdir

cd /mnt

Then use below command to mount .iso file to “/mnt/cd” directory :

# mount -o loop /home/mohsen/XenServer-7.0.0-main.iso /mnt/cd

Then change to “/mnt/cd” directory via “cd” command :

[root@localhost ~]# cd /mnt/cd/

[root@localhost cd]# ls

boot client_install EFI EULA install.img LICENSES Packages Read_Me_First.html repodata

You can see a directory with the name “ Packages” and move to it via “cd” command. After it you can find “XAPI” package here :

[root@localhost Packages]# ls xapi-xe*

xapi-xe-1.9.57-8535.x86_64.rpm

Then use “rpm” command to install it as below :

[root@localhost Packages]# rpm -Uvh xapi-xe-1.9.57-8535.x86_64.rpm

Preparing... ################################# [100%]

Updating / installing...

1:xapi-xe-1.9.57-8535 ################################# [100%]

After it you can see that we installed “xe” successfully and can use it :

[root@localhost Packages]# xe

Usage: xe <cmd> [-s server] [-p port] ([-u username] [-pw password] or [-pwf <password file>]) <other arguments>

A full list of commands can be obtained by running

xe help -s <server> -p <port>

You may ask why we did it, We did it because you can control a Citrix XenServer host from your Xen Project or your Linux client. We will tell something about Citrix XenServer in the next chapter.

OK, This chapter Finished and you can test your knowledge after it. At the end of this chapter I just want to show you something that maybe useful : 1-For more information about DomU and Virt-Manager Please look at “http://wiki.xenproject.org/wiki/DomU_Install_with_Virt-Manager”.

2- For learn “virsh” command and use it via Xen Project Please look at http://wiki.xenproject.org/wiki/Virsh_Commands .

3- For more information about VGA Passthrough Please look at : http://wiki.xen.org/wiki/Xen_VGA_Passthrough , http://wiki.xen.org/wiki/VTdHowTo , http://wiki.xen.org/wiki/XenGT , https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/ and http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf