Home Server: Xen-based Virtualization
By chance, I had to update my home server, the core 2 duo processor and decent memory (3 gigabytes) turned out to be in the new server. Because Usually the server was used as a file cleaner, a router and a music server, I decided to take it with something so that the resources did not stand idle, since now there are a lot of them. I decided to configure virtualization technology, quite popular recently, so that it would be possible to conduct various experiments with tuning and collect packages in various distributions / systems.
Other articles in the series: media center , proxies for SIP
Cross-post from my blog
Technologies and systems
To get started, consider existing virtualization technologies:- OpenVZ
technology consists in executing 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 kernel is essentially the same thing, the performance loss is minimal, but the choice of systems is limited to linux distributions with a single core. There is a paid version of this system with a large number of functions: Virtuozzo. - Xen
The basis is paravirtualization technology. In short: the guest system is specially prepared for working with Xen, and, accordingly, a rather small loss of performance is obtained. The guest system can be Linux (the guest system kernel may differ from the core system), FreeBSD, NetBSD, OpenBSD, OpenSolaris, Plan 9, and others. It is also possible to launch 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, so this virtualization method will not be considered. - VirtualBOX / VMWare / Qemu and similar emulation systems.
These systems provide emulation at the cost of performance loss; therefore, they will not be considered.
Installation and setup
All actions were carried out on the home server with ubuntu-server, for other distributions you may have to change the actions a bit. Initially, you need to install the kernel and the necessary 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-toolsWe reboot into the new kernel and install xen-utils-3.2:
apt-get install xen-utils-3.2Important: if you tried to install xen-3.1 before installing xen-3.2, you must remove all packages containing xen3.1 references, then install xen-hypervisor-3.2, and reboot, as xen-hypervisor makes some changes to the kernel boot. If you try to install xen-utils-3.2 before rebooting, an error will occur, because xend will not be able to boot on the kernel for this purpose not intended. The same symptoms will be when trying to install enomalism (web interface for managing xen), because he pulls xen3.1
Xen + Nvidia
It so happened that I have a video card from Nvidia, and it is planned to launch a media center on this server, so I have 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 trying to remove the driver and assemble it with my hands, an unpleasant thing occurred: rebooting into the kernel, dkms reinstalled the driver. I had to remove the driver on all cores ( dkms remove -m nvidia -v 173.14.12 --all) and put it with your hands. When installing non-envy drivers, the old version (9x.xx.xx) is installed, which may cause problems. It must be said right away that the standard driver swears at the xen kernel, and refuses to install. A small recipe to get around this: the driver needs root privileges to install, and with sudo the variables of the current user are not used, then all the commands must be run 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 superuser rights: 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.runAfter the installation is completed, you must exit the superuser console: exit Attention: this installation method is not recommended and is a pretty bad practice, due to the fact that it will be quite difficult to remove this driver in the future, but since There is no other way, and creating and maintaining a package for these purposes, which will possibly conflict with packages in the repository, is quite problematic, I used this method. You can build a driver package.
Creating and using images
In xen, you can use ready-made images for virtual machines, or create your own. A large archive of ready-made images is on jailtime.org . We will create our image using xen-utils. The images are created using the xen-create-image command. Let's create an image with debian etch 64-bit:xen-create-image -hostname = machine-name -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 -passwdImportant: the main system must be 64-bit in order to be able to create 64-bit guest systems.
- hostname: system hostname and image name
- size : image disk size
- swap : swap file size for the image
- ide : use ide driver for disk
- ip : ip image address
- netmask : image network mask
- gateway : the ip address of the router (in this case, the ip of the main system)
- force : overwrites already created images
- dir : the directory in which the image will be contained
- memory : memory size allocated to the system
- arch : system architecture (amd64, i386, etc)
- dist : the distribution you want to install
- passwd : request root password for image
xm create /etc/xen/ machine_name.cfgBecause we use xen3.2 most likely the error message will fall out:
Error: Device 769 (vbd) could not be connected. losetup / dev / loop0 /xen/domains/machinename/swap.img failedThis is due to the fact that xen-tools3.2 in the configuration file uses paths to disk files via file: / , while this parameter is removed from Xen3.2. To avoid this error, it is necessary to change the paths from file: / xen / ... to tap: aio: / xen / ... in the configuration file /etc/xen/ machine_name.cfg in the disk section . You also need to configure network support on the main system, for this, in the / etc / network / interfaces file, you need to add the following parameters to the internal interface:
up ip addr 192.168.0.100/28 dev eth0Now we have a virtual machine that can be connected over the network from any computer. If the machine boots up, but something went wrong, you can always go to the local console using the command: xm console machine_name To start the virtual machine at When starting the system, you need to make a symlink from the machine configuration file in / etc / xen / auto:
ln -s /etc/xen/ machine_name.cfg / etc / xen / auto /
Basic commands for managing virtual machines:
- xm console - calls the first terminal of the virtual machine
- xm create - starts a virtual machine based on the configuration file
- xm pause - temporarily stops the virtual machine
- xm unpause - starts a virtual machine after stopping
- xm save - saves the state of the virtual machine
- xm restore - restores the state of a virtual machine
- xm reboot - reboots a virtual machine
- xm shutdown - shuts down the virtual machine
- xentop - shows the current load of all virtual machines
- xm list - list of running virtual machines
- xm dmesg - shows a dmesg virtual machine
- xm delete - deletes a virtual machine
- xm destroy - force deletes a virtual machine
Other articles in the series: media center , proxies for SIP
Cross-post from my blog