Blog Code Forum

Xen

From Wiki.cyring.fr

Revision as of 16:31, 22 October 2012 by Cyril (Talk | contribs)
Jump to: navigation, search

Contents

Installation

Initialization

Context:

  1. Create a SSD partition, number 3, formatted with a 6 GB Ext4 file system.
  2. Attach an existing HDD partition named /vm to store the virtual machines.
Partitioning
  1. fdisk /dev/sda
n 3 [enter] +6G
Formatting
  1. mkfs.ext4 -E discard -L DEBIAN /dev/sda3
  2. mount /dev/disk/by-label/DEBIAN /mnt

Requirements

  1. pacman -S abs
  2. pacman -S base-devel
  3. abs
  4. mkdir /tmp/debootstrap
  5. cd /tmp/debootstrap
  6. wget https://aur.archlinux.org/packages/de/debootstrap/PKGBUILD
  7. makepkg -s
  8. pacman -U debootstrap*

Debian

  1. debootstrap --arch=amd64 wheezy /mnt http://ftp.fr.debian.org/debian
  2. LANG=C chroot /mnt /bin/bash
  3. export TERM=xterm-color
  4. cd /dev
  5. MAKEDEV generic
  6. cd /
  7. mkdir /vm

Configuration

Filesystems

  1. nano /etc/fstab
# /etc/fstab
#
# <file system>           <dir>    <type> <options>                           <dump> <pass>

/dev/disk/by-label/DEBIAN /        ext4   discard,noatime,nodiratime,defaults 0      1

proc                      /proc    proc   defaults                            0      0
devpts                    /dev/pts devpts defaults                            0      0
shm                       /dev/shm tmpfs  nodev,nosuid                        0      0
tmpfs                     /tmp     tmpfs  size=2048M                          0      0
tmpfs                     /var/log tmpfs  size=64M                            0      0

/dev/disk/by-label/VM     /vm      ext4   defaults                            0      0

Network

  1. nano /etc/network/interfaces
auto lo eth0 br0
iface lo inet loopback
iface eth0 inet static
    address 192.168.1.101
    network 192.168.1.0
    netmask 255.255.255.0
    gateway 192.168.1.1
iface br0 inet static
    bridge_ports none
    address 192.168.1.199
    broadcast 192.168.1.255
    netmask 255.255.255.0
    gateway 192.168.1.1
  1. nano /etc/resolv.conf
nameserver 192.168.1.1
  1. echo XEN > /etc/hostname
  2. nano /etc/hosts
127.0.0.1	localhost
127.0.0.1	XEN

Kernel

  1. nano /etc/modprobe.d/blacklist.conf
blacklist pcspkr
blacklist acpi_cpufreq
blacklist bluetooth

Packages

  1. nano /etc/apt/sources.list
deb http://ftp.fr.debian.org/debian wheezy main non-free
  1. aptitude update

Localization

  1. aptitude install locales
  2. dpkg-reconfigure locales
  3. aptitude install console-data
  4. dpkg-reconfigure console-data

Defaults

Locale
  1. nano /etc/default/locale
LANG=en_US.UTF-8
Keyboard
  1. nano /etc/default/keyboard
XKBMODEL="pc105"
XKBLAYOUT="fr"
tmp filesystem
  1. nano /etc/default/tmpfs
RAMTMP=yes
HDD temperature
  1. nano /etc/default/tmpfs
RUN_DAEMON="true"
DISKS="/dev/sdb"
rcS
  1. nano /etc/default/rcS
TMPTIME=-1

XEN

Deployment

  1. aptitude install xen-linux-system-amd64
  2. aptitude install xen-hypervisor-4.1-amd64
  3. aptitude install xen-tools

Boot Manager

Files
  1. exit
  2. ln -s /usr/lib/syslinux/mboot.c32 /boot/syslinux/mboot.c32
  3. mkdir /boot/Debian
  4. cp /mnt/boot/xen-4.1-amd64.gz /boot/Debian/
  5. cp /mnt/boot/vmlinuz-3.2.0-3-amd64 /boot/Debian/
  6. cp /mnt/boot/initrd.img-3.2.0-3-amd64 /boot/Debian/
  7. ln -s /boot/Debian/xen-4.1-amd64.gz /boot/Debian/xen.gz
  8. ln -s /boot/Debian/vmlinuz-3.2.0-3-amd64 /boot/Debian/vmlinuz
  9. ln -s /boot/Debian/vmlinuz-3.2.0-3-amd64 /boot/Debian/initrd.img
SysLinux
  1. nano /boot/syslinux/syslinux.cfg
LABEL debian
	MENU LABEL De^bian Linux
	LINUX ../Debian/vmlinuz
	APPEND root=/dev/sda3 ro quiet elevator=noop nmi_watchdog=0 vga=0
	INITRD ../Debian/initrd.img

LABEL xen
	MENU LABEL Debian ^Xen
	KERNEL mboot.c32
	APPEND ../Debian/xen.gz --- ../Debian/vmlinuz root=/dev/sda3 ro quiet elevator=noop --- ../Debian/initrd.img
  1. shutdown -r now

Testing

  1. /usr/sbin/xentop
xentop - 14:55:16   Xen 4.1.3
1 domains: 1 running, 0 blocked, 0 paused, 0 crashed, 0 dying, 0 shutdown
Mem: 6282360k total, 5093488k used, 1188872k free    CPUs: 8 @ 3210MHz
      NAME  STATE   CPU(sec) CPU(%)     MEM(k) MEM(%)  MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS   VBD_OO   VBD_RD   VBD_WR  VBD_RSECT  VBD_WSECT SSID
  Domain-0 -----r        491    1.7    5020324   79.9   no limit       n/a     8    0        0        0    0        0        0        0          0          0 0














  Delay  Networks  vBds  Tmem  VCPUs  Repeat header  Sort order  Quit  

Virtual Machine Manager

X11
  1. wget http://us.download.nvidia.com/XFree86/Linux-x86_64/304.60/NVIDIA-Linux-x86_64-304.60.run
  2. chmod +x NVIDIA-Linux-x86_64-304.60.run
  3. ./NVIDIA-Linux-x86_64-304.60.run
  4. nvidia-xconfig
Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Dell"
    ModelName      "U2711"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection
  1. aptitude install xfce4
  2. aptitude install lightdm lightdm-gtk-greeter
  3. echo "/usr/sbin/lightdm" > /etc/X11/default-display-manager
  4. nano /etc/X11/Xsession
ERRFILE=$HOME/tmp/.xsession-errors
First VM
  1. ifup br0
  2. brctl show
  3. cd /vm
  4. mkdir XEN
  5. chgrp users XEN
  6. chmod g+w XEN
  7. nano /etc/xen-tools/xen-tools.conf
dir = /vm/XEN
  1. xen-create-image --hostname VPC1 --ip 192.168.1.201 --vcpus 2 --dist wheezy
...
General Information
--------------------
Hostname       :  VPC1
Distribution   :  wheezy
Mirror         :  http://ftp.fr.debian.org/debian
Partitions     :  swap            128Mb (swap)
                  /               4Gb   (ext3)
Image type     :  sparse
Memory size    :  128Mb
Kernel path    :  /boot/vmlinuz-3.2.0-3-amd64
Initrd path    :  /boot/initrd.img-3.2.0-3-amd64

Networking Information
----------------------
IP Address 1   : 192.168.1.201 [MAC: 00:06:0E:05:0B:09]
...
Creating partition image: /vm/XEN/domains/VPC1/swap.img
Done

Creating swap on /vm/XEN/domains/VPC1/swap.img
Done

Creating partition image: /vm/XEN/domains/VPC1/disk.img
Done

Creating ext3 filesystem on /vm/XEN/domains/VPC1/disk.img
Done
Installation method: debootstrap
Done

Running hooks
Done

No role scripts were specified.  Skipping

Creating Xen configuration file
Done

No role scripts were specified.  Skipping
Setting up root password
Generating a password for the new guest.
All done


Logfile produced at:
	 /var/log/xen-tools/VPC1.log

Installation Summary
---------------------
Hostname        :  VPC1
Distribution    :  wheezy
IP-Address(es)  :  192.168.1.201 
RSA Fingerprint :  07:04:0e:08:0c:01:08:0b:0c:03:09:07:00:08:01:02
Root Password   :  xXxXxXxX
  1. xn create /etc/xen/VPC1.cfg
GUI
  1. aptitude install virt-manager
  2. usermod -a -G libvirt LOGIN
Personal tools