LINUXOR.SK ... open source notes ...

Xen 03 - domU

category: learnz/xen · date: 2008-01-09 · source: old.linuxor.sk/VIRTUALIZATION/BASIC/BH_Debian4.0_XEN_domU.txt · theme: github

Xen on Debian 4 Learning · Previous: dom0 · Next: domU - backup with LVM snapshots

The Slovak original of this document: Xen 03 - domU (slovensky).

asciiart
|=----------------------------------=[ XEN ]=------------------------------=|
+---------------------------------------------------------------------------+
|                                                                           |
|                               XEN - domU (vmware)                         |
|                                 Debian 4.0 Etch                           |
|                                                                           |
+---------------------------------------------------------------------------+
|=-------------------------------=[ BH 2007 ]=-----------------------------=|

1. Creating a new virtual machine (LVM)

asciiart
        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)

asciiart
----
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.44

3. Setting up the network (NAT-ed network)

asciiart
----
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

asciiart
        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

asciiart
        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.html

Current 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.
bash
$ # 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
ini
disk = [ '/dev/system/www.vhosts.example-disk,raw,xvda1,rw' ]

Sources:

← learnz/xen(EN | SK)