Book/HelloXenProject/4-Chapter: Difference between revisions
Lars.kurth (talk | contribs) |
No edit summary |
||
(3 intermediate revisions by one other user not shown) | |||
Line 7: | Line 7: | ||
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. |
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}} |
== {{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. |
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. |
||
Line 15: | Line 15: | ||
Gnome : |
Gnome : |
||
< |
<syntaxhighlight lang="sh"># yum groupinstall gnome</syntaxhighlight> |
||
or |
or |
||
< |
<syntaxhighlight lang="sh"># yum groupinstall gdm</syntaxhighlight> |
||
KDE : |
KDE : |
||
< |
<syntaxhighlight lang="sh"># yum groupinstall kde</syntaxhighlight> |
||
XFCE : |
XFCE : |
||
< |
<syntaxhighlight lang="sh"># yum groupinstall xfce</syntaxhighlight> |
||
MATE : |
MATE : |
||
< |
<syntaxhighlight lang="sh"># yum groupinstall "MATE Desktop”</syntaxhighlight> |
||
When installing finished just run below command : |
When installing finished just run below command : |
||
< |
<syntaxhighlight lang="sh"># startx</syntaxhighlight> |
||
And after it you can see your Desktop. Mine is: |
And after it you can see your Desktop. Mine is: |
||
Line 45: | Line 45: | ||
Open a “Terminal” and type below command for installing “Virt-Manager” : |
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”. |
After it you can run “virt-manager”. |
||
Line 54: | Line 54: | ||
[[Image:Figure_19-_Virt-Manager_(OpenSUSE).png|top|600px|none|thumb|Figure 19 : Virt-Manager (OpenSUSE).]] |
[[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).]] |
[[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. |
As you see, It is easy as ABC and give you this ability to run your own DomU guest via a nice Graphical interface. |
||
Line 66: | Line 61: | ||
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 : |
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. |
After, Everything back to a right point. |
||
Line 72: | Line 67: | ||
If you start “Virt-Manager” and see some error like “unable to connect to libvirt” then don't worry, Just type below command : |
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/”. |
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/”. |
||
Line 79: | Line 73: | ||
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! |
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 == |
|||
== {{anchor|Toc476606915}} <span style="color:#00000a;">Storage and Networking</span> == |
|||
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. |
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. |
||
Line 99: | Line 88: | ||
* Save space. Small chunks of unused space from several disks can be combined to create a usable volume. |
* 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. |
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 : |
It a good figure that help you to understand LVM easily : |
||
[[Image:Figure_21-_LVM_Scheme..png|top|600px|none|thumb|Figure 21 : LVM Scheme.]] |
[[Image:Figure_21-_LVM_Scheme..png|top|600px|none|thumb|Figure 21 : LVM Scheme.]] |
||
Line 114: | Line 100: | ||
The first tool that we cover here is “fdisk” or “cfdisk”. Just type : |
The first tool that we cover here is “fdisk” or “cfdisk”. Just type : |
||
< |
<syntaxhighlight lang="sh"># cfdisk</syntaxhighlight> |
||
or |
or |
||
< |
<syntaxhighlight lang="sh"># fdisk -l</syntaxhighlight> |
||
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 : |
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 : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# fdisk -l |
[root@localhost ~]# fdisk -l |
||
Line 155: | Line 142: | ||
I/O size (minimum/optimal): 512 bytes / 512 bytes |
I/O size (minimum/optimal): 512 bytes / 512 bytes |
||
</syntaxhighlight> |
|||
And “cfdisk” : |
And “cfdisk” : |
||
Line 173: | Line 160: | ||
I added a new HDD to my system and Linus detected it as “sdb”. I use below command for look at my new HDD : |
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> |
||
[[Image:Figure_23-_cfdisk.png|top|600px|none|thumb|Figure 23 : cfdisk.]] |
[[Image:Figure_23-_cfdisk.png|top|600px|none|thumb|Figure 23 : cfdisk.]] |
||
Line 181: | Line 168: | ||
I used a tool with the name “parted” as below : |
I used a tool with the name “parted” as below : |
||
< |
<syntaxhighlight lang="sh"># parted /dev/sdb mklabel msdos</syntaxhighlight> |
||
It show you a warning message about that all of your information will be destroy. Type “yes” and enter. Then, Write below command : |
It show you a warning message about that all of your information will be destroy. Type “yes” and enter. Then, Write below command : |
||
< |
<syntaxhighlight lang="sh"># parted /dev/sdb mkpart primary</syntaxhighlight> |
||
after this command, Linux ask you some questions, I selected default file system (ext2) and enter “1” as “Start” and “100%” as “End”. |
after this command, Linux ask you some questions, I selected default file system (ext2) and enter “1” as “Start” and “100%” as “End”. |
||
Line 191: | Line 178: | ||
What do you see? Linux created a partition for you with the name “/dev/sdb1”. You can confirm it via below command : |
What do you see? Linux created a partition for you with the name “/dev/sdb1”. You can confirm it via below command : |
||
< |
<syntaxhighlight lang="sh"># fdisk /dev/sdb -l</syntaxhighlight> |
||
[[Image:Figure_24-_fdisk.png|top|600px|none|thumb|Figure 24 : fdisk.]] |
[[Image:Figure_24-_fdisk.png|top|600px|none|thumb|Figure 24 : fdisk.]] |
||
Line 197: | Line 184: | ||
After it, I want enable “LVM” for this partition and use below command : |
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 : |
In above command I used “set 1” that mean partition 1. Let me to see our partitions via “fdisk” command : |
||
< |
<syntaxhighlight lang="sh"># fdisk /dev/sdb -l</syntaxhighlight> |
||
[[Image:Figure_25-_fdisk_-l.png|top|600px|none|thumb|Figure 25 : fdisk -l.]] |
[[Image:Figure_25-_fdisk_-l.png|top|600px|none|thumb|Figure 25 : fdisk -l.]] |
||
Line 210: | Line 197: | ||
Type below command : |
Type below command : |
||
< |
<syntaxhighlight lang="sh"># pvcreate /dev/sdb1</syntaxhighlight> |
||
< |
<syntaxhighlight lang="sh"># vgcreate Xen /dev/sdb1 -v</syntaxhighlight> |
||
[[Image:Figure_26-_vgcreate.png|top|600px|none|thumb|Figure 26 : vgcreate.]] |
[[Image:Figure_26-_vgcreate.png|top|600px|none|thumb|Figure 26 : vgcreate.]] |
||
< |
<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 : |
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 : |
||
Line 224: | Line 211: | ||
Let me to see our LVM via “vgdisplay” command : |
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.]] |
[[Image:Figure_28-_vgdisplay-1.png|top|600px|none|thumb|Figure 28 : vgdisplay-1.]] |
||
[[Image:Figure_29-_vgdisplay-2.png|top|600px|none|thumb|Figure 29 : vgdisplay-2.]] |
[[Image:Figure_29-_vgdisplay-2.png|top|600px|none|thumb|Figure 29 : vgdisplay-2.]] |
||
OK, our storage is ready and we just need to create a config file for our VM. Before we dive into config file, Please let us for write something about “Networking”. |
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 == |
|||
== {{anchor|Toc476606916}} <span style="color:#00000a;">Networking in Xen</span> == |
|||
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. |
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. |
||
Line 243: | Line 226: | ||
The Xen Project support some kind of networking that we will show you them here : |
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. |
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. |
||
Line 250: | Line 232: | ||
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). |
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. |
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. |
OK, Xen need bridge for running and we want to show that you how you can create a Bridge for The Xen Project. |
||
Line 261: | Line 241: | ||
My Current config are : |
My Current config are : |
||
<syntaxhighlight lang="sh"> |
|||
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
||
Line 277: | Line 257: | ||
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 294: | Line 275: | ||
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 309: | Line 291: | ||
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, 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. |
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. |
||
Line 315: | Line 297: | ||
I want to create a bridge that use this static IP, So I create a file via below command : |
I want to create a bridge that use this static IP, So I create a file via below command : |
||
<syntaxhighlight lang="sh"># touch /etc/sysconfig/network-scripts/ifcfg-br0</syntaxhighlight> |
|||
<nowiki># touch /etc/sysconfig/network-scripts/ifcfg-br0</nowiki> |
|||
Then open it via an editor like “nano” and fill it with below information : |
Then open it via an editor like “nano” and fill it with below information : |
||
<syntaxhighlight lang="sh"> |
|||
DEVICE=br0 |
DEVICE=br0 |
||
Line 339: | Line 321: | ||
NM_CONTROLLED=no |
NM_CONTROLLED=no |
||
</syntaxhighlight> |
|||
But, If your real NIC use DHCP protocol then you should use below config for Bridge : |
But, If your real NIC use DHCP protocol then you should use below config for Bridge : |
||
<syntaxhighlight lang="sh"> |
|||
DEVICE=br0 |
DEVICE=br0 |
||
Line 355: | Line 337: | ||
NM_CONTROLLED=no |
NM_CONTROLLED=no |
||
</syntaxhighlight> |
|||
After it, I must change my real NIC configuration, So I open it via an editor : |
After it, I must change my real NIC configuration, So I open it via an editor : |
||
< |
<syntaxhighlight lang="sh"># nano /etc/sysconfig/network-scripts/ifcfg-enp7s0</syntaxhighlight> |
||
<syntaxhighlight lang="sh"> |
|||
HWADDR=50:E5:49:40:C4:8F |
HWADDR=50:E5:49:40:C4:8F |
||
Line 385: | Line 368: | ||
ONBOOT=yes |
ONBOOT=yes |
||
#IPADDR=172.30.9.20< |
|||
#PREFIX=24 |
|||
#GATEWAY=172.30.9.254 |
|||
#DNS1=172.30.9.1 |
|||
IPV6_PEERDNS=yes |
IPV6_PEERDNS=yes |
||
Line 402: | Line 385: | ||
BRIDGE=br0 |
BRIDGE=br0 |
||
</syntaxhighlight> |
|||
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. |
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. |
||
Line 409: | Line 393: | ||
Everything is ready and I must restart my network service for take affect : |
Everything is ready and I must restart my network service for take affect : |
||
< |
<syntaxhighlight lang="sh"># systemctl restart network.service</syntaxhighlight> |
||
After it, you can see current configuration via “ifconfig” command as below : |
After it, you can see current configuration via “ifconfig” command as below : |
||
<syntaxhighlight lang="sh"> |
|||
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
||
Line 428: | Line 413: | ||
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"> |
|||
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
||
Line 443: | Line 429: | ||
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 460: | 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 475: | 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, 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. |
Our network is ready and we must create a Guest config. |
||
== Installing Windows as HVM domainU Guest== |
== Installing Windows as HVM domainU Guest== |
||
Line 494: | Line 477: | ||
First of all, We must create a config file for our VM. Let me to create it via “touch” command in Linux : |
First of all, We must create a config file for our VM. Let me to create it via “touch” command in Linux : |
||
< |
<syntaxhighlight lang="sh"># touch /etc/xen/windows.cfg</syntaxhighlight> |
||
Then, I open it via an editor like “nano” as below : |
Then, I open it via an editor like “nano” as below : |
||
<syntaxhighlight lang="sh"># nano /etc/xen/windows.cfg</syntaxhighlight> |
|||
<nowiki># nano /etc/xen/windows.cfg</nowiki> |
|||
And fill this file via below information : |
And fill this file via below information : |
||
<syntaxhighlight lang="sh"> |
|||
name = "Windows7" |
name = "Windows7" |
||
Line 537: | Line 517: | ||
on_crash = "restart" |
on_crash = "restart" |
||
</syntaxhighlight> |
|||
I must tell you something about this file : |
I must tell you something about this file : |
||
Line 548: | Line 528: | ||
* 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). |
* 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 : |
Let us start our Guest. Just type below command : |
||
< |
<syntaxhighlight lang="sh"># xl create /etc/xen/windows.cfg</syntaxhighlight> |
||
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. |
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. |
||
Line 560: | Line 538: | ||
After it write below command : |
After it write below command : |
||
< |
<syntaxhighlight lang="sh"># xl list</syntaxhighlight> |
||
and you can see something like below : |
and you can see something like below : |
||
<syntaxhighlight lang="sh"> |
|||
Name ID Mem VCPUsStateTime(s) |
Name ID Mem VCPUsStateTime(s) |
||
Line 569: | Line 548: | ||
Windows7 19 4096 4 -b---- 23.1 |
Windows7 19 4096 4 -b---- 23.1 |
||
</syntaxhighlight> |
|||
As you see, “Windows7” is running and we just need connect to it via “vncviewer”. But you must did something on your Firewall. |
As you see, “Windows7” is running and we just need connect to it via “vncviewer”. But you must did something on your Firewall. |
||
Line 577: | Line 556: | ||
I use “netstat -nat” command for show our current network connections : |
I use “netstat -nat” command for show our current network connections : |
||
<syntaxhighlight lang="sh"># netstat -nat |
|||
<nowiki># netstat -nat</nowiki> |
|||
Active Internet connections (servers and established) |
Active Internet connections (servers and established) |
||
Line 595: | Line 573: | ||
tcp6 0 0 :::22 :::* LISTEN |
tcp6 0 0 :::22 :::* LISTEN |
||
</syntaxhighlight> |
|||
As you see, The IP “172.30.9.20” and Port “5900” are ready for connect but we must doing some steps for connect to our VM : |
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 : |
||
Line 603: | Line 581: | ||
2- Depend on your Linux Distro (Dom0) you must use “iptables” for open VNC Port on Dom0 : |
2- Depend on your Linux Distro (Dom0) you must use “iptables” for open VNC Port on Dom0 : |
||
< |
<syntaxhighlight lang="sh"># iptables -A INPUT -p tcp --dport 5900 -j ACCEPT</syntaxhighlight> |
||
< |
<syntaxhighlight lang="sh"># iptables-save</syntaxhighlight> |
||
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. |
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. |
||
Line 611: | Line 589: | ||
We ready ready to connect to our Xen Server : |
We ready ready to connect to our Xen Server : |
||
< |
<syntaxhighlight lang="sh"># vncviewer 172.30.9.20:5900</syntaxhighlight> |
||
And after it, A window displayed and we can do Windows install process: |
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.]] |
[[Image:Figure_30-_Windows_7_on_Xen.png|top|600px|none|thumb|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 : |
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 : |
||
<syntaxhighlight lang="sh"> |
|||
vncpasswd=”Your Password” |
vncpasswd=”Your Password” |
||
</syntaxhighlight> |
|||
After it, When you want view your VM via VNC you must enter a password : |
After it, When you want view your VM via VNC you must enter a password : |
||
<syntaxhighlight lang="sh"> |
|||
vncviewer 172.30.9.20:5900 |
vncviewer 172.30.9.20:5900 |
||
Line 631: | Line 610: | ||
Password: |
Password: |
||
</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 : |
When you working with Your VM, You may have some problems with your Display and you must consider below Links for Troubleshooting your problems : |
||
Line 640: | Line 619: | ||
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 : |
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 : |
||
[[Image:Figure_31-_Static_IP.png|top|600px|none|thumb|Figure 31 : Static IP.]] |
[[Image:Figure_31-_Static_IP.png|top|600px|none|thumb|Figure 31 : Static IP.]] |
||
When you create another VM: |
When you create another VM: |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# netstat -nat |
[root@localhost ~]# netstat -nat |
||
Line 670: | Line 648: | ||
tcp6 0 0 :::22 :::* LISTEN |
tcp6 0 0 :::22 :::* LISTEN |
||
</syntaxhighlight> |
|||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xl list |
[root@localhost ~]# xl list |
||
Line 681: | Line 660: | ||
linux 10 2048 1 r----- 64.8 |
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. |
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. |
||
Line 687: | Line 666: | ||
For adding more than one NIC you can use : |
For adding more than one NIC you can use : |
||
<syntaxhighlight lang="sh"> |
|||
vif=['bridge=br0','mac=00:16:17:a5:6y:89,bridge=virbr0'] |
vif=['bridge=br0','mac=00:16:17:a5:6y:89,bridge=virbr0'] |
||
</syntaxhighlight> |
|||
The “mac” defined the MAC address for our NIC. |
The “mac” defined the MAC address for our NIC. |
||
Line 694: | Line 674: | ||
We can use our first Bridge(br0) for adding more than NIC too but we should add a MAC address fpr each NIC : |
We can use our first Bridge(br0) for adding more than NIC too but we should add a MAC address fpr each NIC : |
||
<syntaxhighlight lang="sh"> |
|||
vif=['bridge=br0,mac=00:13:r6:45:g6:9o','mac=00:16:17:a5:6y:89,bridge=br0'] |
vif=['bridge=br0,mac=00:13:r6:45:g6:9o','mac=00:16:17:a5:6y:89,bridge=br0'] |
||
</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. |
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. |
||
Line 703: | Line 684: | ||
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 : |
In some situation, You may want to use another HDD or other Vms HDD in a VM. It is so easy and you can write the name of your other HDD in “disk” in the config file : |
||
<syntaxhighlight lang="sh"> |
|||
disk=['phy:/dev/Xen/Fedora,hda,w','phy:/dev/Xen/linux,hdb,w','file:/home/mohsen/Windows7.iso,hdc:cdrom,r'] |
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”. |
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”. |
||
== {{anchor|Toc476606917}} |
== {{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? |
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? |
||
Line 714: | Line 696: | ||
For example, I run “xl list” and the output is as below : |
For example, I run “xl list” and the output is as below : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xl list |
[root@localhost ~]# xl list |
||
Line 721: | Line 704: | ||
OpenSUSE 44 2048 1 r----- 4.6 |
OpenSUSE 44 2048 1 r----- 4.6 |
||
</syntaxhighlight> |
|||
I will tel you something about these words : |
I will tel you something about these words : |
||
Line 748: | Line 731: | ||
The domain is in process of dying, but hasn't completely shutdown or crashed. |
The domain is in process of dying, but hasn't completely shutdown or crashed. |
||
In below example, my “OpenSUSE” VM is running and established : |
In below example, my “OpenSUSE” VM is running and established : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xl list |
[root@localhost ~]# xl list |
||
Line 759: | Line 742: | ||
OpenSUSE 44 2048 2 -b---- 127.4 |
OpenSUSE 44 2048 2 -b---- 127.4 |
||
</syntaxhighlight> |
|||
Then, I run below command for “Pause” it : |
Then, I run below command for “Pause” it : |
||
< |
<syntaxhighlight lang="sh"># xl pause OpenSUSE</syntaxhighlight> |
||
and my current state is: |
and my current state is: |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xl list |
[root@localhost ~]# xl list |
||
Line 774: | Line 758: | ||
OpenSUSE 44 2048 2 --p--- 127.5 |
OpenSUSE 44 2048 2 --p--- 127.5 |
||
</syntaxhighlight> |
|||
For “unpause” a VM you can use below command : |
For “unpause” a VM you can use below command : |
||
< |
<syntaxhighlight lang="sh"># xl unpause OpenSUSE |
||
[root@localhost ~]# xl list |
[root@localhost ~]# xl list |
||
Line 787: | Line 771: | ||
OpenSUSE 44 2048 2 -b---- 128.3 |
OpenSUSE 44 2048 2 -b---- 128.3 |
||
</syntaxhighlight> |
|||
Add USB Devices to your VM |
Add USB Devices to your VM |
||
Line 793: | Line 777: | ||
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 : |
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"> |
|||
[root@localhost ~]# lsusb |
[root@localhost ~]# lsusb |
||
Line 812: | Line 797: | ||
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub |
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub |
||
</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 : |
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 : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# lsusb |
[root@localhost ~]# lsusb |
||
Line 837: | Line 823: | ||
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub |
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub |
||
</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. |
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. |
||
Line 852: | Line 838: | ||
Fist of all, You must open your VM cofing file via an editor like “nano” : |
Fist of all, You must open your VM cofing file via an editor like “nano” : |
||
< |
<syntaxhighlight lang="sh"># nano /etc/xen/linux.cg</syntaxhighlight> |
||
Then add below lines to your config file : |
Then add below lines to your config file : |
||
<syntaxhighlight lang="sh"> |
|||
usb="1" |
usb="1" |
||
usbdevice=['host:03f0:5607'] |
usbdevice=['host:03f0:5607'] |
||
</syntaxhighlight> |
|||
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. |
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. |
||
Line 865: | Line 852: | ||
After it, When I start my VM then I can see my Pendrive that mounted in my VM. In below Figure, You can see that my HP Pendrive mounted in OpenSUSE Linux : |
After it, 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 : |
||
[[Image:Figure_33-_USB_Mounted.png|top|600px|none|thumb|Figure 33: USB Mounted.]] |
|||
== {{anchor|Toc476606918}} Use Physical CD/DVD ROM == |
|||
[[Image:Figure_33-_USB_Mounted.png|top|600px|none|thumb]] |
|||
===== <span style="color:#00000a;">Figure 33: USB Mounted.]] |
|||
== {{anchor|Toc476606918}} <span style="color:#00000a;">Use Physical CD/DVD ROM</span> == |
|||
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. |
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. |
||
Line 878: | Line 860: | ||
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 : |
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 ~]# lsblk |
[root@localhost ~]# lsblk |
||
Line 899: | Line 882: | ||
sr0 11:0 1 158.5M 0 rom |
sr0 11:0 1 158.5M 0 rom |
||
</syntaxhighlight> |
|||
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 : |
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 : |
||
<syntaxhighlight lang="sh"> |
|||
disk=['phy:/dev/sr0,hdc:cdrom,r'] |
disk=['phy:/dev/sr0,hdc:cdrom,r'] |
||
</syntaxhighlight> |
|||
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 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. |
||
Line 910: | Line 894: | ||
If DVD Drive not detected automatically then use below command : |
If DVD Drive not detected automatically then use below command : |
||
< |
<syntaxhighlight lang="sh"># eject</syntaxhighlight> |
||
This command eject DVD from the Guest and if you change CD or DVD then for detect the insertion use below command : |
This command eject DVD from the Guest and if you change CD or DVD then for detect the insertion use below command : |
||
< |
<syntaxhighlight lang="sh"># eject -t</syntaxhighlight> |
||
== {{anchor|Toc476606919}} |
== {{anchor|Toc476606919}} 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. |
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. |
||
Line 925: | Line 906: | ||
First of all, Please let me to create a directory via “mkdir” for our Virtual HDD : |
First of all, Please let me to create a directory via “mkdir” for our Virtual HDD : |
||
< |
<syntaxhighlight lang="sh"># mkdir Windows</syntaxhighlight> |
||
change to “Windows” directory via “cd” command : |
change to “Windows” directory via “cd” command : |
||
< |
<syntaxhighlight lang="sh"># cd Windows/</syntaxhighlight> |
||
And run below command for create a Virtual HDD about 40GB : |
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> |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost Windows]# 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 |
||
Line 942: | Line 924: | ||
41943040000 bytes (42 GB) copied, 332.735 s, 126 MB/s |
41943040000 bytes (42 GB) copied, 332.735 s, 126 MB/s |
||
</syntaxhighlight> |
|||
If you list files and directory via “ls” command then you will see something like below : |
If you list files and directory via “ls” command then you will see something like below : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost Windows]# ls |
[root@localhost Windows]# ls |
||
windows.img |
windows.img |
||
</syntaxhighlight> |
|||
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. |
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. |
||
Line 955: | Line 938: | ||
Open your VM config file via an editor like “Nano” and add below line as your HDD : |
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'] |
disk=['file:/home/mohsen/Windows/windows.img,hda,w'] |
||
</syntaxhighlight> |
|||
As you see, We used “file” instead of “phy”. |
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 : |
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 : |
||
Line 964: | Line 948: | ||
[[Image:Figure_34-_Windows_10_Error..png|top|600px|none|thumb|Figure 34 : Windows 10 Error.]] |
[[Image:Figure_34-_Windows_10_Error..png|top|600px|none|thumb|Figure 34 : Windows 10 Error.]] |
||
== {{anchor|Toc476606920}} |
== {{anchor|Toc476606920}} 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 :) |
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 :) |
||
Line 976: | Line 960: | ||
First of all, Run below command to see a list of Hardware : |
First of all, Run below command to see a list of Hardware : |
||
<syntaxhighlight lang="sh"># lspci</syntaxhighlight> |
|||
<nowiki># lspci</nowiki> |
|||
Then run : |
Then run : |
||
< |
<syntaxhighlight lang="sh"># lspci -vv -s PCI ID | grep FLR</syntaxhighlight> |
||
For example : |
For example : |
||
< |
<syntaxhighlight lang="sh"># lspci -vv -s 00:02.0 | grep FLR</syntaxhighlight> |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# lspci -vv -s 00:02.0 | grep FLR |
[root@localhost ~]# lspci -vv -s 00:02.0 | grep FLR |
||
Line 992: | Line 976: | ||
AFCtrl: FLR- |
AFCtrl: FLR- |
||
</syntaxhighlight> |
|||
OK, We consider that your device support FLR and I will tell you that how you can attach it. |
OK, We consider that your device support FLR and I will tell you that how you can attach it. |
||
Line 998: | Line 982: | ||
First of all, Execute below command : |
First of all, Execute below command : |
||
< |
<syntaxhighlight lang="sh"># modprobe xen-pciback</syntaxhighlight> |
||
Create a file via “touch” command and fill it with below information : |
Create a file via “touch” command and fill it with below information : |
||
<syntaxhighlight lang="sh"> |
|||
remove_device () { |
remove_device () { |
||
BDF=$1 |
BDF=$1 |
||
# Unbind a PCI function from its driver as necessary |
|||
[ ! -e /sys/bus/pci/devices/$BDF/driver/unbind ] || \ |
[ ! -e /sys/bus/pci/devices/$BDF/driver/unbind ] || \ |
||
Line 1,012: | Line 997: | ||
echo -n $BDF > /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 |
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 |
echo -n $BDF > /sys/bus/pci/drivers/pciback/bind |
||
} |
} |
||
remove_device "Your PCI ID" |
remove_device "Your PCI ID" |
||
# For example : remove_device "0000:01:00.1" |
|||
</syntaxhighlight> |
|||
<nowiki># For example : remove_device "0000:01:00.1"</nowiki> |
|||
Save the file and run this script via “sh yourfilename”. |
Save the file and run this script via “sh yourfilename”. |
||
Line 1,032: | Line 1,016: | ||
After it, You must edit your VM config file. Open you config file via an editor like “Nano” : |
After it, You must edit your VM config file. Open you config file via an editor like “Nano” : |
||
< |
<syntaxhighlight lang="sh"># nano /etc/xen/windows.cfg</syntaxhighlight> |
||
Then add below line to your config file : |
Then add below line to your config file : |
||
Line 1,038: | Line 1,022: | ||
pci=['Your PCI ID','Your PCI ID'] |
pci=['Your PCI ID','Your PCI ID'] |
||
< |
<syntaxhighlight lang="sh"># For example : pci=['01:00.1','00:1a.0']</syntaxhighlight> |
||
Then run your VM and your PCI device will attached to your VM. |
Then run your VM and your PCI device will attached to your VM. |
||
== {{anchor|Toc476606921}} |
== {{anchor|Toc476606921}} 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. |
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. |
||
Line 1,052: | Line 1,036: | ||
< |
<syntaxhighlight lang="sh"># swapon --show</syntaxhighlight> |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# swapon --show |
[root@localhost ~]# swapon --show |
||
Line 1,061: | Line 1,046: | ||
[root@localhost ~]# |
[root@localhost ~]# |
||
</syntaxhighlight> |
|||
As you see, My system has 16GB Swap space. |
As you see, My system has 16GB Swap space. |
||
Line 1,067: | Line 1,052: | ||
You can use “free -h” command too : |
You can use “free -h” command too : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# free -h |
[root@localhost ~]# free -h |
||
Line 1,076: | Line 1,062: | ||
[root@localhost ~]# |
[root@localhost ~]# |
||
</syntaxhighlight> |
|||
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. |
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. |
||
Line 1,082: | Line 1,068: | ||
First of all, We use “dd” command for create an image : |
First of all, We use “dd” command for create an image : |
||
< |
<syntaxhighlight lang="sh"># dd if=/dev/zero of=linuxswap.swap bs=1024 count=”Your size”</syntaxhighlight> |
||
For example : |
For example : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost mohsen]# dd if=/dev/zero of=linuxswap.swap bs=1024 count=4096000 |
[root@localhost mohsen]# dd if=/dev/zero of=linuxswap.swap bs=1024 count=4096000 |
||
Line 1,093: | Line 1,080: | ||
4194304000 bytes (4.2 GB) copied, 32.8729 s, 128 MB/s |
4194304000 bytes (4.2 GB) copied, 32.8729 s, 128 MB/s |
||
</syntaxhighlight> |
|||
Then : |
Then : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost mohsen]# mkswap linuxswap.swap |
[root@localhost mohsen]# mkswap linuxswap.swap |
||
Line 1,104: | Line 1,092: | ||
no label, UUID=f2464b51-c7ef-4990-8cb6-8d50d151b52e |
no label, UUID=f2464b51-c7ef-4990-8cb6-8d50d151b52e |
||
</syntaxhighlight> |
|||
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 : |
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"> |
|||
file:/YourPath/linuxswap.swap,hdb,w |
file:/YourPath/linuxswap.swap,hdb,w |
||
</syntaxhighlight> |
|||
The complete line is something like : |
The complete line is something like : |
||
<syntaxhighlight lang="sh"> |
|||
disk=['phy:/dev/Xen/linux,hda,w','file:/home/mohsen/linuxswap.swap,hdb,w'] |
disk=['phy:/dev/Xen/linux,hda,w','file:/home/mohsen/linuxswap.swap,hdb,w'] |
||
</syntaxhighlight> |
|||
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 : |
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> |
||
[[Image:Figure_35-_Swap_Space.png|top|600px|none|thumb|Figure 35 : Swap Space.]] |
[[Image:Figure_35-_Swap_Space.png|top|600px|none|thumb|Figure 35 : Swap Space.]] |
||
Line 1,134: | Line 1,123: | ||
/dev/XXX none swap defaults 0 0 |
/dev/XXX none swap defaults 0 0 |
||
< |
<syntaxhighlight lang="sh"># For example : /dev/hdb none swap defaults 0 0</syntaxhighlight> |
||
Line 1,140: | Line 1,129: | ||
== {{anchor|Toc476606922}} |
== {{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! |
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! |
||
Line 1,146: | Line 1,135: | ||
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 : |
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 : |
||
< |
<syntaxhighlight lang="sh"># yum install debootstrap perl-Text-Template perl-Config-IniFiles perl-File-Slurp perl-File-Which perl-Data-Dumper</syntaxhighlight> |
||
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 : |
After it go to the location that downloaded file is there and use “gunzip” and “tar” command for extract it. Then use “cd” command for change the current location and when you are in “Xen-Tools” directory run “make install” command. You will see something like below : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost xen-tools-4.6.2]# make install |
[root@localhost xen-tools-4.6.2]# make install |
||
Line 1,376: | Line 1,365: | ||
cp man/*.8.gz /usr/share/man/man8/ |
cp man/*.8.gz /usr/share/man/man8/ |
||
</syntaxhighlight> |
|||
OK, “Xen-Tools” installed successfully and you can use it. |
OK, “Xen-Tools” installed successfully and you can use it. |
||
Line 1,382: | Line 1,371: | ||
For install under Debian Dom0 just run : |
For install under Debian Dom0 just run : |
||
< |
<syntaxhighlight lang="sh"># apt-get install xen-tools</syntaxhighlight> |
||
Let me to run “xen-create-image” and see what happen : |
Let me to run “xen-create-image” and see what happen : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xen-create-image |
[root@localhost ~]# xen-create-image |
||
Line 1,391: | Line 1,381: | ||
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 802. |
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 802. |
||
</syntaxhighlight> |
|||
OK, It is an error and can solved via install “perl-Env” package : |
OK, It is an error and can solved via install “perl-Env” package : |
||
< |
<syntaxhighlight lang="sh"># yum install perl-Env</syntaxhighlight> |
||
If after install “perl-Env” you got other errors then : |
If after install “perl-Env” you got other errors then : |
||
Line 1,403: | Line 1,393: | ||
2- Then use “cpan” with the package that you see. For example : |
2- Then use “cpan” with the package that you see. For example : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xen-create-image |
[root@localhost ~]# xen-create-image |
||
Line 1,408: | Line 1,399: | ||
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 814. |
BEGIN failed--compilation aborted at /usr/bin/xen-create-image line 814. |
||
</syntaxhighlight> |
|||
As you see, I got an error about a package with the name “Term::UI module” then I use below command for install it : |
As you see, I got an error about a package with the name “Term::UI module” then I use below command for install it : |
||
< |
<syntaxhighlight lang="sh"># cpan Term::UI module</syntaxhighlight> |
||
You may need to doing it for some packages but after it you are ready for work with “Xen-tools”. |
You may need to doing it for some packages but after it you are ready for work with “Xen-tools”. |
||
Line 1,420: | Line 1,411: | ||
I run “xen-create-image” : |
I run “xen-create-image” : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xen-create-image |
[root@localhost ~]# xen-create-image |
||
Line 1,429: | Line 1,421: | ||
[root@localhost ~]# |
[root@localhost ~]# |
||
</syntaxhighlight> |
|||
It is a tool for automate creating. The syntax is straightforward and you can see more options just with “--help” option. |
It is a tool for automate creating. The syntax is straightforward and you can see more options just with “--help” option. |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xen-create-image --size=4Gb --swap=512Mb --ip=172.30.9.21 --netmask=255.255.255.0 --gateway=172.30.9.254 --dir=/home/mohsen --hostname=linux.via.xentools –dist=jessie --kernel /boot/vmlinuz-4.2.3-300.fc23.x86_64 --initrd /boot/initrd-plymouth.img --role gdm |
[root@localhost ~]# 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 |
[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 |
||
Line 1,445: | Line 1,437: | ||
General Information |
General Information |
||
-------------------- |
|||
Hostname : linux.via.xentools |
Hostname : linux.via.xentools |
||
Line 1,468: | Line 1,460: | ||
Networking Information |
Networking Information |
||
---------------------- |
|||
IP Address 1 : 172.30.9.21 [MAC: 00:16:3E:52:EF:69] |
IP Address 1 : 172.30.9.21 [MAC: 00:16:3E:52:EF:69] |
||
Line 1,530: | Line 1,522: | ||
Installation Summary |
Installation Summary |
||
--------------------- |
|||
Hostname : linux.via.xentools |
Hostname : linux.via.xentools |
||
Line 1,545: | Line 1,537: | ||
Root Password : z8gCMQGvyumHiQFSjWV9iXd |
Root Password : z8gCMQGvyumHiQFSjWV9iXd |
||
</syntaxhighlight> |
|||
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 : |
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 : |
||
< |
<syntaxhighlight lang="sh"># xl create /etc/xen/linux.via.xentools.cfg</syntaxhighlight> |
||
You can change “dist” parameter and for Linux Distros that supported, Please look at “/usr/share/xen-tools/”. |
You can change “dist” parameter and for Linux Distros that supported, Please look at “/usr/share/xen-tools/”. |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost boot]# xl create /etc/xen/linux.via.xentools.cfg |
[root@localhost boot]# xl create /etc/xen/linux.via.xentools.cfg |
||
Line 1,568: | Line 1,561: | ||
libxl: info: libxl.c:1698:devices_destroy_cb: forked pid 24683 for destroy of domain 15 |
libxl: info: libxl.c:1698:devices_destroy_cb: forked pid 24683 for destroy of domain 15 |
||
</syntaxhighlight> |
|||
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. |
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. |
||
Line 1,574: | Line 1,567: | ||
Open your config file that generated by “Xen-Tools” via an editor like “nano” and add below lines to it : |
Open your config file that generated by “Xen-Tools” via an editor like “nano” and add below lines to it : |
||
<syntaxhighlight lang="sh"> |
|||
interface=['br0'] |
interface=['br0'] |
||
vif |
vif = [ 'ip=172.30.9.21 ,mac=00:16:3E:52:EF:69, bridge=br0' ] |
||
vnc="1" |
vnc="1" |
||
vnclisten="172.30.9.20" |
vnclisten="172.30.9.20" |
||
</syntaxhighlight> |
|||
I bold the parts that you must adding to your config file. |
I bold the parts that you must adding to your config file. |
||
Line 1,591: | Line 1,584: | ||
== {{anchor|Toc476606923}} Monitoring Xen project == |
|||
== {{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. |
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. |
||
Line 1,599: | Line 1,590: | ||
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 : |
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 : |
||
[[Image:Figure_36-_Xenmon.png|top|600px|none|thumb|Figure 36 : Xenmon.py.]] |
|||
[[Image:Figure_36-_Xenmon.png|top|600px|none|thumb]] |
|||
=====<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. |
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. |
||
Line 1,610: | Line 1,598: | ||
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 : |
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 : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# xenmon.py |
[root@localhost ~]# xenmon.py |
||
Line 1,652: | Line 1,640: | ||
[root@localhost ~]# |
[root@localhost ~]# |
||
</syntaxhighlight> |
|||
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 : |
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 : |
||
< |
<syntaxhighlight lang="sh"># xenmon.py --iocount --cpu=1 --allocated</syntaxhighlight> |
||
Another useful tool is “xentop”. You as a Linux administrator are familiar with “top” command in Linux Environment. |
Another useful tool is “xentop”. You as a Linux administrator are familiar with “top” command in Linux Environment. |
||
< |
<syntaxhighlight lang="sh"># xentop</syntaxhighlight> |
||
[[Image:Figure_37-_Xentop.png|top|600px|none|thumb|Figure 37 : Xentop.]] |
[[Image:Figure_37-_Xentop.png|top|600px|none|thumb|Figure 37 : Xentop.]] |
||
Line 1,668: | Line 1,657: | ||
1-''' VmStat''' |
|||
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... |
It is a useful command that display statistics of virtual memory, kernerl threads, disks, system processes, I/O blocks, interrupts, CPU activity and... |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# vmstat |
[root@localhost ~]# vmstat |
||
Line 1,679: | Line 1,669: | ||
0 2 60 130248 36912 3107996 0 0 7 7 20 9 0 0 100 0 0 |
0 2 60 130248 36912 3107996 0 0 7 7 20 9 0 0 100 0 0 |
||
</syntaxhighlight> |
|||
2-''' Tcpdump''' |
|||
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. |
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. |
||
< |
<syntaxhighlight lang="sh"># 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.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 |
||
Line 1,709: | Line 1,699: | ||
7 packets dropped by kernel |
7 packets dropped by kernel |
||
</syntaxhighlight> |
|||
3-''' Htop''' |
|||
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”. |
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”. |
||
< |
<syntaxhighlight lang="sh"># htop</syntaxhighlight> |
||
[[Image:Figure_38-_Htop.png|top|600px|none|thumb|Figure 38 : Htop.]] |
[[Image:Figure_38-_Htop.png|top|600px|none|thumb|Figure 38 : Htop.]] |
||
4-''' IPTraf''' |
|||
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”. |
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”. |
||
< |
<syntaxhighlight lang="sh"># iptraf-ng</syntaxhighlight> |
||
[[Image:Figure_39-_IPTraf.png|top|600px|none|thumb|Figure 39 : IPTraf.]] |
[[Image:Figure_39-_IPTraf.png|top|600px|none|thumb|Figure 39 : IPTraf.]] |
||
5- '''Nmon''' |
|||
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. |
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. |
||
Line 1,735: | Line 1,726: | ||
[[Image:Figure_40-_Nmon.png|top|600px|none|thumb|Figure 40 : Nmon.]] |
[[Image:Figure_40-_Nmon.png|top|600px|none|thumb|Figure 40 : Nmon.]] |
||
== {{anchor|Toc476606924}} 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 : |
|||
== {{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. |
* Provide a way to manage Pools. |
||
Line 1,749: | Line 1,735: | ||
* Support of SLA and mutli-tenancy. |
* 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] . |
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] . |
||
Line 1,757: | Line 1,742: | ||
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 : |
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 : |
||
< |
<syntaxhighlight lang="sh"># scp XenServer-7.0.0-main.iso root@172.30.9.20:/home/mohsen/</syntaxhighlight> |
||
After it, We must mount this .iso file thus create a directory with the name “cd” under “/mnt/” directory : |
After it, We must mount this .iso file thus create a directory with the name “cd” under “/mnt/” directory : |
||
< |
<syntaxhighlight lang="sh"># mkdir </syntaxhighlight>cd /mnt |
||
Then use below command to mount .iso file to “/mnt/cd” directory : |
Then use below command to mount .iso file to “/mnt/cd” directory : |
||
< |
<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 : |
Then change to “/mnt/cd” directory via “cd” command : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost ~]# cd /mnt/cd/ |
[root@localhost ~]# cd /mnt/cd/ |
||
Line 1,775: | Line 1,761: | ||
boot client_install EFI EULA install.img LICENSES Packages Read_Me_First.html repodata |
boot client_install EFI EULA install.img LICENSES Packages Read_Me_First.html repodata |
||
</syntaxhighlight> |
|||
You can see a directory with the name “ Packages” and move to it via “cd” command. After it you can find “XAPI” package here : |
You can see a directory with the name “ Packages” and move to it via “cd” command. After it you can find “XAPI” package here : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost Packages]# ls xapi-xe* |
[root@localhost Packages]# ls xapi-xe* |
||
xapi-xe-1.9.57-8535.x86_64.rpm |
xapi-xe-1.9.57-8535.x86_64.rpm |
||
</syntaxhighlight> |
|||
Then use “rpm” command to install it as below : |
Then use “rpm” command to install it as below : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost Packages]# rpm -Uvh xapi-xe-1.9.57-8535.x86_64.rpm |
[root@localhost Packages]# rpm -Uvh xapi-xe-1.9.57-8535.x86_64.rpm |
||
Preparing... |
Preparing... ################################# [100%] |
||
Updating / installing... |
Updating / installing... |
||
1:xapi-xe-1.9.57-8535 |
1:xapi-xe-1.9.57-8535 ################################# [100%] |
||
</syntaxhighlight> |
|||
After it you can see that we installed “xe” successfully and can use it : |
After it you can see that we installed “xe” successfully and can use it : |
||
<syntaxhighlight lang="sh"> |
|||
[root@localhost Packages]# xe |
[root@localhost Packages]# xe |
||
Line 1,805: | Line 1,793: | ||
xe help -s <server> -p <port> |
xe help -s <server> -p <port> |
||
</syntaxhighlight> |
|||
You may ask why we did it, We did it because you can control a Citrix XenServer host from your Xen Project or your Linux client. We will tell something about Citrix XenServer in the next chapter. |
You may ask why we did it, We did it because you can control a Citrix XenServer host from your Xen Project or your Linux client. We will tell something about Citrix XenServer in the next chapter. |
||
Line 1,814: | Line 1,803: | ||
3- For more information about VGA Passthrough Please look at : [http://wiki.xen.org/wiki/Xen_VGA_Passthrough http://wiki.xen.org/wiki/Xen_VGA_Passthrough] , [http://wiki.xen.org/wiki/VTdHowTo http://wiki.xen.org/wiki/VTdHowTo] , [http://wiki.xen.org/wiki/XenGT http://wiki.xen.org/wiki/XenGT] , [https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/ https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/] and [http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf] |
3- For more information about VGA Passthrough Please look at : [http://wiki.xen.org/wiki/Xen_VGA_Passthrough http://wiki.xen.org/wiki/Xen_VGA_Passthrough] , [http://wiki.xen.org/wiki/VTdHowTo http://wiki.xen.org/wiki/VTdHowTo] , [http://wiki.xen.org/wiki/XenGT http://wiki.xen.org/wiki/XenGT] , [https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/ https://blog.xenproject.org/2014/03/11/xen-graphics-virtualization-xengt/] and [http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf http://events.linuxfoundation.org/sites/events/files/slides/XenGT-LinuxCollaborationSummit-final_1.pdf] |
||
[[Category:Users]] [[Category:HelloXenProjectBook]] |
Latest revision as of 13:25, 27 September 2017
Chapter 4: Using Xen Project
Configuring and Booting Virtual Machines
Welcome to chapter 4, I bet this chapter is, the more interested chapter for you and you can learn to run and manage your Virtual Machines via The Xen Project. In this chapter, we show you how you can configure DomU and setting up your network and storage. We knows, You are familiar with Linux but we show you some Linux tools for manage LVM and create your partitions. After this chapter, You can manage Xen Project and your Virtual Machines and Install GNU/Linux and Windows OS on your Xen Project ax DomU. We will speak about a tool with the name “ virt-manager” that is a Graphical tool for managing your Vms.
By default, Fedora Server edition not have any Graphical Environment and as you know, The Graphical Environment need a lot of resources and not a good idea for server. So, System administrator don't like to install Graphical Environment and prefer CLI. You may ask yourself, Some Graphical Environment like “XFCE” need low resources but compared with CLI they need more resources.
Manage virtual machines with virt-manager
We want to show you “virt-manager” and it is a graphical program, Thus we need to install a Graphical Environment. Popular Desktops in Fedora are “Gnome” , “KDE” , “XFCE” and “MATE” but you can use other Desktops too.
For Install a Graphical Environment use below commands :
Gnome :
# yum groupinstall gnome
or
# yum groupinstall gdm
KDE :
# yum groupinstall kde
XFCE :
# yum groupinstall xfce
MATE :
# yum groupinstall "MATE Desktop”
When installing finished just run below command :
# startx
And after it you can see your Desktop. Mine is:
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 :
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 :
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” :
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
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
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
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
# 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 :
Let me to see our LVM via “vgdisplay” command :
# vgdisplay | more
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:
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 :
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 :
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.
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 :
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 :
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 :
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
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 :
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
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
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
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.
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