⬆️ ⬇️

Home server: Xen-based virtualization

By chance, I had to update the home server, the core 2 processor turned out to be a processor core 2 duo and decent memory (3 gigabytes). Because Usually the server was used as a file server, a router and a music server, I decided to use it with something so that the resources were not idle, since there are now quite a lot of them. I decided to set up a quite popular recently virtualization technology, so that it was possible to conduct various experiments with customization and build packages in various distributions / systems.

Technologies and systems

First, consider the existing virtualization technologies:
  1. Openvz

    The technology consists in the implementation of various systems with different settings and the root system under one core. This technology is often used in the provision of VDS / VPS services. Because the core is essentially the same, the loss of performance is minimal, but the choice of systems is limited to linux distributions with one core. There is a paid version of this system with a large number of functions: Virtuozzo.
  2. Xen

    The basis is the technology of paravirtualization. In short: the guest system is specially prepared for working with Xen, and accordingly a rather small performance loss is obtained. The guest system may be Linux (the kernel of the guest system may differ from the core of the main system), FreeBSD, NetBSD, OpenBSD, OpenSolaris, Plan 9, and others. It is also possible to run almost any system through Intel / AMD virtualization technologies, but you need a processor with support for these architectures. My server, unlike a laptop, as it turned out, does not support these technologies; therefore, this virtualization method will not be considered.
  3. VirtualBOX / VMWare / Qemu and similar emulation systems.

    These systems provide emulation at the cost of performance loss, so they will not be considered.
Xen is the best option because has the ability to virtualize a sufficiently large number of OS with minimal performance loss.

Installation and Setup

All actions were performed on a home server with a ubuntu-server, for other distributions you may have to change the actions a bit. First you need to install the kernel and the required set of utilities:
 apt-get install linux-headers-2.6.24-19-xen linux-image-2.6.24-19-xen \
 linux-ubuntu-modules-2.6.24-19-xen xen-hypervisor-3.2 xen-tools
Reboot to the new kernel and install xen-utils-3.2:
  apt-get install xen-utils-3.2 
Important: if you tried to install xen-3.1 before installing xen-3.2, you must remove all packages containing xen3.1 mentions, then install xen-hypervisor-3.2, and reboot, because xen-hypervisor makes some edits to the kernel boot. If you try to install xen-utils-3.2 before rebooting, you get an error, because xend will not be able to boot on the kernel for this not intended. The same symptoms will occur when trying to establish enomalism (web interface for controlling xen), since he pulls a xen3.1

Xen + Nvidia

It so happened that I have a video card from Nvidia, and on this server it is planned to launch a media center, respectively, it is necessary to use proprietary drivers. Initially I tried to install via envyng (a bunch of scripts for convenient installation of proprietary video card drivers in ubuntu), but the kernel panicked. When I tried to remove the driver and assemble with my hands, an unpleasant thing arose: while rebooting into the kernel, dkms reinstalled the driver. I had to remove the driver on all kernels ( dkms remove -m nvidia -v 173.14.12 - all ) and install it with my hands. When installing not envy drivers, install the old version (9x.xx.xx), which may cause problems. It is necessary to immediately say that the standard driver swears on the xen core, and refuses to install. A small recipe to get around this: Because the driver needs root permissions to install, and when sudo does not use the variables of the current user, then all commands must be executed from the root. Due to the fact that ubuntu does not have a root password, and it is not known how its installation will affect the system, you have to use a little trick to get a console with root permissions: sudo su or sudo bash (zsh, csh, etc)
 # export IGNORE_XEN_PRESENCE = 1
 # chmod a + x NVIDIA-Linux-x86-173.14.12-pkg2.run
 # ./NVIDIA-Linux-x86-173.14.12-pkg2.run </ i>
After the installation is completed, you need to exit the superuser console: exit Attention: this installation method is not recommended and is a rather bad practice, due to the fact that it will be rather difficult to remove this driver in the future, but since There is no other way, and to create and maintain a package for these purposes, which will probably conflict with packages in the repository is quite problematic, I used this method. You can build a package with drivers.

Creating and using images

In xen, you can use both ready-made images for virtual machines, and create your own. There is a large archive of ready-made images on jailtime.org . We will create our own image using xen-utils. Images are created using the xen-create-image command. We will create an image with debian etch 64-bit:
 xen-create-image -hostname = hostname -size = 10Gb -swap = 512Mb -ide -ip = 192.168.0.100 
 -netmask = 255.255.255.0 -gateway = 192.168.0.1 -force -dir = / xen -memory = 128Mb -arch = amd64 -dist = etch 
 -passwd
Important: the main system must be 64-bit in order to be able to create 64-bit guest systems. Options:we start the car on the basis of the created image:
  xm create /etc/xen/machinename.cfg 
Because we are using xen3.2 will most likely fall out the error message:
  Error: Device 769 (vbd) could not be connected.  losetup / dev / loop0 
 /xen/domains/machine_name/swap.img failed
This is due to the fact that xen-tools3.2 in the configuration file uses paths to disk files through file: / , while this parameter is removed from Xen3.2. To prevent this error, you need to replace paths with file: / xen / ... with tap: aio: / xen / ... in the disk section of the disk section /etc/xen/name-.cfg on the main system, for this in the file / etc / network / interfaces you need to add the following parameters to the internal interface:
  up ip addr 192.168.0.100/28 dev eth0 
Now we have a virtual machine that you can join over the network from any computer. In case the machine boots, but something goes wrong, you can always log into the local console using the command: xm console machine_name To autoload the virtual machine when When starting the system, you need to make a symlink from the machine configuration file in / etc / xen / auto:
  ln -s /etc/xen/machinename.cfg / etc / xen / auto / 

Basic commands for managing virtual machines:

That's all. Later maybe write about deploying Xen on a production server using LVM.


Other articles in this series: media center , proxy for SIP

Cross post from my blog


')

Source: https://habr.com/ru/post/37824/



All Articles