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

From Xen
 
(11 intermediate revisions by one other user 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>
  
<div style="text-align:center;">[[Image:Figure_19-_Virt-Manager_(OpenSUSE).png|top|600px|none|thumb]]</div>
+
And “cfdisk” :
  
===== <span style="color:#00000a;">Figure 19 : Virt-Manager (OpenSUSE).=====
+
[[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.
  
<div style="text-align:center;">[[Image:Figure_20-_Virt-Manager_(Create_Fedora_22_as_DomU_on_OpenSUSE).png|top|600px|none|thumb]]</div>
+
We explained it because we don't like you remove other partitions and lost your data.
  
===== <span style="color:#00000a;">Figure 20 : Virt-Manager (Create Fedora 22 as DomU on OpenSUSE).=====
+
I added a new HDD to my system and Linus detected it as “sdb”. I use below command for look at my new HDD :
  
 +
<syntaxhighlight lang="sh"># cfdisk /dev/sdb</syntaxhighlight>
  
As you see, It is easy as ABC and give you this ability to run your own DomU guest via a nice Graphical interface.
+
[[Image:Figure_23-_cfdisk.png|top|600px|none|thumb|Figure 23 : cfdisk.]]
  
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 :
+
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.
  
<nowiki># dnf reinstall xen*</nowiki>
+
I used a tool with the name “parted” as below :
  
After, Everything back to a right point.
+
<syntaxhighlight lang="sh"># parted /dev/sdb mklabel msdos</syntaxhighlight>
  
If you start “Virt-Manager” and see some error like “unable to connect to libvirt” then don't worry, Just type below command :
+
It show you a warning message about that all of your information will be destroy. Type “yes” and enter. Then, Write below command :
  
<nowiki># service libvirtd restart</nowiki>
+
<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”.
  
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/”.
+
What do you see? Linux created a partition for you with the name “/dev/sdb1”. You can confirm it via below command :
  
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!
+
<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>
  
== {{anchor|Toc476606915}} <span style="color:#00000a;">Storage and Networking</span> ==
+
[[Image:Figure_25-_fdisk_-l.png|top|600px|none|thumb|Figure 25 : fdisk -l.]]
  
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.
+
Look carefully, You can see “LVM” at the end of line. It mean that “LVM” enable for our partition.
  
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 :
+
Type below command :
  
●It can support more than one HDD.
+
<syntaxhighlight lang="sh"># pvcreate /dev/sdb1</syntaxhighlight>
  
●LVM can be created to support RAID. including RAID 1, RAID 5 and RAID 6
+
<syntaxhighlight lang="sh"># vgcreate Xen /dev/sdb1 -v</syntaxhighlight>
  
●It can support HA (High availability) and is a good option for Clusters.
+
[[Image:Figure_26-_vgcreate.png|top|600px|none|thumb|Figure 26 : vgcreate.]]
  
●Save space. Small chunks of unused space from several disks can be combined to create a usable volume.
+
<syntaxhighlight lang="sh"># lvcreate -L 8G -v -n Fedora Xen</syntaxhighlight>
  
 +
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 :
  
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.
+
[[Image:Figure_27-_lvcreate.png|top|600px|none|thumb|Figure 27 : lvcreate.]]
  
It a good figure that help you to understand LVM easily :
+
Let me to see our LVM via “vgdisplay” command :
  
 +
<syntaxhighlight lang="sh"># vgdisplay | more</syntaxhighlight>
  
 +
[[Image:Figure_28-_vgdisplay-1.png|top|600px|none|thumb|Figure 28 : vgdisplay-1.]]
  
<div style="text-align:center;">[[Image:Figure_21-_LVM_Scheme..png|top|600px|none|thumb]]</div>
+
[[Image:Figure_29-_vgdisplay-2.png|top|600px|none|thumb|Figure 29 : vgdisplay-2.]]
  
===== <span style="color:#00000a;">Figure 21 : LVM Scheme.=====
+
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 ==
  
I guess you understand it better. I want to show you some Linux Tools that via them you can manage your HDDs.
+
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.
  
The first tool that we cover here is “fdisk” or “cfdisk”. Just type :
+
It is true that Virtual Machines share your interfaces but it is not true that you must not concern about the security.
  
<nowiki># cfdisk</nowiki>
+
The Xen Project support some kind of networking that we will show you them here :
  
or
+
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.
  
<nowiki># fdisk -l</nowiki>
+
Names are personalisation and you can select other names.
  
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 :
+
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).
  
[root@localhost ~]# fdisk -l
+
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.
  
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
+
OK, Xen need bridge for running and we want to show that you how you can create a Bridge for The Xen Project.
  
Units: sectors of 1 * 512 = 512 bytes
+
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.
  
Sector size (logical/physical): 512 bytes / 512 bytes
+
My Current config are :
  
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
<syntaxhighlight lang="sh">
 +
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  
Disklabel type: dos
+
inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255
  
Disk identifier: 0xed8a6a75
+
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
  
Device Boot Start End Sectors Size Id Type
+
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
  
/dev/sda1 2048 662710271 662708224 316G 8e Linux LVM
+
RX packets 989 bytes 84310 (82.3 KiB)
  
Disk /dev/mapper/fedora-root00: 300 GiB, 322122547200 bytes, 629145600 sectors
+
RX errors 0 dropped 0 overruns 0 frame 0
  
Units: sectors of 1 * 512 = 512 bytes
+
TX packets 77 bytes 9575 (9.3 KiB)
  
Sector size (logical/physical): 512 bytes / 512 bytes
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
<syntaxhighlight lang="sh">
 +
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  
Disk /dev/mapper/fedora-swap: 16 GiB, 17179869184 bytes, 33554432 sectors
+
inet 127.0.0.1 netmask 255.0.0.0
  
Units: sectors of 1 * 512 = 512 bytes
+
inet6 ::1 prefixlen 128 scopeid 0x10<host>
  
Sector size (logical/physical): 512 bytes / 512 bytes
+
loop txqueuelen 1 (Local Loopback)
  
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
RX packets 83 bytes 9332 (9.1 KiB)
  
 +
RX errors 0 dropped 0 overruns 0 frame 0
  
And “cfdisk” :
+
TX packets 83 bytes 9332 (9.1 KiB)
  
<div style="text-align:center;">[[Image:Figure_22-_cfdisk..png|top|600px|none|thumb]]</div>
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
===== <span style="color:#00000a;">Figure 22 : cfdisk.=====
+
<syntaxhighlight lang="sh">
 +
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  
OK. The first method that we choice is using your real partition as guest HDD.
+
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  
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 :
+
ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)
  
●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.
+
RX packets 0 bytes 0 (0.0 B)
  
●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.
+
RX errors 0 dropped 0 overruns 0 frame 0
  
We explained it because we don't like you remove other partitions and lost your data.
+
TX packets 0 bytes 0 (0.0 B)
  
I added a new HDD to my system and Linus detected it as “sdb”. I use below command for look at my new HDD :
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
<nowiki># cfdisk /dev/sdb</nowiki>
+
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.
  
<div style="text-align:center;">[[Image:Figure_23-_cfdisk.png|top|600px|none|thumb]]</div>
+
I want to create a bridge that use this static IP, So I create a file via below command :
  
===== <span style="color:#00000a;">Figure 23 : cfdisk.=====
+
<syntaxhighlight lang="sh"># touch /etc/sysconfig/network-scripts/ifcfg-br0</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.
+
Then open it via an editor like “nano” and fill it with below information :
  
I used a tool with the name “parted” as below :
+
<syntaxhighlight lang="sh">
 +
DEVICE=br0
  
<nowiki># parted /dev/sdb mklabel msdos</nowiki>
+
TYPE=Bridge
  
It show you a warning message about that all of your information will be destroy. Type “yes” and enter. Then, Write below command :
+
BOOTPROTO=none
  
<nowiki># parted /dev/sdb mkpart primary</nowiki>
+
ONBOOT=yes
  
after this command, Linux ask you some questions, I selected default file system (ext2) and enter “1” as “Start” and “100%” as “End”.
+
IPADDR=172.30.9.20
  
What do you see? Linux created a partition for you with the name “/dev/sdb1”. You can confirm it via below command :
+
PREFIX=24
  
<nowiki># fdisk /dev/sdb -l</nowiki>
+
GATEWAY=172.30.9.254
  
[[Image:Figure_24-_fdisk.png|top|600px|none|thumb]]
+
DNS1=172.30.9.1
  
===== <span style="color:#00000a;">Figure 24 : fdisk.=====
+
DELAY=0
  
After it, I want enable “LVM” for this partition and use below command :
+
NM_CONTROLLED=no
 +
</syntaxhighlight>
  
<nowiki># parted -s /dev/sdb set 1 lvm on</nowiki>
+
But, If your real NIC use DHCP protocol then you should use below config for Bridge :
  
In above command I used “set 1” that mean partition 1. Let me to see our partitions via “fdisk” command :
+
<syntaxhighlight lang="sh">
 +
DEVICE=br0
  
<nowiki># fdisk /dev/sdb -l</nowiki>
+
TYPE=Bridge
  
[[Image:Figure_25-_fdisk_-l.png|top|600px|none|thumb]]
+
BOOTPROTO=dhcp
  
===== <span style="color:#00000a;">Figure 25 : fdisk -l.=====
+
ONBOOT=yes
  
 +
DELAY=0
  
Look carefully, You can see “LVM” at the end of line. It mean that “LVM” enable for our partition.
+
NM_CONTROLLED=no
 +
</syntaxhighlight>
  
Type below command :
+
After it, I must change my real NIC configuration, So I open it via an editor :
  
<nowiki># pvcreate /dev/sdb1</nowiki>
+
<syntaxhighlight lang="sh"># nano /etc/sysconfig/network-scripts/ifcfg-enp7s0</syntaxhighlight>
  
<nowiki># vgcreate Xen /dev/sdb1 -v</nowiki>
+
<syntaxhighlight lang="sh">
 +
HWADDR=50:E5:49:40:C4:8F
  
[[Image:Figure_26-_vgcreate.png|top|600px|none|thumb]]
+
TYPE=Ethernet
  
===== <span style="color:#00000a;">Figure 26 : vgcreate.=====
+
BOOTPROTO=none
  
<nowiki># lvcreate -L 8G -v -n Fedora Xen</nowiki>
+
DEFROUTE=yes
  
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 :
+
IPV4_FAILURE_FATAL=no
  
[[Image:Figure_27-_lvcreate.png|top|600px|none|thumb]]
+
IPV6INIT=yes
  
===== <span style="color:#00000a;">Figure 27 : lvcreate.=====
+
IPV6_AUTOCONF=yes
  
Let me to see our LVM via “vgdisplay” command :
+
IPV6_DEFROUTE=yes
  
<nowiki># vgdisplay | more</nowiki>
+
IPV6_FAILURE_FATAL=no
  
[[Image:Figure_28-_vgdisplay-1.png|top|600px|none|thumb]]
+
NAME=enp7s0
  
===== <span style="color:#00000a;">Figure 28 : vgdisplay-1.=====
+
UUID=5e520f04-b32c-4116-b61f-89c190868edc
  
[[Image:Figure_29-_vgdisplay-2.png|top|600px|none|thumb]]
+
ONBOOT=yes
  
===== <span style="color:#00000a;">Figure 29 : vgdisplay-2.=====
+
#IPADDR=172.30.9.20<
  
 +
#PREFIX=24
  
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”.
+
#GATEWAY=172.30.9.254
  
 +
#DNS1=172.30.9.1
  
 +
IPV6_PEERDNS=yes
  
 +
IPV6_PEERROUTES=yes
  
== {{anchor|Toc476606916}} <span style="color:#00000a;">Networking in Xen</span> ==
+
IPV6_PRIVACY=no
  
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.
+
NM_CONTROLLED=no
 +
 
 +
BRIDGE=br0
 +
</syntaxhighlight>
  
It is true that Virtual Machines share your interfaces but it is not true that you must not concern about the security.
+
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.
  
The Xen Project support some kind of networking that we will show you them here :
+
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 :
  
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"># systemctl restart network.service</syntaxhighlight>
  
Names are personalisation and you can select other names.
+
After it, you can see current configuration via “ifconfig” command as below :
  
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).
+
<syntaxhighlight lang="sh">
 +
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  
 +
inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255
  
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.
+
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
  
 +
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
  
OK, Xen need bridge for running and we want to show that you how you can create a Bridge for The Xen Project.
+
RX packets 846 bytes 62175 (60.7 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.
+
RX errors 0 dropped 0 overruns 0 frame 0
  
My Current config are :
+
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
 
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>
 
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
Line 339: Line 422:
 
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
 
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
  
RX packets 989 bytes 84310 (82.3 KiB)
+
RX packets 5479 bytes 468651 (457.6 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 558 bytes 75815 (74.0 KiB)
  
 
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
 
+
<syntaxhighlight lang="sh">
 
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
 
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  
Line 363: Line 447:
  
 
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 +
</syntaxhighlight>
  
 
+
<syntaxhighlight lang="sh">
 
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
 
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  
Line 378: Line 463:
  
 
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.
  
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.
+
Our network is ready and we must create a Guest config.  
  
I want to create a bridge that use this static IP, So I create a file via below command :
+
== 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.
  
<nowiki># touch /etc/sysconfig/network-scripts/ifcfg-br0</nowiki>
+
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.
  
Then open it via an editor like “nano” and fill it with below information :
+
First of all, We must create a config file for our VM. Let me to create it via “touch” command in Linux :
  
DEVICE=br0
+
<syntaxhighlight lang="sh"># touch /etc/xen/windows.cfg</syntaxhighlight>
  
TYPE=Bridge
+
Then, I open it via an editor like “nano” as below :
  
BOOTPROTO=none
+
<syntaxhighlight lang="sh"># nano /etc/xen/windows.cfg</syntaxhighlight>
  
ONBOOT=yes
+
And fill this file via below information :
  
IPADDR=172.30.9.20
+
<syntaxhighlight lang="sh">
 +
name = "Windows7"
  
PREFIX=24
+
builder = "hvm"
  
GATEWAY=172.30.9.254
+
vcpus = 4
  
DNS1=172.30.9.1
+
memory = "4096"
  
DELAY=0
+
maxmex= "8192"
  
NM_CONTROLLED=no
+
vif=['bridge=br0']
  
 +
disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r']
  
But, If your real NIC use DHCP protocol then you should use below config for Bridge :
+
vnc="1"
  
 +
vnclisten="172.30.9.20"
  
DEVICE=br0
+
vncconsole="0"
  
TYPE=Bridge
+
boot="dc"
  
BOOTPROTO=dhcp
+
stdvga=1
  
ONBOOT=yes
+
videoram=32
  
DELAY=0
+
on_poweroff = "destroy"
  
NM_CONTROLLED=no
+
on_reboot = "restart"
  
 +
on_crash = "restart"
 +
</syntaxhighlight>
  
After it, I must change my real NIC configuration, So I open it via an editor :
+
I must tell you something about this file :
  
<nowiki># nano /etc/sysconfig/network-scripts/ifcfg-enp7s0</nowiki>
+
* 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.
  
HWADDR=50:E5:49:40:C4:8F
+
* 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.
  
TYPE=Ethernet
+
* 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.
  
BOOTPROTO=none
+
* 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).
  
DEFROUTE=yes
 
  
IPV4_FAILURE_FATAL=no
+
Let us start our Guest. Just type below command :
  
IPV6INIT=yes
+
<syntaxhighlight lang="sh"># xl create /etc/xen/windows.cfg</syntaxhighlight>
  
IPV6_AUTOCONF=yes
+
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.
  
IPV6_DEFROUTE=yes
+
After it write below command :
  
IPV6_FAILURE_FATAL=no
+
<syntaxhighlight lang="sh"># xl list</syntaxhighlight>
  
NAME=enp7s0
+
and you can see something like below :
  
UUID=5e520f04-b32c-4116-b61f-89c190868edc
+
<syntaxhighlight lang="sh">
 +
Name ID Mem VCPUsStateTime(s)
  
ONBOOT=yes
+
Domain-0 0 3659 8 r----- 887.6
  
<nowiki>#IPADDR=172.30.9.20</nowiki>
+
Windows7 19 4096 4 -b---- 23.1
 +
</syntaxhighlight>
  
<nowiki>#PREFIX=24</nowiki>
+
As you see, “Windows7” is running and we just need connect to it via “vncviewer”. But you must did something on your Firewall.
  
<nowiki>#GATEWAY=172.30.9.254</nowiki>
+
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.
  
<nowiki>#DNS1=172.30.9.1</nowiki>
+
I use “netstat -nat” command for show our current network connections :
  
IPV6_PEERDNS=yes
+
<syntaxhighlight lang="sh"># netstat -nat
  
IPV6_PEERROUTES=yes
+
Active Internet connections (servers and established)
  
IPV6_PRIVACY=no
+
Proto Recv-Q Send-Q Local Address Foreign Address State
  
NM_CONTROLLED=no
+
tcp 0 0 172.30.9.20:5900 0.0.0.0:* LISTEN
  
BRIDGE=br0
+
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
  
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.
+
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
  
If my NIC use DHCP protocol then I didn't need any extra works.
+
tcp 0 0 172.30.9.20:22 172.30.10.18:49824 ESTABLISHED
  
Everything is ready and I must restart my network service for take affect :
+
tcp6 0 0 :::9090 :::* LISTEN
  
<nowiki># systemctl restart network.service</nowiki>
+
tcp6 0 0 :::22 :::* LISTEN
 +
</syntaxhighlight>
  
After it, you can see current configuration via “ifconfig” command as below :
+
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 :
  
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
+
1- First of all, Install a tool like “vncviewer” on your Linux Distro.
  
inet 172.30.9.20 netmask 255.255.255.0 broadcast 172.30.9.255
+
2- Depend on your Linux Distro (Dom0) you must use “iptables” for open VNC Port on Dom0 :
  
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
+
<syntaxhighlight lang="sh"># iptables -A INPUT -p tcp --dport 5900 -j ACCEPT</syntaxhighlight>
  
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
+
<syntaxhighlight lang="sh"># iptables-save</syntaxhighlight>
  
RX packets 846 bytes 62175 (60.7 KiB)
+
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.
  
RX errors 0 dropped 0 overruns 0 frame 0
+
We ready ready to connect to our Xen Server :
  
TX packets 129 bytes 11550 (11.2 KiB)
+
<syntaxhighlight lang="sh"># vncviewer 172.30.9.20:5900</syntaxhighlight>
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
And after it, A window displayed and we can do Windows install process:
  
 +
[[Image:Figure_30-_Windows_7_on_Xen.png|top|600px|none|thumb|Figure 30 : Windows 7 on Xen.]]
  
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
+
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 :
  
inet6 fe80::52e5:49ff:fe40:c48f prefixlen 64 scopeid 0x20<link>
+
<syntaxhighlight lang="sh">
 +
vncpasswd=”Your Password”
 +
</syntaxhighlight>
 +
After it, When you want view your VM via VNC you must enter a password :
  
ether 50:e5:49:40:c4:8f txqueuelen 1000 (Ethernet)
+
<syntaxhighlight lang="sh">
 +
vncviewer 172.30.9.20:5900
  
RX packets 5479 bytes 468651 (457.6 KiB)
+
Connected to RFB server, using protocol version 3.8
  
RX errors 0 dropped 0 overruns 0 frame 0
+
Performing standard VNC authentication
  
TX packets 558 bytes 75815 (74.0 KiB)
+
Password:
 +
</syntaxhighlight>
  
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+
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_do_I_change_the_resolution_of_Xen_PV_domU_vfb_graphical_VNC_console.3F]
  
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
+
[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 127.0.0.1 netmask 255.0.0.0
+
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 ::1 prefixlen 128 scopeid 0x10<host>
+
[[Image:Figure_31-_Static_IP.png|top|600px|none|thumb|Figure 31 : Static IP.]]
  
loop txqueuelen 1 (Local Loopback)
+
When you create another VM:
  
RX packets 83 bytes 9332 (9.1 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 83 bytes 9332 (9.1 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
  
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
+
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
  
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
+
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
  
ether 52:54:00:8b:c5:55 txqueuelen 1000 (Ethernet)
+
tcp 0 0 172.30.9.20:5900 172.30.10.18:33869 ESTABLISHED
  
RX packets 0 bytes 0 (0.0 B)
+
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 0 bytes 0 (0.0 B)
+
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
  
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.
+
Name ID Mem VCPUsStateTime(s)
  
Our network is ready and we must create a Guest config.  
+
Domain-0 0 1590 8 r----- 192.7
  
 +
Windows7 9 4096 4 -b---- 21.0
  
 +
linux 10 2048 1 r----- 64.8
 +
</syntaxhighlight>
  
 +
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 :
  
 +
<syntaxhighlight lang="sh">
 +
vif=['bridge=br0','mac=00:16:17:a5:6y:89,bridge=virbr0']
 +
</syntaxhighlight>
  
'''''Installing Windows as HVM domainU Guest'''''
+
The “mac” defined the MAC address for our NIC.
  
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 can use our first Bridge(br0) for adding more than NIC too but we should add a MAC address fpr each NIC :
  
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.
+
<syntaxhighlight lang="sh">
 +
vif=['bridge=br0,mac=00:13:r6:45:g6:9o','mac=00:16:17:a5:6y:89,bridge=br0']
 +
</syntaxhighlight>
  
First of all, We must create a config file for our VM. Let me to create it via “touch” command in Linux :
+
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.
  
<nowiki># touch /etc/xen/windows.cfg</nowiki>
+
== 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 :
  
Then, I open it via an editor like “nano” as below :
+
<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>
  
 +
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”.
  
<nowiki># nano /etc/xen/windows.cfg</nowiki>
+
== {{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?
  
And fill this file via below information :
+
For example, I run “xl list” and the output is as below :
  
 +
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xl list
  
name = "Windows7"
+
Name ID Mem VCPUsStateTime(s)
  
builder = "hvm"
+
Domain-0 0 1590 8 r----- 1211.3
  
vcpus = 4
+
OpenSUSE 44 2048 1 r----- 4.6
 +
</syntaxhighlight>
  
memory = "4096"
+
I will tel you something about these words :
  
maxmex= "8192"
+
* r - running
  
vif=['bridge=br0']
+
The domain is currently running.
  
disk=['phy:/dev/Xen/Fedora,hda,w','file:/home/mohsen/windows7.iso,hdc:cdrom,r']
+
* b - blocked
  
vnc="1"
+
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.
  
vnclisten="172.30.9.20"
+
* p - paused
  
vncconsole="0"
+
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.
  
boot="dc"
+
* s - shutdown
  
stdvga=1
+
The guest has requested to be shutdown, rebooted or suspended.
  
videoram=32
+
* c - crashed
  
on_poweroff = "destroy"
+
The domain has crashed. It may if the domain has been configured not to restart on crash.
  
on_reboot = "restart"
+
* d - dying
  
on_crash = "restart"
+
The domain is in process of dying, but hasn't completely shutdown or crashed.
  
 +
In below example, my “OpenSUSE” VM is running and established :
  
I must tell you something about this file :
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xl list
  
●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.
+
Name ID Mem VCPUsStateTime(s)
  
●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.
+
Domain-0 0 1590 8 r----- 1245.3
  
●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.
+
OpenSUSE 44 2048 2 -b---- 127.4
 +
</syntaxhighlight>
  
●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).
+
Then, I run below command for “Pause” it :
  
 +
<syntaxhighlight lang="sh"># xl pause OpenSUSE</syntaxhighlight>
  
 +
and my current state is:
  
 +
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xl list
  
Let us start our Guest. Just type below command :
+
Name ID Mem VCPUsStateTime(s)
  
<nowiki># xl create /etc/xen/windows.cfg</nowiki>
+
Domain-0 0 1590 8 r----- 1248.0
  
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.
+
OpenSUSE 44 2048 2 --p--- 127.5
 +
</syntaxhighlight>
  
After it write below command :
+
For “unpause” a VM you can use below command :
  
<nowiki># xl list</nowiki>
+
<syntaxhighlight lang="sh"># xl unpause OpenSUSE
  
and you can see something like below :
+
[root@localhost ~]# xl list
  
 
Name ID Mem VCPUsStateTime(s)
 
Name ID Mem VCPUsStateTime(s)
  
Domain-0 0 3659 8 r----- 887.6
+
Domain-0 0 1590 8 r----- 1257.0
  
Windows7 19 4096 4 -b---- 23.1
+
OpenSUSE 44 2048 2 -b---- 128.3
 +
</syntaxhighlight>
  
 +
Add USB Devices to your VM
  
As you see, “Windows7” is running and we just need connect to it via “vncviewer”. But you must did something on your Firewall.
+
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 :
  
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.
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lsusb
  
I use “netstat -nat” command for show our current network connections :
+
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
  
<nowiki># netstat -nat</nowiki>
+
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
Active Internet connections (servers and established)
+
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
Proto Recv-Q Send-Q Local Address Foreign Address State
+
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
tcp 0 0 172.30.9.20:5900 0.0.0.0:* LISTEN
+
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
+
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
  
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
+
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  
tcp 0 0 172.30.9.20:22 172.30.10.18:49824 ESTABLISHED
+
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
</syntaxhighlight>
  
tcp6 0 0 :::9090 :::* LISTEN
+
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 :
  
tcp6 0 0 :::22 :::* LISTEN
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lsusb
  
 +
Bus 002 Device 003: ID 03f0:5607 Hewlett-Packard
  
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 :
+
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  
1- First of all, Install a tool like “vncviewer” on your Linux Distro.
+
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
2- Depend on your Linux Distro (Dom0) you must use “iptables” for open VNC Port on Dom0 :
+
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
<nowiki># iptables -A INPUT -p tcp --dport 5900 -j ACCEPT</nowiki>
+
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
<nowiki># iptables-save</nowiki>
+
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  
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.
+
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  
We ready ready to connect to our Xen Server :
+
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
  
<nowiki># vncviewer 172.30.9.20:5900</nowiki>
+
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  
And after it, A window displayed and we can do Windows install process:
+
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
</syntaxhighlight>
  
[[Image:Figure_30-_Windows_7_on_Xen.png|top|600px|none|thumb]]
+
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.
  
===== <span style="color:#00000a;">Figure 30 : Windows 7 on Xen.=====
+
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 :
  
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 :
+
[[Image:Figure_32-_USB_ID_Database.png|top|600px|none|thumb|Figure 32 : USB ID Database.]]
  
vncpasswd=”Your Password”
 
  
After it, When you want view your VM via VNC you must enter a password :
+
OK, We want add out Pendrive to our VM and copy and paste some files from/to it from our VM.
  
vncviewer 172.30.9.20:5900
+
Fist of all, You must open your VM cofing file via an editor like “nano” :
  
Connected to RFB server, using protocol version 3.8
+
<syntaxhighlight lang="sh"># nano /etc/xen/linux.cg</syntaxhighlight>
  
Performing standard VNC authentication
+
Then add below lines to your config file :
  
Password:
+
<syntaxhighlight lang="sh">
 +
usb="1"
  
 +
usbdevice=['host:03f0:5607']
 +
</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 :
+
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.
  
[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]
+
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 :
  
[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]  
+
[[Image:Figure_33-_USB_Mounted.png|top|600px|none|thumb|Figure 33: USB Mounted.]]
  
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 :
+
== {{anchor|Toc476606918}} 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.
  
[[Image:Figure_31-_Static_IP.png|top|600px|none|thumb]]
+
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 :
  
===== <span style="color:#00000a;">Figure 31 : Static IP.=====
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lsblk
  
 +
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  
When you create another VM:
+
sda 8:0 0 931.5G 0 disk
  
[root@localhost ~]# netstat -nat
+
├─sda1 8:1 0 316G 0 part
  
Active Internet connections (servers and established)
+
│ ├─fedora-root00 253:0 0 300G 0 lvm /
  
Proto Recv-Q Send-Q Local Address Foreign Address State
+
│ └─fedora-swap 253:1 0 16G 0 lvm [SWAP]
  
tcp 0 0 172.30.9.20:5900  0.0.0.0:* LISTEN
+
└─sda2 8:2 0 615.5G 0 part
  
tcp 0 0 172.30.9.20:5901 0.0.0.0:* LISTEN
+
├─Xen-Fedora 253:2 0 20G 0 lvm
  
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
+
└─Xen-linux 253:3 0 20G 0 lvm
  
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
+
sdb 8:16 1 15.1G 0 disk
  
tcp 0 0 172.30.9.20:5900 172.30.10.18:33869 ESTABLISHED
+
sr0 11:0 1 158.5M 0 rom
 +
</syntaxhighlight>
  
tcp 0 0 172.30.9.20:22 172.30.10.18:55000 ESTABLISHED
+
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 :
  
tcp 0 180 172.30.9.20:22 172.30.10.18:54616 ESTABLISHED
+
<syntaxhighlight lang="sh">
 +
disk=['phy:/dev/sr0,hdc:cdrom,r']
 +
</syntaxhighlight>
  
tcp6 0 0 :::9090 :::* LISTEN
+
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.
  
tcp6 0 0 :::22 :::* LISTEN
+
If DVD Drive not detected automatically then use below command :
  
 +
<syntaxhighlight lang="sh"># eject</syntaxhighlight>
  
[root@localhost ~]# xl list
+
This command eject DVD from the Guest and if you change CD or DVD then for detect the insertion use below command :
  
Name ID Mem VCPUsStateTime(s)
+
<syntaxhighlight lang="sh"># eject -t</syntaxhighlight>
  
Domain-0 0 1590 8 r----- 192.7
+
== {{anchor|Toc476606919}} Create a VM via .img ==
  
Windows7 9 4096 4 -b---- 21.0
+
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.
  
linux 10 2048 1 r----- 64.8
+
First of all, Please let me to create a directory via “mkdir” for our Virtual HDD :
  
 +
<syntaxhighlight lang="sh"># mkdir Windows</syntaxhighlight>
  
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.
+
change to “Windows” directory via “cd” command :
  
For adding more than one NIC you can use :
+
<syntaxhighlight lang="sh"># cd Windows/</syntaxhighlight>
  
vif=['bridge=br0','mac=00:16:17:a5:6y:89,bridge=virbr0']
+
And run below command for create a Virtual HDD about 40GB :
  
 +
<syntaxhighlight lang="sh"># dd if=/dev/zero of=windows.img bs=1M count=40000</syntaxhighlight>
  
The “mac” defined the MAC address for our NIC.
+
<syntaxhighlight lang="sh">
 +
[root@localhost Windows]# dd if=/dev/zero of=windows.img bs=1M count=40000
  
We can use our first Bridge(br0) for adding more than NIC too but we should add a MAC address fpr each NIC :
+
40000+0 records in
  
vif=['bridge=br0,mac=00:13:r6:45:g6:9o','mac=00:16:17:a5:6y:89,bridge=br0']
+
40000+0 records out
  
 +
41943040000 bytes (42 GB) copied, 332.735 s, 126 MB/s
 +
</syntaxhighlight>
  
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.
+
If you list files and directory via “ls” command then you will see something like below :
  
 +
<syntaxhighlight lang="sh">
 +
[root@localhost Windows]# ls
  
'''''Share storage between VMS'''''
+
windows.img
 +
</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 :
+
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.
  
disk=['phy:/dev/Xen/Fedora,hda,w','phy:/dev/Xen/linux,hdb,w','file:/home/mohsen/Windows7.iso,hdc:cdrom,r']
+
Open your VM config file via an editor like “Nano” and add below line as your HDD :
  
 +
<syntaxhighlight lang="sh">
 +
disk=['file:/home/mohsen/Windows/windows.img,hda,w']
 +
</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”.
+
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 :
  
== {{anchor|Toc476606917}} <span style="color:#00000a;">VM States in The Xen Project</span> ==
+
[[Image:Figure_34-_Windows_10_Error..png|top|600px|none|thumb|Figure 34 : Windows 10 Error.]]
  
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?
+
== {{anchor|Toc476606920}} VGA Passthrough ==
  
For example, I run “xl list” and the output is as below :
+
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 :)
  
[root@localhost ~]# xl list
+
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.
  
Name ID Mem VCPUsStateTime(s)
+
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.
  
Domain-0 0 1590 8 r----- 1211.3
+
We use Fedora and “-w” parameter not exist and thus we must use below commands :
  
OpenSUSE 44 2048 1 r----- 4.6
+
First of all, Run below command to see a list of Hardware :
  
 +
<syntaxhighlight lang="sh"># lspci</syntaxhighlight>
  
I will tel you something about these words :
+
Then run :
  
●r - running
+
<syntaxhighlight lang="sh"># lspci -vv -s PCI ID | grep FLR</syntaxhighlight>
  
The domain is currently running.
+
For example :
  
●b - blocked
+
<syntaxhighlight lang="sh"># lspci -vv -s 00:02.0 | grep FLR</syntaxhighlight>
  
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.
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# lspci -vv -s 00:02.0 | grep FLR
  
●p - paused
+
AFCap: TP+ FLR+
  
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.
+
AFCtrl: FLR-
 +
</syntaxhighlight>
  
●s - shutdown
+
OK, We consider that your device support FLR and I will tell you that how you can attach it.
  
The guest has requested to be shutdown, rebooted or suspended.
+
First of all, Execute below command :
  
●c - crashed
+
<syntaxhighlight lang="sh"># modprobe xen-pciback</syntaxhighlight>
  
The domain has crashed. It may if the domain has been configured not to restart on crash.
+
Create a file via “touch” command and fill it with below information :
  
●d - dying
+
<syntaxhighlight lang="sh">
 +
remove_device () {
  
The domain is in process of dying, but hasn't completely shutdown or crashed.
+
BDF=$1
  
 +
# Unbind a PCI function from its driver as necessary
  
In below example, my “OpenSUSE” VM is running and established :
+
[ ! -e /sys/bus/pci/devices/$BDF/driver/unbind ] || \
  
[root@localhost ~]# xl list
+
echo -n $BDF > /sys/bus/pci/devices/$BDF/driver/unbind
  
Name ID Mem VCPUsStateTime(s)
+
# Add a new slot to the PCI Backend's list
  
Domain-0 0 1590 8 r----- 1245.3
+
echo -n $BDF > /sys/bus/pci/drivers/pciback/new_slot
  
OpenSUSE 44 2048 2 -b---- 127.4
+
# Now that the backend is watching for the slot, bind to it
  
 +
echo -n $BDF > /sys/bus/pci/drivers/pciback/bind
  
Then, I run below command for “Pause” it :
+
}
  
<nowiki># xl pause OpenSUSE</nowiki>
+
remove_device "Your PCI ID"
 +
# For example : remove_device "0000:01:00.1"
  
and my current state is:
+
</syntaxhighlight>
  
[root@localhost ~]# xl list
+
Save the file and run this script via “sh yourfilename”.
  
Name ID Mem VCPUsStateTime(s)
+
After it, You must edit your VM config file. Open you config file via an editor like “Nano” :
  
Domain-0 0 1590 8 r----- 1248.0
+
<syntaxhighlight lang="sh"># nano /etc/xen/windows.cfg</syntaxhighlight>
  
OpenSUSE 44 2048 2 --p--- 127.5
+
Then add below line to your config file :
  
 +
pci=['Your PCI ID','Your PCI ID']
  
For “unpause” a VM you can use below command :
+
<syntaxhighlight lang="sh"># For example : pci=['01:00.1','00:1a.0']</syntaxhighlight>
  
<nowiki># xl unpause OpenSUSE</nowiki>
 
  
[root@localhost ~]# xl list
+
Then run your VM and your PCI device will attached to your VM.
  
Name ID Mem VCPUsStateTime(s)
+
== {{anchor|Toc476606921}} Swap ==
  
Domain-0 0 1590 8 r----- 1257.0
+
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.
  
OpenSUSE 44 2048 2 -b---- 128.3
+
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 :
  
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 :
+
<syntaxhighlight lang="sh"># swapon --show</syntaxhighlight>
  
[root@localhost ~]# lsusb
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# swapon --show
  
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
+
NAME TYPE SIZE USED PRIO
  
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
/dev/dm-1 partition 16G 0B -1
  
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
[root@localhost ~]#
 +
</syntaxhighlight>
  
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
As you see, My system has 16GB Swap space.
  
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
You can use “free -h” command too :
  
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# free -h
  
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
+
total used free shared buff/cache available
  
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
+
Mem: 7.5G 186M 7.0G 4.4M 325M 7.2G
  
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
Swap: 15G 0B 15G
  
 +
[root@localhost ~]#
 +
</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 :
+
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.
  
[root@localhost ~]# lsusb
+
First of all, We use “dd” command for create an image :
  
Bus 002 Device 003: ID 03f0:5607 Hewlett-Packard
+
<syntaxhighlight lang="sh"># dd if=/dev/zero of=linuxswap.swap bs=1024 count=”Your size”</syntaxhighlight>
  
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
+
For example :
  
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
<syntaxhighlight lang="sh">
 +
[root@localhost mohsen]# dd if=/dev/zero of=linuxswap.swap bs=1024 count=4096000
  
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
4096000+0 records in
  
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
4096000+0 records out
  
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
+
4194304000 bytes (4.2 GB) copied, 32.8729 s, 128 MB/s
 +
</syntaxhighlight>
  
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
Then :
  
Bus 001 Device 003: ID 13ba:0017 PCPlay PS/2 Keyboard+Mouse Adapter
+
<syntaxhighlight lang="sh">
 +
[root@localhost mohsen]# mkswap linuxswap.swap
  
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
+
mkswap: linuxswap.swap: insecure permissions 0644, 0600 suggested.
  
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
Setting up swapspace version 1, size = 3.9 GiB (4194299904 bytes)
  
 +
no label, UUID=f2464b51-c7ef-4990-8cb6-8d50d151b52e
 +
</syntaxhighlight>
  
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.
+
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 :
  
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.
+
<syntaxhighlight lang="sh">
 +
file:/YourPath/linuxswap.swap,hdb,w
 +
</syntaxhighlight>
  
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 :
+
The complete line is something like :
  
<div style="text-align:center;">[[Image:Figure_32-_USB_ID_Database.png|top|600px|none|thumb]]</div>
+
<syntaxhighlight lang="sh">
 +
disk=['phy:/dev/Xen/linux,hda,w','file:/home/mohsen/linuxswap.swap,hdb,w']
 +
</syntaxhighlight>
  
===== <span style="color:#00000a;">Figure 32 : USB ID Database.=====
+
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 :
  
 +
<syntaxhighlight lang="sh"># swapon /dev/hdb</syntaxhighlight>
  
OK, We want add out Pendrive to our VM and copy and paste some files from/to it from our VM.
+
[[Image:Figure_35-_Swap_Space.png|top|600px|none|thumb|Figure 35 : Swap Space.]]
  
Fist of all, You must open your VM cofing file via an editor like “nano” :
 
  
<nowiki># nano /etc/xen/linux.cg</nowiki>
+
As you see, My Linux had 2GB of Swap and after it my Linux VM has 5.9GB Swap Space.
  
Then add below lines to your config file :
+
For mount it automatically via boot just doing following steps :
  
usb="1"
+
1- Open “fstab” file from “/etc/fstab” via an editor like “nano”.
  
usbdevice=['host:03f0:5607']
+
2- add below line :
  
 +
/dev/XXX none swap defaults 0 0
  
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.
+
<syntaxhighlight lang="sh"># For example : /dev/hdb none swap defaults 0 0</syntaxhighlight>
  
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 :
 
  
 +
3- Save file and reboot your system.
  
<div style="text-align:center;">[[Image:Figure_33-_USB_Mounted.png|top|600px|none|thumb]]</div>
 
===== <span style="color:#00000a;">Figure 33: USB Mounted.=====
 
  
 +
== {{anchor|Toc476606922}} 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 :
  
== {{anchor|Toc476606918}} <span style="color:#00000a;">Use Physical CD/DVD ROM</span> ==
+
<syntaxhighlight lang="sh"># yum install debootstrap perl-Text-Template perl-Config-IniFiles perl-File-Slurp perl-File-Which perl-Data-Dumper</syntaxhighlight>
  
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.
+
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 :
  
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 :
+
<syntaxhighlight lang="sh">
 +
[root@localhost xen-tools-4.6.2]# make install
  
[root@localhost ~]# lsblk
+
for i in hooks/*/*-*; do chmod 755 $i; done
  
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
+
chmod 755 hooks/common.sh
  
sda 8:0 0 931.5G 0 disk
+
chmod 644 etc/*.conf
  
├─sda1 8:1 0 316G 0 part
+
chmod 644 etc/xm.tmpl
  
│ ├─fedora-root00 253:0 0 300G 0 lvm /
+
chmod 644 etc/xm-nfs.tmpl
  
│ └─fedora-swap 253:1 0 16G 0 lvm [SWAP]
+
chmod 644 misc/*
  
└─sda2 8:2 0 615.5G 0 part
+
mkdir -p /usr/bin
  
├─Xen-Fedora 253:2 0 20G 0 lvm
+
cp bin/xen-create-image /usr/bin
  
└─Xen-linux 253:3 0 20G 0 lvm
+
cp bin/xen-create-nfs /usr/bin
  
sdb 8:16 1 15.1G 0 disk
+
cp bin/xt-customize-image /usr/bin
  
sr0 11:0 1 158.5M 0 rom
+
cp bin/xt-install-image /usr/bin
  
 +
cp bin/xt-create-xen-config /usr/bin
  
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 bin/xen-delete-image /usr/bin
  
disk=['phy:/dev/sr0,hdc:cdrom,r']
+
cp bin/xen-list-images /usr/bin
  
 +
cp bin/xen-update-image /usr/bin
  
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 bin/xt-guess-suite-and-mirror /usr/bin
  
If DVD Drive not detected automatically then use below command :
+
chmod 755 /usr/bin/xen-create-image
  
<nowiki># eject</nowiki>
+
chmod 755 /usr/bin/xen-create-nfs
  
This command eject DVD from the Guest and if you change CD or DVD then for detect the insertion use below command :
+
chmod 755 /usr/bin/xt-customize-image
  
<nowiki># eject -t</nowiki>
+
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
  
=== {{anchor|Toc476606919}} <span style="color:#00000a;">Create a VM via .img</span> ===
+
chmod 755 /usr/bin/xen-update-image
  
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.
+
chmod 755 /usr/bin/xt-guess-suite-and-mirror
  
First of all, Please let me to create a directory via “mkdir” for our Virtual HDD :
+
mkdir -p /etc/xen-tools
  
<nowiki># mkdir Windows</nowiki>
+
if [ -d /etc/xen-tools/hook.d ]; then mv /etc/xen-tools/hook.d/ /etc/xen-tools/hook.d.obsolete ; fi
  
change to “Windows” directory via “cd” command :
+
mkdir -p /etc/xen-tools/skel/
  
<nowiki># cd Windows/</nowiki>
+
mkdir -p /etc/xen-tools/role.d/
  
And run below command for create a Virtual HDD about 40GB :
+
mkdir -p /etc/xen-tools/partitions.d/
  
<nowiki># dd if=/dev/zero of=windows.img bs=1M count=40000</nowiki>
+
cp etc/*.conf /etc/xen-tools/
  
[root@localhost Windows]# dd if=/dev/zero of=windows.img bs=1M count=40000
+
cp etc/xm.tmpl /etc/xen-tools/
  
40000+0 records in
+
cp etc/xm-nfs.tmpl /etc/xen-tools/
  
40000+0 records out
+
cp partitions/*-* /etc/xen-tools/partitions.d/
  
41943040000 bytes (42 GB) copied, 332.735 s, 126 MB/s
+
mkdir -p /usr/share/bash-completion/completions/
  
 +
cp misc/xen-tools.bash-completion /usr/share/bash-completion/completions/xen-tools
  
If you list files and directory via “ls” command then you will see something like below :
+
mkdir -p /etc/initramfs-tools/conf.d/
  
[root@localhost Windows]# ls
+
cp misc/xen-tools.initramfs-tools /etc/initramfs-tools/conf.d/xen-tools
  
windows.img
+
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
  
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.
+
mkdir -p /usr/share/xen-tools/centos-4.d/
  
Open your VM config file via an editor like “Nano” and add below line as your HDD :
+
mkdir -p /usr/share/xen-tools/centos-5.d/
  
disk=['file:/home/mohsen/Windows/windows.img,hda,w']
+
mkdir -p /usr/share/xen-tools/centos-6.d/
  
As you see, We used “file” instead of “phy”.
+
mkdir -p /usr/share/xen-tools/fedora-core-6.d/
  
 +
cp -R hooks/centos-4/*-* /usr/share/xen-tools/centos-4.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 :
+
cp -R hooks/centos-5/*-* /usr/share/xen-tools/centos-5.d
  
<div style="text-align:center;">[[Image:Figure_34-_Windows_10_Error..png|top|600px|none|thumb]]</div>
+
cp -R hooks/centos-6/*-* /usr/share/xen-tools/centos-6.d
  
===== <span style="color:#00000a;">Figure 34 : Windows 10 Error.=====
+
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
  
=== {{anchor|Toc476606920}} <span style="color:#00000a;">VGA Passthrough</span> ===
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-8.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 fedora-core-6.d fedora-core-9.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 fedora-core-6.d fedora-core-10.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 fedora-core-6.d fedora-core-11.d
  
We use Fedora and “-w” parameter not exist and thus we must use below commands :
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-12.d
  
First of all, Run below command to see a list of Hardware :
+
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
  
<nowiki># lspci</nowiki>
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-15.d
  
Then run :
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-16.d
  
<nowiki># lspci -vv -s PCI ID | grep FLR</nowiki>
+
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-17.d
  
For example :
+
mkdir -p /usr/share/xen-tools/debian.d/
  
<nowiki># lspci -vv -s 00:02.0 | grep FLR</nowiki>
+
cp -R hooks/debian/*-* /usr/share/xen-tools/debian.d
  
[root@localhost ~]# lspci -vv -s 00:02.0 | grep FLR
+
cd /usr/share/xen-tools/ && ln -s debian.d sarge.d
  
AFCap: TP+ FLR+
+
cd /usr/share/xen-tools/ && ln -s debian.d etch.d
  
AFCtrl: FLR-
+
cd /usr/share/xen-tools/ && ln -s debian.d lenny.d
  
 +
cd /usr/share/xen-tools/ && ln -s debian.d squeeze.d
  
OK, We consider that your device support FLR and I will tell you that how you can attach it.
+
cd /usr/share/xen-tools/ && ln -s debian.d wheezy.d
  
First of all, Execute below command :
+
cd /usr/share/xen-tools/ && ln -s debian.d jessie.d
  
<nowiki># modprobe xen-pciback</nowiki>
+
cd /usr/share/xen-tools/ && ln -s debian.d stretch.d
  
Create a file via “touch” command and fill it with below information :
+
cd /usr/share/xen-tools/ && ln -s debian.d sid.d
  
remove_device () {
+
cd /usr/share/xen-tools/ && ln -s debian.d unstable.d
  
BDF=$1
+
cd /usr/share/xen-tools/ && ln -s debian.d testing.d
  
<nowiki># Unbind a PCI function from its driver as necessary</nowiki>
+
cd /usr/share/xen-tools/ && ln -s debian.d stable.d
  
[ ! -e /sys/bus/pci/devices/$BDF/driver/unbind ] || \
+
cd /usr/share/xen-tools/ && ln -s debian.d oldstable.d
  
echo -n $BDF > /sys/bus/pci/devices/$BDF/driver/unbind
+
cd /usr/share/xen-tools/ && ln -s debian.d oldoldstable.d
  
<nowiki># Add a new slot to the PCI Backend's list</nowiki>
+
mkdir -p /usr/share/xen-tools/gentoo.d/
  
echo -n $BDF > /sys/bus/pci/drivers/pciback/new_slot
+
cp -R hooks/gentoo/*-* /usr/share/xen-tools/gentoo.d
  
<nowiki># Now that the backend is watching for the slot, bind to it</nowiki>
+
mkdir -p /usr/share/xen-tools/dapper.d/
  
echo -n $BDF > /sys/bus/pci/drivers/pciback/bind
+
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/
  
remove_device "Your PCI ID"
+
cd /usr/share/xen-tools/ && ln -s edgy.d feisty.d
  
<nowiki># For example : remove_device "0000:01:00.1"</nowiki>
+
cd /usr/share/xen-tools/ && ln -s edgy.d gutsy.d
  
 +
cd /usr/share/xen-tools/ && ln -s edgy.d hardy.d
  
Save the file and run this script via “sh yourfilename”.
+
mkdir -p /usr/share/xen-tools/intrepid.d/
  
After it, You must edit your VM config file. Open you config file via an editor like “Nano” :
+
cp -R hooks/intrepid/*-* /usr/share/xen-tools/intrepid.d/
  
<nowiki># nano /etc/xen/windows.cfg</nowiki>
+
cd /usr/share/xen-tools/ && ln -s intrepid.d jaunty.d
  
Then add below line to your config file :
+
mkdir -p /usr/share/xen-tools/karmic.d/
  
pci=['Your PCI ID','Your PCI ID']
+
cp -R hooks/karmic/*-* /usr/share/xen-tools/karmic.d/
  
<nowiki># For example : pci=['01:00.1','00:1a.0']</nowiki>
+
cd /usr/share/xen-tools/ && ln -s karmic.d lucid.d
  
 +
cd /usr/share/xen-tools/ && ln -s karmic.d maverick.d
  
Then run your VM and your PCI device will attached to your VM.
+
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
  
== {{anchor|Toc476606921}} <span style="color:#00000a;">Swap</span> ==
+
cd /usr/share/xen-tools/ && ln -s karmic.d trusty.d
  
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.
+
cd /usr/share/xen-tools/ && ln -s karmic.d utopic.d
  
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.
+
cd /usr/share/xen-tools/ && ln -s karmic.d vivid.d
  
For check the Swap space of your system use below command :
+
cd /usr/share/xen-tools/ && ln -s karmic.d wily.d
  
 +
cd /usr/share/xen-tools/ && ln -s karmic.d xenial.d
  
<nowiki># swapon --show</nowiki>
+
cp hooks/common.sh /usr/share/xen-tools
  
[root@localhost ~]# swapon --show
+
cp -r hooks/common /usr/share/xen-tools
  
NAME TYPE SIZE USED PRIO
+
mkdir -p /usr/share/perl5/Xen/Tools
  
/dev/dm-1 partition 16G 0B -1
+
cp ./lib/Xen/Tools/*.pm /usr/share/perl5/Xen/Tools
  
[root@localhost ~]#
+
mkdir -p man
  
 +
cd bin; for i in *-*[!y]; do pod2man --release=4.6.2 --official --section=8 $i ../man/$i.8; done
  
As you see, My system has 16GB Swap space.
+
for i in man/*.8; do gzip --force -9 $i; done
  
You can use “free -h” command too :
+
mkdir -p /usr/share/man/man8/
  
[root@localhost ~]# free -h
+
cp man/*.8.gz /usr/share/man/man8/
 +
</syntaxhighlight>
  
total used free shared buff/cache available
+
OK, “Xen-Tools” installed successfully and you can use it.
  
Mem: 7.5G 186M 7.0G 4.4M 325M 7.2G
+
For install under Debian Dom0 just run :
  
Swap: 15G 0B 15G
+
<syntaxhighlight lang="sh"># apt-get install xen-tools</syntaxhighlight>
  
[root@localhost ~]#
+
Let me to run “xen-create-image” and see what happen :
  
 +
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xen-create-image
  
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.
+
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.
  
First of all, We use “dd” command for create an image :
+
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 802.
 +
</syntaxhighlight>
  
<nowiki># dd if=/dev/zero of=linuxswap.swap bs=1024 count=”Your size”</nowiki>
+
OK, It is an error and can solved via install “perl-Env” package :
  
For example :
+
<syntaxhighlight lang="sh"># yum install perl-Env</syntaxhighlight>
  
[root@localhost mohsen]# dd if=/dev/zero of=linuxswap.swap bs=1024 count=4096000
+
If after install “perl-Env” you got other errors then :
  
4096000+0 records in
+
1- yum install cpan
  
4096000+0 records out
+
2- Then use “cpan” with the package that you see. For example :
  
4194304000 bytes (4.2 GB) copied, 32.8729 s, 128 MB/s
+
<syntaxhighlight lang="sh">
 +
[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.
  
Then :
+
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 814.
 +
</syntaxhighlight>
  
[root@localhost mohsen]# mkswap linuxswap.swap
+
As you see, I got an error about a package with the name “Term::UI module” then I use below command for install it :
  
mkswap: linuxswap.swap: insecure permissions 0644, 0600 suggested.
+
<syntaxhighlight lang="sh"># cpan Term::UI module</syntaxhighlight>
  
Setting up swapspace version 1, size = 3.9 GiB (4194299904 bytes)
+
You may need to doing it for some packages but after it you are ready for work with “Xen-tools”.
  
no label, UUID=f2464b51-c7ef-4990-8cb6-8d50d151b52e
+
OK, I consider you installed all modules and “Xen-tools” is ready for work.
  
 +
I run “xen-create-image” :
  
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 :
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xen-create-image
  
file:/YourPath/linuxswap.swap,hdb,w
+
Couldn't find a useful entry in the sources.list files of the Dom0. Tried:
  
 +
/etc/apt/sources.list
  
The complete line is something like :
+
The '--hostname' argument is mandatory.
  
disk=['phy:/dev/Xen/linux,hda,w','file:/home/mohsen/linuxswap.swap,hdb,w']
+
[root@localhost ~]#
 +
</syntaxhighlight>
  
 +
It is a tool for automate creating. The syntax is straightforward and you can see more options just with “--help” option.
  
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 :
+
<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
  
<nowiki># swapon /dev/hdb</nowiki>
+
[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:
  
<div style="text-align:center;">[[Image:Figure_35-_Swap_Space.png|top|600px|none|thumb]]</div>
+
/etc/apt/sources.list
  
===== <span style="color:#00000a;">Figure 35 : Swap Space.=====
 
  
 +
General Information
  
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 :
+
Hostname : linux.via.xentools
  
1- Open “fstab” file from “/etc/fstab” via an editor like “nano”.
+
Distribution : jessie
  
2- add below line :
+
Mirror : http://httpredir.debian.org/debian
  
/dev/XXX none swap defaults 0 0
+
Partitions : swap 512Mb (swap)
  
<nowiki># For example : /dev/hdb none swap defaults 0 0</nowiki>
+
/ 4Gb (ext3)
  
 +
Image type : sparse
  
3- Save file and reboot your system.
+
Memory size : 128M
  
 +
Kernel path : /boot/vmlinuz-4.4.7-300.fc23.x86_64
  
== {{anchor|Toc476606922}} <span style="color:#00000a;">Using Xen-Tools</span> ==
+
Initrd path : /boot/initrd.img-4.4.7-300.fc23.x86_64
  
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 :
+
Networking Information
  
<nowiki># yum install debootstrap perl-Text-Template perl-Config-IniFiles perl-File-Slurp perl-File-Which perl-Data-Dumper</nowiki>
+
----------------------
  
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 :
+
IP Address 1 : 172.30.9.21 [MAC: 00:16:3E:52:EF:69]
  
 +
Netmask : 255.255.255.0
  
[root@localhost xen-tools-4.6.2]# make install
+
Gateway : 172.30.9.254
  
for i in hooks/*/*-*; do chmod 755 $i; done
 
  
chmod 755 hooks/common.sh
+
Creating partition image: /home/mohsen/domains/linux.via.xentools/swap.img
  
chmod 644 etc/*.conf
+
Done
  
chmod 644 etc/xm.tmpl
 
  
chmod 644 etc/xm-nfs.tmpl
+
Creating swap on /home/mohsen/domains/linux.via.xentools/swap.img
  
chmod 644 misc/*
+
Done
  
mkdir -p /usr/bin
 
  
cp bin/xen-create-image /usr/bin
+
Creating partition image: /home/mohsen/domains/linux.via.xentools/disk.img
  
cp bin/xen-create-nfs /usr/bin
+
Done
  
cp bin/xt-customize-image /usr/bin
 
  
cp bin/xt-install-image /usr/bin
+
Creating ext3 filesystem on /home/mohsen/domains/linux.via.xentools/disk.img
  
cp bin/xt-create-xen-config /usr/bin
+
Done
  
cp bin/xen-delete-image /usr/bin
+
Installation method: debootstrap
  
cp bin/xen-list-images /usr/bin
 
  
cp bin/xen-update-image /usr/bin
+
Running hooks
  
cp bin/xt-guess-suite-and-mirror /usr/bin
+
Done
  
chmod 755 /usr/bin/xen-create-image
 
  
chmod 755 /usr/bin/xen-create-nfs
+
No role scripts were specified. Skipping
  
chmod 755 /usr/bin/xt-customize-image
 
  
chmod 755 /usr/bin/xt-install-image
+
Creating Xen configuration file
  
chmod 755 /usr/bin/xt-create-xen-config
+
Done
  
chmod 755 /usr/bin/xen-delete-image
 
  
chmod 755 /usr/bin/xen-list-images
+
No role scripts were specified. Skipping
  
chmod 755 /usr/bin/xen-update-image
+
Setting up root password
  
chmod 755 /usr/bin/xt-guess-suite-and-mirror
+
Generating a password for the new guest.
  
mkdir -p /etc/xen-tools
+
All done
  
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/
+
Logfile produced at:
  
cp etc/*.conf /etc/xen-tools/
+
/var/log/xen-tools/linux.via.xentools.log
  
cp etc/xm.tmpl /etc/xen-tools/
 
  
cp etc/xm-nfs.tmpl /etc/xen-tools/
+
Installation Summary
  
cp partitions/*-* /etc/xen-tools/partitions.d/
+
---------------------
  
mkdir -p /usr/share/bash-completion/completions/
+
Hostname : linux.via.xentools
  
cp misc/xen-tools.bash-completion /usr/share/bash-completion/completions/xen-tools
+
Distribution : jessie
  
mkdir -p /etc/initramfs-tools/conf.d/
+
MAC Address : 00:16:3E:52:EF:69
  
cp misc/xen-tools.initramfs-tools /etc/initramfs-tools/conf.d/xen-tools
+
IP Address(es) : 172.30.9.21
  
for i in roles/* ; do if [ -f $i ]; then cp $i /etc/xen-tools/role.d; fi ; done
+
SSH Fingerprint : SHA256:oRLrvjgRgIcJkVeuQKJRQEKM656GVD9t4EQOmgrAr0k (DSA)
  
for i in /usr/share/xen-tools/*.d; do if [ -L "$i" ]; then rm -vf "$i"; fi; done
+
SSH Fingerprint : SHA256:vynLLpUihRZ14l7zExPh8CDcGg/PgVjCs2RVe9QbD64 (RSA)
  
mkdir -p /usr/share/xen-tools/centos-4.d/
+
Root Password : z8gCMQGvyumHiQFSjWV9iXd
 +
</syntaxhighlight>
  
mkdir -p /usr/share/xen-tools/centos-5.d/
+
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 :
  
mkdir -p /usr/share/xen-tools/centos-6.d/
+
<syntaxhighlight lang="sh"># xl create /etc/xen/linux.via.xentools.cfg</syntaxhighlight>
  
mkdir -p /usr/share/xen-tools/fedora-core-6.d/
+
You can change “dist” parameter and for Linux Distros that supported, Please look at “/usr/share/xen-tools/.
  
cp -R hooks/centos-4/*-* /usr/share/xen-tools/centos-4.d
+
<syntaxhighlight lang="sh">
 +
[root@localhost boot]# xl create /etc/xen/linux.via.xentools.cfg
  
cp -R hooks/centos-5/*-* /usr/share/xen-tools/centos-5.d
+
Parsing config from /etc/xen/linux.via.xentools.cfg
  
cp -R hooks/centos-6/*-* /usr/share/xen-tools/centos-6.d
+
libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge online [-1] exited with error status 1
  
cp -R hooks/fedora-core-6/*-* /usr/share/xen-tools/fedora-core-6.d
+
libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-4.d
+
libxl: error: libxl_create.c:1362:domcreate_attach_vtpms: unable to add nic devices
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-5.d
+
libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus: /etc/xen/scripts/vif-bridge offline [-1] exited with error status 1
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-7.d
+
libxl: error: libxl_device.c:1078:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-8.d
+
libxl: info: libxl.c:1698:devices_destroy_cb: forked pid 24683 for destroy of domain 15
 +
</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-9.d
+
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.
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-10.d
+
Open your config file that generated by “Xen-Tools” via an editor like “nano” and add below lines to it :
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-11.d
+
<syntaxhighlight lang="sh">
 +
interface=['br0']
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-12.d
+
vif = [ 'ip=172.30.9.21 ,mac=00:16:3E:52:EF:69, bridge=br0' ]
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-13.d
+
vnc="1"
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-14.d
+
vnclisten="172.30.9.20"
 +
</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-15.d
+
I bold the parts that you must adding to your config file.
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-16.d
+
For More information about the Xen-Tools you can read the man page of it via below link :
  
cd /usr/share/xen-tools/ && ln -s fedora-core-6.d fedora-core-17.d
+
http://man.cx/xen-create-image
  
mkdir -p /usr/share/xen-tools/debian.d/
 
  
cp -R hooks/debian/*-* /usr/share/xen-tools/debian.d
+
== {{anchor|Toc476606923}} Monitoring Xen project ==
  
cd /usr/share/xen-tools/ && ln -s debian.d sarge.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.
  
cd /usr/share/xen-tools/ && ln -s debian.d etch.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 :
  
cd /usr/share/xen-tools/ && ln -s debian.d lenny.d
+
[[Image:Figure_36-_Xenmon.png|top|600px|none|thumb|Figure 36 : Xenmon.py.]]
  
cd /usr/share/xen-tools/ && ln -s debian.d squeeze.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 debian.d wheezy.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 debian.d jessie.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 debian.d stretch.d
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# xenmon.py
  
cd /usr/share/xen-tools/ && ln -s debian.d sid.d
+
ms_per_sample = 100
  
cd /usr/share/xen-tools/ && ln -s debian.d unstable.d
+
Initialized with 8 cpu's
  
cd /usr/share/xen-tools/ && ln -s debian.d testing.d
+
CPU Frequency = 3392.37
  
cd /usr/share/xen-tools/ && ln -s debian.d stable.d
+
Event counts:
  
cd /usr/share/xen-tools/ && ln -s debian.d oldstable.d
+
104856299Other
  
cd /usr/share/xen-tools/ && ln -s debian.d oldoldstable.d
+
00000000Add Domain
  
mkdir -p /usr/share/xen-tools/gentoo.d/
+
00000000Remove Domain
  
cp -R hooks/gentoo/*-* /usr/share/xen-tools/gentoo.d
+
00002256Sleep
  
mkdir -p /usr/share/xen-tools/dapper.d/
+
03238839Wake
  
cp -R hooks/dapper/*-* /usr/share/xen-tools/dapper.d/
+
01477357Block
  
mkdir -p /usr/share/xen-tools/edgy.d/
+
06431042Switch
  
cp -R hooks/edgy/*-* /usr/share/xen-tools/edgy.d/
+
00000000Timer Func
  
cd /usr/share/xen-tools/ && ln -s edgy.d feisty.d
+
06431042Switch Prev
  
cd /usr/share/xen-tools/ && ln -s edgy.d gutsy.d
+
06431042Switch Next
  
cd /usr/share/xen-tools/ && ln -s edgy.d hardy.d
+
00000000Page Map
  
mkdir -p /usr/share/xen-tools/intrepid.d/
+
00000000Page Unmap
  
cp -R hooks/intrepid/*-* /usr/share/xen-tools/intrepid.d/
+
00000000Page Transfer
  
cd /usr/share/xen-tools/ && ln -s intrepid.d jaunty.d
+
processed 128867877 total records in 761 seconds (169340 per second)
  
mkdir -p /usr/share/xen-tools/karmic.d/
+
woke up 22863 times in 761 seconds (30 per second)
  
cp -R hooks/karmic/*-* /usr/share/xen-tools/karmic.d/
+
[root@localhost ~]#
 +
</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s karmic.d lucid.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 karmic.d maverick.d
+
<syntaxhighlight lang="sh"># xenmon.py --iocount --cpu=1 --allocated</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s karmic.d natty.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 karmic.d oneiric.d
+
<syntaxhighlight lang="sh"># xentop</syntaxhighlight>
  
cd /usr/share/xen-tools/ && ln -s karmic.d precise.d
+
[[Image:Figure_37-_Xentop.png|top|600px|none|thumb|Figure 37 : Xentop.]]
  
cd /usr/share/xen-tools/ && ln -s karmic.d quantal.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.
  
cd /usr/share/xen-tools/ && ln -s karmic.d raring.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.
  
cd /usr/share/xen-tools/ && ln -s karmic.d saucy.d
 
  
cd /usr/share/xen-tools/ && ln -s karmic.d trusty.d
+
1-''' VmStat'''
  
cd /usr/share/xen-tools/ && ln -s karmic.d utopic.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 karmic.d vivid.d
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# vmstat
  
cd /usr/share/xen-tools/ && ln -s karmic.d wily.d
+
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
  
cd /usr/share/xen-tools/ && ln -s karmic.d xenial.d
+
r b swpd free buff cache si so bi bo in cs us sy id wa st
  
cp hooks/common.sh /usr/share/xen-tools
+
0 2 60 130248 36912 3107996 0 0 7 7 20 9 0 0 100 0 0
 +
</syntaxhighlight>
  
cp -r hooks/common /usr/share/xen-tools
+
2-''' Tcpdump'''
  
mkdir -p /usr/share/perl5/Xen/Tools
+
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.
  
cp ./lib/Xen/Tools/*.pm /usr/share/perl5/Xen/Tools
+
<syntaxhighlight lang="sh"># tcpdump -i enp7s0
  
mkdir -p man
+
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 bin; for i in *-*[!y]; do pod2man --release=4.6.2 --official --section=8 $i ../man/$i.8; done
+
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
  
for i in man/*.8; do gzip --force -9 $i; done
+
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
  
mkdir -p /usr/share/man/man8/
+
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
  
cp man/*.8.gz /usr/share/man/man8/
+
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
  
OK, “Xen-Tools” installed successfully and you can use it.
+
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
  
For install under Debian Dom0 just run :
+
^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
  
<nowiki># apt-get install xen-tools</nowiki>
 
  
Let me to run “xen-create-image” and see what happen :
+
9184 packets captured
  
[root@localhost ~]# xen-create-image
+
9194 packets received by filter
  
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.
+
7 packets dropped by kernel
 +
</syntaxhighlight>
  
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 802.
+
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”.
  
OK, It is an error and can solved via install “perl-Env” package :
 
  
<nowiki># yum install perl-Env</nowiki>
+
<syntaxhighlight lang="sh"># htop</syntaxhighlight>
  
If after install “perl-Env” you got other errors then :
+
[[Image:Figure_38-_Htop.png|top|600px|none|thumb|Figure 38 : Htop.]]
  
1- yum install cpan
 
  
2- Then use “cpan” with the package that you see. For example :
+
4-''' IPTraf'''
  
[root@localhost ~]# xen-create-image
+
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”.
  
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.
+
<syntaxhighlight lang="sh"># iptraf-ng</syntaxhighlight>
  
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 814.
+
[[Image:Figure_39-_IPTraf.png|top|600px|none|thumb|Figure 39 : IPTraf.]]
  
  
As you see, I got an error about a package with the name “Term::UI module” then I use below command for install it :
+
5- '''Nmon'''
  
<nowiki># cpan Term::UI module</nowiki>
+
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.
  
You may need to doing it for some packages but after it you are ready for work with “Xen-tools”.
+
[[Image:Figure_40-_Nmon.png|top|600px|none|thumb|Figure 40 : Nmon.]]
  
OK, I consider you installed all modules and “Xen-tools” is ready for work.
+
== {{anchor|Toc476606924}} XCP / XenServer ==
  
I run “xen-create-image” :
+
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.
  
Couldn't find a useful entry in the sources.list files of the Dom0. Tried:
+
* Support of advantage storage.
  
/etc/apt/sources.list
+
* Support of SLA and mutli-tenancy.
  
The '--hostname' argument is mandatory.
+
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] .  
  
[root@localhost ~]#
+
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 :
  
It is a tool for automate creating. The syntax is straightforward and you can see more options just with “--help” option.
+
<syntaxhighlight lang="sh"># scp XenServer-7.0.0-main.iso root@172.30.9.20:/home/mohsen/</syntaxhighlight>
  
[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
+
After it, We must mount this .iso file thus create a directory with the name “cd” under “/mnt/” directory :
  
  
[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
+
<syntaxhighlight lang="sh"># mkdir </syntaxhighlight>cd /mnt
  
Couldn't find a useful entry in the sources.list files of the Dom0. Tried:
+
Then use below command to mount .iso file to “/mnt/cd” directory :
  
/etc/apt/sources.list
+
<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 :
  
General Information
+
<syntaxhighlight lang="sh">
 +
[root@localhost ~]# cd /mnt/cd/
  
<nowiki>--------------------</nowiki>
+
[root@localhost cd]# ls
  
Hostname : linux.via.xentools
+
boot client_install EFI EULA install.img LICENSES Packages Read_Me_First.html repodata
 +
</syntaxhighlight>
  
Distribution : jessie
+
You can see a directory with the name “ Packages” and move to it via “cd” command. After it you can find “XAPI” package here :
  
Mirror : http://httpredir.debian.org/debian
+
<syntaxhighlight lang="sh">
 +
[root@localhost Packages]# ls xapi-xe*
  
Partitions : swap 512Mb (swap)
+
xapi-xe-1.9.57-8535.x86_64.rpm
 +
</syntaxhighlight>
  
/ 4Gb (ext3)
+
Then use “rpm” command to install it as below :
  
Image type : sparse
+
<syntaxhighlight lang="sh">
 +
[root@localhost Packages]# rpm -Uvh xapi-xe-1.9.57-8535.x86_64.rpm
  
Memory size : 128M
+
Preparing... ################################# [100%]
  
Kernel path : /boot/vmlinuz-4.4.7-300.fc23.x86_64
+
Updating / installing...
  
Initrd path : /boot/initrd.img-4.4.7-300.fc23.x86_64
+
1:xapi-xe-1.9.57-8535 ################################# [100%]
 +
</syntaxhighlight>
  
 +
After it you can see that we installed “xe” successfully and can use it :
  
Networking Information
+
<syntaxhighlight lang="sh">
 +
[root@localhost Packages]# xe
  
<nowiki>----------------------</nowiki>
+
Usage: xe <cmd> [-s server] [-p port] ([-u username] [-pw password] or [-pwf <password file>]) <other arguments>
  
IP Address 1 : 172.30.9.21 [MAC: 00:16:3E:52:EF:69]
+
A full list of commands can be obtained by running
  
Netmask : 255.255.255.0
+
xe help -s <server> -p <port>
 +
</syntaxhighlight>
  
Gateway : 172.30.9.254
+
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”.
  
Creating partition image: /home/mohsen/domains/linux.via.xentools/swap.img
+
2- For learn “virsh” command and use it via Xen Project Please look at [http://wiki.xenproject.org/wiki/Virsh_Commands http://wiki.xenproject.org/wiki/Virsh_Commands] .
  
Done
+
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]]
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:Figure_36-_Xenmon.png|top|600px|none|thumb]]</div>
 
 
 
=====<span style="color:#00000a;">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 :
 
 
 
<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>
 
 
 
[[Image:Figure_37-_Xentop.png|top|600px|none|thumb]]
 
 
 
===== <span style="color:#00000a;">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-''' <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:Figure_38-_Htop.png|top|600px|none|thumb]]</div>
 
 
 
===== <span style="color:#00000a;">Figure 38 : Htop.=====
 
 
 
 
 
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:Figure_39-_IPTraf.png|top|600px|none|thumb]]
 
 
 
===== <span style="color:#00000a;">Figure 39 : IPTraf.=====
 
 
 
 
 
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:Figure_40-_Nmon.png|top|600px|none|thumb]]
 
 
 
===== <span style="color:#00000a;">Figure 40 : Nmon.=====
 
 
 
 
 
 
 
 
 
 
 
 
 
== {{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...
 
 
 
1:xapi-xe-1.9.57-8535 <nowiki>################################# [100%]</nowiki>
 
 
 
 
 
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 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/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]
 

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