The Perfect Xen 3.1.0 Setup For Debian Etch (i386) - Page 3

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2007-06-03 17:14. ::

4.2 Creating Virtual Machines (domU)

We will use xen-tools to create virtual machines. xen-tools make it very easy to create virtual machines - please read this tutorial to learn more: http://www.howtoforge.com/xen_tools_xen_shell_argo. xen-tools are available as a Debian Etch package, so we install that one right now:

apt-get install xen-tools

Next we edit /etc/xen-tools/xen-tools.conf. This file contains the default values that are used by the xen-create-image script unless you specify other values on the command line. I changed the following values and left the rest untouched:

vi /etc/xen-tools/xen-tools.conf

[...]
gateway   = 192.168.0.1
netmask   = 255.255.255.0

passwd = 1

kernel = /boot/vmlinuz-2.6.18-xen
#initrd = /boot/initrd.img-2.6.16-2-xen-686

mirror = http://ftp2.de.debian.org/debian/
[...]

Please make sure that you comment out the initrd line! At least on my installations I've never needed a ramdisk for virtual machines.

The passwd = 1 line makes that you can specify a root password when you create a new guest domain. In the kernel line you must specify the domU kernel that you want to use for your guest domains. In the mirror line specify a Debian mirror close to you.

Make sure you specify a gateway and netmask. If you don't, and you don't specify a gateway and netmask on the command line when using xen-create-image, your guest domains won't have networking even if you specified an IP address!

Now let's create our first guest domain, xen1.example.com, with the IP address 192.168.0.101:

xen-create-image --hostname=xen1.example.com --size=2Gb --swap=256Mb --ide \
--ip=192.168.0.101 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
--dir=/vserver --memory=32Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.18-xen \
--debootstrap --dist=etch --mirror=http://ftp2.de.debian.org/debian/ --passwd

A lot of switches are unnecessary here because we specified the same details in /etc/xen-tools/xen-tools.conf but it shows that you can specify the desired settings either on the command line or in /etc/xen-tools/xen-tools.conf. Please make sure that you specify --ide, otherwise your virtual machine might not boot!

(To learn more about the available options, take a look at the xen-create-image man page:

man xen-create-image

)

The xen-create-image command will now create the xen1.example.com virtual machine for us. This can take a few minutes. The output should be similar to this one:

server1:~# xen-create-image --hostname=xen1.example.com --size=2Gb --swap=256Mb --ide \
>   --ip=192.168.0.101 --netmask=255.255.255.0  --gateway=192.168.0.1 --force \
>   --dir=/vserver --memory=32Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.18-xen \
>   --debootstrap --dist=etch --mirror=http://ftp2.de.debian.org/debian/ --passwd

General Infomation
--------------------
Hostname       :  xen1.example.com
Distribution   :  etch
Fileystem Type :  ext3

Size Information
----------------
Image size     :  2Gb
Swap size      :  256Mb
Image type     :  sparse
Memory size    :  32Mb
Kernel path    :  /boot/vmlinuz-2.6.18-xen

Networking Information
----------------------
IP Address 1   : 192.168.0.101
Netmask        : 255.255.255.0
Gateway        : 192.168.0.1

WARNING
-------
Loopback module not loaded and you're using loopback images
Run the following to load the module:

modprobe loop loop_max=255


Creating swap image: /vserver/domains/xen1.example.com/swap.img
Done

Creating disk image: /vserver/domains/xen1.example.com/disk.img
Done

Creating ext3 filesystem on /vserver/domains/xen1.example.com/disk.img
Done

Installing your system with debootstrap mirror http://ftp2.de.debian.org/debian/
Done

Running hooks
Done

No role script specified.  Skipping

Creating Xen configuration file
Done
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done


Logfile produced at:
         /var/log/xen-tools/xen1.example.com.log
server1:~#

(You can ignore this warning:

WARNING
-------
Loopback module not loaded and you're using loopback images
Run the following to load the module:

modprobe loop loop_max=255

The virtual machine will work nevertheless.)

There should now be a xen1.example.com configuration file - /etc/xen/xen1.example.com.cfg. Take a look at it to become familiar with virtual machines configuration files:

cat /etc/xen/xen1.example.com.cfg

#
#  Configuration file for the Xen instance xen1.example.com, created on
# Mon May 28 20:53:05 2007.
#


#
#  Kernel + memory size
#
kernel  = '/boot/vmlinuz-2.6.18-xen'

memory  = '32'


#
#  Disk device(s).
#
root    = '/dev/hda1 ro'

disk    = [ 'file:/vserver/domains/xen1.example.com/disk.img,hda1,w', 'file:/vserver/domains/xen1.example.com/swap.img,hda2,w' ]

#
#  Hostname
#
name    = 'xen1.example.com'


#
#  Networking
#
vif  = [ 'ip=192.168.0.101' ]

#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

To start the virtual machine, run

xm create /etc/xen/xen1.example.com.cfg

Run

xm console xen1.example.com

to log in on that virtual machine (type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0), or use an SSH client to connect to it (192.168.0.101).

To get a list of running virtual machines, type

xm list

The output should look like this:

server1:~# xm list
Name                                      ID   Mem VCPUs      State   Time(s)
Domain-0                                   0   301     1     r-----   1191.0
xen1.example.com                           1    32     1     -b----     50.6
server1:~#

To shut down xen1.example.com, do this:

xm shutdown xen1.example.com

If you want xen1.example.com to start automatically at the next boot of the system, then do this:

ln -s /etc/xen/xen1.example.com.cfg /etc/xen/auto

Here are the most important Xen commands:

xm create -c /path/to/config - Start a virtual machine.
xm shutdown <name> - Stop a virtual machine.
xm destroy <name> - Stop a virtual machine immediately without shutting it down. It's as if you switch off the power button.
xm list - List all running systems.
xm console <name> - Log in on a virtual machine.
xm help - List of all commands.

Let's create a second vm, xen2.example.com with the IP address 192.168.0.102:

xen-create-image --hostname=xen2.example.com --size=2Gb --swap=256Mb --ide \
--ip=192.168.0.102 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
--dir=/vserver --memory=32Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.18-xen \
--debootstrap --dist=etch --mirror=http://ftp2.de.debian.org/debian/ --passwd

Afterwards, you can start xen2.example.com like this:

xm create /etc/xen/xen2.example.com.cfg

and shut it down like this:

xm shutdown xen2.example.com

A list of all virtual machines that were created with the xen-create-image command is available under

xen-list-images

server1:~# xen-list-images
Name: xen1.example.com
Memory: 32
IP: 192.168.0.101

Name: xen2.example.com
Memory: 32
IP: 192.168.0.102
server1:~#

To learn more about what you can do with xen-tools, take a look at this tutorial: http://www.howtoforge.com/xen_tools_xen_shell_argo


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by LeoLinux (registered user) on Wed, 2007-11-14 23:14.

Hi,

 I think there isa newer version of xen utils neccessary, because the XEN-3.1.0 Binary version seems to be to new ...

It also asked a lots of questions about replacing scripts when I installed xen utils via aptitude - and after rebooting it a secound time my xen bridge settings got lost and I wheren't able to start any virtual machine again.

There might be an update of the Howto neccessary ...

 

Thanks 

J. K. S.

Submitted by wrongdoze (registered user) on Fri, 2007-10-26 23:33.

 You say:

> Please make sure that you comment out the initrd line!

When I did this my LVM-based VM's wouldn't boot.

Submitted by arnageddon (registered user) on Fri, 2007-09-07 20:32.

Dear Author

please add the bcc package to your requirements. The hvmloader won´t be compiled without it. It took me an hour or so to discover the missing package.

Best Regards an thx for the Howto

arnageddon