Xen 03 - domU
Xen on Debian 4 Learning · Previous: dom0 · Next: domU - backup with LVM snapshots
The Slovak original of this document: Xen 03 - domU (slovensky).
|=----------------------------------=[ XEN ]=------------------------------=| +---------------------------------------------------------------------------+ | | | XEN - domU (vmware) | | Debian 4.0 Etch | | | +---------------------------------------------------------------------------+ |=-------------------------------=[ BH 2007 ]=-----------------------------=|
1. Creating a new virtual machine (LVM)
Install the utilities for managing xen hosts
--------------------------------------------
# apt-get install xen-tools
Set the parameters the new VM host needs
# nano /etc/xen-tools/xen-tools.conf
------------------------------------
lvm = nejaka_volume_group
debootstrap = 1
size = 3Gb
memory = 64Mb
swap = 128Mb
fs = ext3
dist = etch
gateway = 10.62.1.1
netmask = 255.255.0.0
passwd = 1
kernel = /boot/vmlinuz_nejake_jadro_v_boot
e.g. /boot/vmlinuz-2.6.18-5-xen-686
initrd = /boot/initrd_nejaky_initrd_v_boot
e.g. /boot/initrd.img-2.6.18-5-xen-686
------------------------------------END-/etc/xen-tools/xen-tools.conf
Create a VM host named www.vhosts.example with the IP address 10.62.2.45
------------------------------------------------------------------------
# xen-create-image --ip=10.62.2.45 --hostname=www.vhosts.example
Start the newly created VM host and switch to its console (-c)
--------------------------------------------------------------
# xm create -c www.vhosts.example.cfg
Install 2 packages to prevent warnings from APT
-----------------------------------------------
# apt-get install locales console-data
Configure the locales package
-----------------------------
# dpkg-reconfigure locales
Leaving the virtual machine console
-----------------------------------
CTRL + ]
Returning to the virtual machine console
----------------------------------------
# xm console www.vhosts.example
Shutting down the virtual machine
---------------------------------
# xm shutdown -H www.vhosts.example
Destroying the virtual machine [destroy] (!!! does not do a clean shutdown !!!)
-------------------------------------------------------------------------------
# xm destroy www.vhosts.example
To have the virtual machine start when the dom0 machine boots
-------------------------------------------------------------
# mkdir /etc/xen/auto
# ln -s /etc/xen/www.vhosts.example.cfg /etc/xen/auto/2. Setting up the network (routed network)
----
dom0
----
# nano /etc/xen/xend-config.sxp
-------------------------------
(network-script network-route)
(vif-script vif-route)
-----------
www.vhosts.example
-----------
# nano /etc/xen/www.vhosts.example.cfg
-------------------------------
vif = [ 'ip=10.62.2.45' ]
---------------------------------------------------
workstation (from which I connect to dom0 and domU)
---------------------------------------------------
# route add 10.62.2.45 gw 10.62.2.443. Setting up the network (NAT-ed network)
----
dom0
----
# nano /etc/xen/xend-config.sxp
-------------------------------
(network-script network-nat)
(vif-script vif-nat)
Enable SNAT for the network 192.168.1.0/24
------------------------------------------
# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 10.62.2.44
Redirect requests for 10.62.2.44:2222 to 192.168.1.2:22
-------------------------------------------------------
# iptables -t nat -A PREROUTING -p tcp -s 10.62.2.22 -d 10.62.2.44 --dport 2222 -j DNAT --to-destination 192.168.1.2:22
Redirect requests for 10.62.2.44:80 to 192.168.1.2:80
-----------------------------------------------------
# iptables -t nat -A PREROUTING -p tcp -s 10.62.2.22 -d 10.62.2.44 --dport 80 -j DNAT --to-destination 192.168.1.2:80
-----------
www.vhosts.example
-----------
# nano /etc/xen/www.vhosts.example.cfg
-------------------------------
vif = [ 'ip=192.168.1.2' ]
Notes
------
iptables -t nat -A PREROUTING -m physdev --physdev-in vif1.0 -p tcp -s 10.62.2.45 -d 10.62.2.44 --dport 8080 -j DNAT --to-destination 10.62.1.1:8080
iptables -t nat -A POSTROUTING -m physdev --physdev-out vif1.0 -p tcp -s 10.62.2.45 -d 10.62.1.1 --dport 8080 -j SNAT --to-source 10.62.2.44
create the logical partition 'xen1' for the first virtual machine
-----------------------------------------------------------------
# lvcreate -L 2G -n xen1 nejaka_volume_group
RAID1
-----
disk1 -|
|- LVM (VG-system - system partitions for the virtual machines)
disk2 -|
-----
/dev/system/www.vhosts.example-disk
/dev/system/www.vhosts.example-swap
RAID1
-----
disk1 -|
|- LVM (VG-data - data partitions for the virtual machines)
disk2 -|
-----
/dev/data/www.vhosts.example-usr
/dev/data/www.vhosts.example-local
...DISKS
If we use a single partition
----------------------------
disk = [ 'phy:/dev/hdX,hda1,w' ]
If we use several partitions
----------------------------
disk = [ 'phy:/dev/hdX,hda1,w', 'phy:/dev/hdY,hda2,w' ]
If we use a single file
-----------------------
disk = [ 'file:/stroje/stroj.img,hda1,w' ]
If we use several files
-----------------------
disk = [ 'file:/stroje/stroj.img,hda1,w', 'file:/stroje/stroj_usr.img,hda2,w' ]X. Linkz
http://www1.shorewall.net/XenMyWay.html
http://www1.shorewall.net/XenMyWay-Routed.html
XEN on DEBIAN domU
------------------
http://wiki.xensource.com/xenwiki/DebianDomU
http://www.jejik.com/articles/2007/03/a_test_drive_of_debian_etch_xen/
http://blackhole.sk/topicxen-ha-cluster-installation
LVM XEN
-------
http://wiki.rpath.com/wiki/Xen_DomU_Guide
preparing LVM for dom0
----------------------
http://wiki.rpath.com/wiki/Virtual_Appliances:Essential_Logical_Volume_Management_for_Xen_DomU_Deployment
http://julien.danjou.info/xen.htmlCurrent practice (checked 2026-10)
noteThe article above is kept as it was written in 2008. This section lists what has changed since and what to do instead today.
- xm commands:
xmwas removed in Xen 4.5. The same steps withxlare below; note thatxl shutdownhas no-Hoption (use-wto wait for the guest to go down).
$ # xl create -c /etc/xen/www.vhosts.example.cfg $ # xl console www.vhosts.example $ # xl shutdown -w www.vhosts.example $ # xl destroy www.vhosts.example
- xen-tools:
xen-create-imagecomes from thexen-toolspackage, which is in Debian unstable but was removed from testing in February 2025 and is not in the current stable release.dist = etchinstalls a release that has been end-of-life since 2010-02-15. - Guest kernel:
kernel =andinitrd =point at the dom0's own kernel in/boot, so every guest runs the dom0 kernel and cannot update it by itself. Today the guest config can load GRUB instead (packagegrub-xen, for examplekernel = "/usr/lib/grub-xen/grub-i386-xen_pvh.bin"for a PVH guest) and the guest boots the kernel installed inside its own filesystem. The olderpygrubis deprecated. - Guest type: these are PV guests. Add
type = "pvh"for a current Linux guest;memoryandvcpusare plain numbers in anxlconfig, and embedded Python is not supported. - Network scripts:
(network-script ...)and(vif-script ...)inxend-config.sxpno longer exist. The hotplug script is chosen per interface withscript=in thevifline (defaultvif-bridge, bridgexenbr0); routing, forwarding and NAT in dom0 are yours to set up. - iptables and route: the NAT rules still load through the
iptables-nftcompatibility layer, but nftables is the default framework in Debian since Debian 10 and new rule sets are written fornft.route add 10.62.2.45 gw 10.62.2.44isip route add 10.62.2.45 via 10.62.2.44with iproute2. - Disk lines: the
phy:andfile:prefixes are stripped and ignored byxl, and for Linux PV guests onlyxvd*device names are recommended, because thehda1/sda1names stop working with recent guest kernels. A current line looks like this:
disk = [ '/dev/system/www.vhosts.example-disk,raw,xvda1,rw' ]
Sources: