The Perfect Xen 3.0.3 Setup For Debian Sarge - Page 7

5.2 Create A Virtual Machine (domU)

(Please note: image creation depends on whether you installed Xen from the sources or from the binaries. If you installed Xen from the sources, please refer to chapter 4.4!)

Next we create an image of a virtual machine. It will be a basic Debian system. This image will be the template for all our virtual machines. Whenever we want to create a new virtual machine, we just copy this image, create a new Xen configuration file and boot the copy, and then we can go on and configure the copy to our needs (e.g install a mail server, web server, DNS server, etc. on it). All our images will be on the /vserver partition which should be the largest one we have.

mkdir /vserver/vm_base
mkdir /vserver/images

Now we create a 1 GB image file and a 500 MB swap image. In the end the virtual machines will have 1 GB space and 500 MB swap. These are just example values, in the real world you might want to have more space for your virtual machines (e.g. between 5 and 30 GB), so just increase the value of count to create larger images.

dd if=/dev/zero of=/vserver/images/vm_base.img bs=1024k count=1000
dd if=/dev/zero of=/vserver/images/vm_base-swap.img bs=1024k count=500

Then we format /vserver/images/vm_base.img with ext3 and vm_base-swap.img with swap:

mkfs.ext3 /vserver/images/vm_base.img

When you see the following, answer with y:

/vserver/images/mail.img is not a block special device.
Proceed anyway? (y,n) <-- y
mkswap /vserver/images/vm_base-swap.img


5.2.1 Install A Basic Debian In The Image

In order to install a basic Debian system in our image, we mount the image, run debootstrap and a few other commands:

mount -o loop /vserver/images/vm_base.img /vserver/vm_base
debootstrap --arch i386 sarge /vserver/vm_base/
chroot /vserver/vm_base

You are asked the following question:

Archive access method for apt: <-- http

Then select a mirror close to you.

Afterwards, edit /etc/apt/sources.list and replace testing with stable. That's how my /etc/apt/sources.list looks:

vi /etc/apt/sources.list
deb stable main
deb-src stable main

deb stable/updates main

Then run

apt-get update

Now we set up our locales. If we do not do this now, we will see some ugly warnings during base-config like these:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_DE:en_US:en_GB:en",
        LC_ALL = (unset),
        LANG = "en_US"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

They are not serious, but ugly... So we run

apt-get install localeconf

You will be asked a few questions:

Select locales to be generated. <-- en_US ISO-8859-1
Which locale should be the default in the system environment?
<-- en_US
Manage locale configuration files with debconf?
<-- Yes
Environment settings that should override the default locale:
<-- do not select anything
Replace existing locale configuration files?
<-- Yes
Default system locale:
<-- e.g. en_US ISO-8859-1

Next run


You will see a menu with installation options. This is what we do:

  1. Configure timezone
  2. Set up users and passwords
  3. Select and install packages (when it comes to Choose software to install:, you can choose whatever you like; I, however, choose nothing because I want to install a basic system.)
  4. Finish configuring the base system

Don't deal with the other menu items, you don't need them. Then we remove nfs-common and delete /etc/hostname:

apt-get remove nfs-common

Then edit /etc/fstab. It should look like this:

vi /etc/fstab
/dev/hda1               /               ext3    defaults        1       2
/dev/hda2               none            swap    sw            0       0
/dev/pts                devpts          gid=5,mode=620    0       0
none                    /dev/shm        tmpfs   defaults     0       0

Then create /etc/hosts:

vi /etc/hosts       localhost.localdomain   localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Then do this:

mkdir /lib/modules/

Next we edit the scripts /etc/init.d/ and /etc/init.d/ and add the line exit 0 right at the beginning because otherwise these two scripts will really slow down the bootup of our virtual machines:

vi /etc/init.d/
#    Set and adjust the CMOS clock, according to the UTC
#               setting in /etc/default/rcS (see also rcS(5)).
# Version:      @(#)  2.00  14-Dec-1998  [email protected]
# Patches:
#               2000-01-30 Henrique M. Holschuh <[email protected]>
#                - Minor cosmetic changes in an attempt to help new
#                  users notice something IS changing their clocks
#                  during startup/shutdown.
#                - Added comments to alert users of hwclock issues
#                  and discourage tampering without proper doc reading.

# WARNING:      Please read /usr/share/doc/util-linux/README.Debian.hwclock
#               before changing this file. You risk serious clock
#               misbehaviour otherwise.

exit 0
vi /etc/init.d/
# Set system clock to hardware clock, according to the UTC
#               setting in /etc/default/rcS (see also rcS(5)).
# WARNING:      Runs without write permission on /etc, and before
#               mounting all filesystems! If you need write permission
#               to do something, do it in
# WARNING:      If your hardware clock is not in UTC/GMT, this script
#               must know the local time zone. This information is
#               stored in /etc/localtime. This might be a problem if
#               your /etc/localtime is a symlink to something in
#               /usr/share/zoneinfo AND /usr isn't in the root
#               partition! The workaround is to define TZ either
#               in /etc/default/rcS, or in the proper place below.

# Set this to any options you might need to give to hwclock, such
# as machine hardware clock type for Alphas.

exit 0


Now we leave the chroot environment:


Then we unmount the image:

mv /vserver/vm_base/lib/tls /vserver/vm_base/lib/tls.disabled
fuser -k /vserver/vm_base
umount /vserver/vm_base

Now our virtual machine image template is ready!

Share this page:

0 Comment(s)