J’ai donc un serveur installé sous Debian 6. je souhaite installer une VM sur ce serveur sous Debian 6 (même système que sur le DOM0).
Je part du principe que XEN est déjà installé et configuré sur le DOM0. Il ne reste plus qu’à créer et initialiser la VM.
Comme j’ai installé les xen-tools sur mon DOM0, je peux utiliser cette commande (voir l’article pour la solution complète sans les xen-tools).
En premier lieu, il faut donc editer et modifier le fichier /etc/xen-tools/xen-tools.conf
[...]
#
##
# Output directory for storing loopback images.
#
# If you choose to use loopback images, which are simple to manage but
# slower than LVM partitions, then specify a directory here and uncomment
# the line.
#
# New instances will be stored in subdirectories named after their
# hostnames.
#
##
dir = /srv/xen/domains
[...]
#
##
#
# Installation method.
#
# There are four distinct methods which you may to install a new copy
# of Linux to use in your Xen guest domain:
#
# - Installation via the debootstrap command.
# - Installation via the rpmstrap command.
# - Installation via the rinse command.
# - Installation by copying a directory containing a previous installation.
# - Installation by untarring a previously archived image.
#
# NOTE That if you use the "untar", or "copy" options you should ensure
# that the image you're left with matches the 'dist' setting later in
# this file.
#
#
##
#
#
# install-method = [ debootstrap | rinse | rpmstrap | copy | tar ]
#
#
install-method = debootstrap
[...]
#
##
# Disk and Sizing options.
##
#
size = 4Gb # Disk image size.
memory = 128Mb # Memory size
swap = 128Mb # Swap size
# noswap = 1 # Don't use swap at all for the new system.
fs = ext4 # use the EXT4 filesystem for the disk image.
dist = `xt-guess-suite-and-mirror --suite` # Default distribution to install.
image = sparse # Specify sparse vs. full disk images.
##
# Networking setup values.
##
#
# Uncomment and adjust these network settings if you wish to give your
# new instances static IP addresses.
#
gateway = 192.168.50.254
netmask = 255.255.255.0
broadcast = 192.168.50.255
#
# Uncomment this if you wish the images to use DHCP
#
# dhcp = 1
#
# Uncomment and adjust this setting if you wish to give your new
# instances a specific nameserver.
#
# By default, nameserver is not set, and Dom0's /etc/resolv.conf will
# be copied to guest.
#
nameserver = 192.168.50.1
#
[...]
#
# Default kernel and ramdisk to use for the virtual servers
#
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
#
# The architecture to use when using debootstrap, rinse, or rpmstrap.
#
# This is most useful on 64 bit host machines, for other systems it
# doesn't need to be used.
#
# arch = [i386|amd64]
#
#
# The default mirror for debootstrap to install Debian-derived distributions
#
mirror = `xt-guess-suite-and-mirror --mirror`
[...]
#
# Filesystem options for the different filesystems we support.
#
ext4_options = noatime,nodiratime,errors=remount-ro
ext3_options = noatime,nodiratime,errors=remount-ro
ext2_options = noatime,nodiratime,errors=remount-ro
xfs_options = defaults
reiserfs_options = defaults
btrfs_options = defaults
Il ne nous reste plus qu’à créer l’image elle-même
xen-create-image --size=20Gb --memory=512Mb --fs=ext4 --dist=wheezy
--hostname=www.example.net --ip=xxx.xxx.xxx.xxx
--netmask=255.255.255.0 --swap=1024Mb --arch=amd64
--kernel=/boot/vmlinuz-2.6.32-5-xen-amd64
--mirror=http://ftp.fr.debian.org/debian/ --passwd
Et voilà, la machine virtuelle est donc configurée. Il ne nous reste plus qu’à la démarrer
xm create /etc/xen/www.example.net.cfg
Using config file "/etc/xen/www.example.net.cfg".
Started domain www.example.net.cfg (id=2)
Et en dernier, nous allons configurer cette nouvelle machine. Pour cela, nous avons deux manières pour s’y connecter
- xm console www.example.net
- ssh root@www.example.net (le mot de passe a été saisi lors de l’appel de la commande xen-create-image)
Une fois connecté, nous allons configurer quelques éléments de base :
Editez le fichier /etc/apt/sources.list :
deb http://ftp.fr.debian.org/debian wheezy main contrib non-free
deb-src http://ftp.fr.debian.org/debian wheezy main contrib non-free
#
#Sec
deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free
#
#anciennement debian-volatile
deb http://ftp.fr.debian.org/debian wheezy-updates main contrib non-free
deb-src http://ftp.fr.debian.org/debian wheezy-updates main contrib non-free
Mettez les paquets à jour, puis installez les locales :
aptitude update
aptitude safe-upgrade
aptitude install locales
dpkg-reconfigure locales
aptitude install console-data
dpkg-reconfigure console-data # from arch > french > latin9)
tzselect
dpkg-reconfigure tzdata
mkdir /srv/data
Configurez /etc/network/interfaces :
auto lo
iface lo inet loopback
#
auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask 255.255.255.0
network xxx.xxx.xxx.0
broadcast xxx.xxx.xxx.255
gateway xxx.xxx.xxx.1
dns-nameservers xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx
dns-search example.net
Configurez votre fichier /etc/hosts :
127.0.0.1 localhost.localdomain localhost
xxx.xxx.xxx.xxx www.example.net
# The following lines are desirable for IPv6 capable hosts
#(added automatically by netbase upgrade)
::1 ip6-localhost ip6-loopback
feo0::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Configurez l’hostname de votre serveur :
echo xen > /etc/hostname
echo example.net > /etc/mailname
Et voilà, le système est configuré et prêt à l’emploi.