The Perfect Xen 3.0.3 Setup For Debian Sarge - Page 4

4.4.2 Create And Start The First Virtual Machine

Now we create our first virtual machine, vm01, by making a copy of our template:

cp -pf /vserver/images/vm_base.img /vserver/images/vm01.img
cp -pf /vserver/images/vm_base-swap.img /vserver/images/vm01-swap.img

Then we create a Xen configuration file for vm01, /etc/xen/vm01-config.sxp:

vi /etc/xen/vm01-config.sxp

name="vm01"
kernel="/boot/vmlinuz-2.6-xenU"
root="/dev/hda1"
memory=32
disk=['file:/vserver/images/vm01.img,hda1,w','file:/vserver/images/vm01-swap.img,hda2,w']

# network
vif=[ '' ]
dhcp="off"
ip="192.168.0.101"
netmask="255.255.255.0"
gateway="192.168.0.1"
hostname="vm01.example.com"

extra="3"

In memory you specify the RAM you want to allocate to that virtual machine (here: 32 MB). In disk you specify which images to use and how to mount them (i.e., under which partition, e.g. hda1). This must correspond to the settings in the image's /etc/fstab file! In the network settings we tell vm01 that its IP address is 192.168.0.101 (the main machine's (dom0) IP address is 192.168.0.100), and what hostname it has.

If you want vm01 to start automatically at the next boot of the system, then do this:

ln -s /etc/xen/vm01-config.sxp /etc/xen/auto

Now let's start vm01:

xm create -c /etc/xen/vm01-config.sxp

If nothing's wrong, vm01 should come up without problems, and you should be able to login. By running

iptables -L

you should see that iptables is available on vm01. To leave vm01's shell, type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY. From the outside you should be able to connect to 192.168.0.101 via SSH.

Back on dom0's shell, you can shutdown vm01 by running

xm shutdown vm01

Here are some other 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> - Login on a virtual machine.
xm help - List of all commands.

Now you can reboot the main system to see if vm01 comes up automatically (if you created the symlink in /etc/xen/auto):

shutdown -r now

 

4.4.3 Creating And Customizing Further Virtual Machines

You can create further virtual machines simply by copying the image template:

cp -pf /vserver/images/vm_base.img /vserver/images/vm02.img
cp -pf /vserver/images/vm_base-swap.img /vserver/images/vm02-swap.img

Then you have to create a Xen configuration file, e.g. /etc/xen/vm02-config.sxp:

vi /etc/xen/vm02-config.sxp

name="vm02"
kernel="/boot/vmlinuz-2.6-xenU"
root="/dev/hda1"
memory=32
disk=['file:/vserver/images/vm02.img,hda1,w','file:/vserver/images/vm02-swap.img,hda2,w']

# network
vif=[ '' ]
dhcp="off"
ip="192.168.0.102"
netmask="255.255.255.0"
gateway="192.168.0.1"
hostname="vm02.example.com"

extra="3"

Start the machine:

xm create -c /etc/xen/vm02-config.sxp

If you get an error like this:

Using config file "/etc/xen/vm02-config.sxp".
Error: Error creating domain: The privileged domain did not balloon!

then this means that the virtual machine tried to use more memory than is available. Edit the configuration file of the virtual machine and decrease the value of memory and try to start it again.

Create a symlink, if you want to start the virtual machine at boot time:

ln -s /etc/xen/vm02-config.sxp /etc/xen/auto

Now you can log into each machine, e.g. via SSH, and configure it as if it was a normal system.

You can create as many virtual machines as you like. Your hardware's the limit!

Share this page:

8 Comment(s)

Add comment

Comments

From: harm at: 2006-10-20 12:17:22

Falko, although this is interesting to use with Sarge on relatively old hardware its useless on new hardware... eg. mainboards with Intel's ICH7 bridge will simply not function with Sarge's kernel (2.6.8) and your better of with Etch in that case. And Etc gets Xen with an easy apt-get :)

From: decep at: 2006-10-24 14:35:06

Compiling separate dom0 and domU kernels is considered to be the "old way" of doing things.  Ever since Xen 3 was released, a single kernel can be used for both dom0 and domU.

From: at: 2006-11-15 10:32:50

I just wanted to add a precision about the command :

mv /lib/tls /lib/tls.disabled 

Xen team advise users to disable TLS (Thread Local Storage) because of performance issues. It's not absolutly needed.

See the Xen team explanation.

From: at: 2006-12-09 05:45:45

If you're trying to compile Xen under a minimal Sarge net installation, 2 additional packages need to be installed prior to running "make world" : xlibs-dev libncurses5-dev Without these packages, the compile will fail near the end (very frustrating 30 minutes into the process). Adding build-essential to the apt-get install statement at the top of the page couldn't hurt either for completeness. Other than this, an excellent howto.

From: at: 2007-01-24 15:44:32

In my case it was mandatory that I install the build-essential package for "make world" to succeed. Thanks

 Additionally, I was getting kernel panics when the mem statement was present in the grub menu config. Removing it eliminated the kernel panic.

From: at: 2007-02-15 01:02:34

gcc-3.3 installed but did not leave a link to gcc. 

ln -s /usr/bin/gcc-3.3 /usr/bin/gcc

ln -s /usr/bin/gccbug-3.3 /usr/bin/gccbug

 Fixed this and I could start step 4.1.

From: at: 2006-11-15 14:22:18

/vserver/images/mail.img is not a block special device.

With this tutorial, the right message should be :

/vserver/images/vm_base.img is not a block special device.

Regards,

From: at: 2007-05-06 16:13:39

During the make world command I had an issue not shure if it was due

to x86_64 or just the version of gcc I had.  I was getting errors like :

 

         LD      .tmp_vmlinux1
         init/built-in.o: In function `try_name':
         do_mounts.c:(.text+0x5d5): undefined reference to `__stack_chk_fail'
         init/built-in.o: In function `name_to_dev_t':

 

         initramfs.c:(.init.text+0x4001): undefined reference to   `__stack_chk_fail'

         arch/x86_64/kernel/built-in.o:(.text+0x3509): more undefined     references to  `__stack_chk_fail' follow

         make[1]: *** [.tmp_vmlinux1] Error 1

         make[1]: Leaving directory `/home/costin/linux-2.6.16.32'

         make: *** [debian/stamp-build-kernel] Error 2

 

It took a while but when I used -fno-stack-protector  like:

http://ubuntuforums.org/showthread.php?t=303541

All compiled like it was supposed to.  I am just now finishing my custom kernel to reboot to.