The Perfect Xen Setup For Debian And Ubuntu - Page 4
4 Create A Virtual Machine (domU)
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
4.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/ http://ftp2.de.debian.org/debian
chroot /vserver/vm_base
apt-setup
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:
deb http://ftp2.de.debian.org/debian/ stable 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. |
They are not serious, but ugly... So we run
apt-get install localeconf
Select locales to install (e.g. en_US ISO-8859-1) and select the standard locale (e.g. en_US).
You will be asked a few questions:
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
base-config
You will see a menu with installation options. This is what we do:
- Configure timezone
- Set up users and passwords
- 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.)
- 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
rm -f /etc/hostname
Then edit /etc/fstab. It should look like this:
/dev/hda1 / ext3 defaults 1 2 |
Change /etc/network/interfaces to look like this:
auto lo |
Then create /etc/hosts:
127.0.0.1 localhost.localdomain localhost |
Now we leave the chroot environment:
exit
Then we copy over the kernel modules to our virtual machine image and unmount the image:
cp -dpR /lib/modules/2.6.11.12-xenU /vserver/vm_base/lib/modules/
mv /vserver/vm_base/lib/tls /vserver/vm_base/lib/tls.disabled
umount /vserver/vm_base
If you get a warning like this: umount: /vserver/vm_base: device is busy don't worry about it, it's not important.
Now our virtual machine image template is ready!