Xen
From Wiki.cyring.fr
(Difference between revisions)
(→SysLinux) |
(→SysOp user) |
||
(12 intermediate revisions not shown) | |||
Line 159: | Line 159: | ||
TMPTIME=-1 | TMPTIME=-1 | ||
</pre> | </pre> | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
=== Boot Manager === | === Boot Manager === | ||
- | ==== | + | ==== SysLinux ==== |
<syntaxhighlight lang="bash" line start="1"> | <syntaxhighlight lang="bash" line start="1"> | ||
exit | exit | ||
- | |||
mkdir /boot/Debian | mkdir /boot/Debian | ||
- | |||
cp /mnt/boot/vmlinuz-3.2.0-3-amd64 /boot/Debian/ | cp /mnt/boot/vmlinuz-3.2.0-3-amd64 /boot/Debian/ | ||
cp /mnt/boot/initrd.img-3.2.0-3-amd64 /boot/Debian/ | cp /mnt/boot/initrd.img-3.2.0-3-amd64 /boot/Debian/ | ||
- | |||
ln -s /boot/Debian/vmlinuz-3.2.0-3-amd64 /boot/Debian/vmlinuz | ln -s /boot/Debian/vmlinuz-3.2.0-3-amd64 /boot/Debian/vmlinuz | ||
- | ln -s /boot/Debian/ | + | ln -s /boot/Debian/initrd.img-3.2.0-3-amd64 /boot/Debian/initrd.img |
- | + | ||
- | + | ||
- | + | ||
nano /boot/syslinux/syslinux.cfg | nano /boot/syslinux/syslinux.cfg | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 191: | Line 176: | ||
APPEND root=/dev/sda3 ro quiet elevator=noop nmi_watchdog=0 vga=0 | APPEND root=/dev/sda3 ro quiet elevator=noop nmi_watchdog=0 vga=0 | ||
INITRD ../Debian/initrd.img | INITRD ../Debian/initrd.img | ||
- | |||
- | |||
- | |||
- | |||
- | |||
</pre></small> | </pre></small> | ||
- | <syntaxhighlight lang="bash" line start=" | + | ==== Reboot to Debian ==== |
+ | <syntaxhighlight lang="bash" line start="1"> | ||
shutdown -r now | shutdown -r now | ||
</syntaxhighlight> | </syntaxhighlight> | ||
- | + | === Xorg === | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
<syntaxhighlight lang="bash" line start="1"> | <syntaxhighlight lang="bash" line start="1"> | ||
+ | aptitude install xfce4 | ||
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/304.60/NVIDIA-Linux-x86_64-304.60.run | wget http://us.download.nvidia.com/XFree86/Linux-x86_64/304.60/NVIDIA-Linux-x86_64-304.60.run | ||
chmod +x NVIDIA-Linux-x86_64-304.60.run | chmod +x NVIDIA-Linux-x86_64-304.60.run | ||
Line 240: | Line 203: | ||
EndSection | EndSection | ||
</pre> | </pre> | ||
- | <syntaxhighlight lang="bash" line start=" | + | <syntaxhighlight lang="bash" line start="6"> |
- | + | ||
aptitude install chromium | aptitude install chromium | ||
aptitude install lightdm lightdm-gtk-greeter | aptitude install lightdm lightdm-gtk-greeter | ||
echo "/usr/sbin/lightdm" > /etc/X11/default-display-manager | echo "/usr/sbin/lightdm" > /etc/X11/default-display-manager | ||
+ | </syntaxhighlight> | ||
+ | === SysOp user === | ||
+ | <syntaxhighlight lang="bash" line start="1"> | ||
+ | adduser --gid 100 sysop | ||
+ | mkdir /home/sysop/tmp | ||
+ | ln -fs /home/sysop/tmp /home/sysop/.cache | ||
nano /etc/X11/Xsession | nano /etc/X11/Xsession | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 250: | Line 218: | ||
ERRFILE=$HOME/tmp/.xsession-errors | ERRFILE=$HOME/tmp/.xsession-errors | ||
</pre> | </pre> | ||
+ | <syntaxhighlight lang="bash" line start="5"> | ||
+ | nano /etc/fstab | ||
+ | </syntaxhighlight> | ||
+ | <pre> | ||
+ | # /etc/fstab | ||
+ | # | ||
+ | # <file system> <dir> <type> <options> <dump> <pass> | ||
+ | tmpfs /home/sysop/tmp tmpfs size=2048M 0 0 | ||
+ | </pre> | ||
+ | |||
+ | == XEN == | ||
+ | === Deployment === | ||
+ | <syntaxhighlight lang="bash" line start="1"> | ||
+ | aptitude install xen-linux-system-amd64 | ||
+ | aptitude install xen-hypervisor-4.1-amd64 | ||
+ | aptitude install xen-tools | ||
+ | </syntaxhighlight> | ||
+ | === Append Boot Manager === | ||
+ | ==== Copy fresh files ==== | ||
+ | <syntaxhighlight lang="bash" line start="1"> | ||
+ | ln -s /usr/lib/syslinux/mboot.c32 /boot/syslinux/mboot.c32 | ||
+ | cp /mnt/boot/xen-4.1-amd64.gz /boot/Debian/ | ||
+ | cp /mnt/boot/vmlinuz-3.2.0-3-amd64 /boot/Debian/ | ||
+ | cp /mnt/boot/initrd.img-3.2.0-3-amd64 /boot/Debian/ | ||
+ | ln -s /boot/Debian/xen-4.1-amd64.gz /boot/Debian/xen.gz | ||
+ | ln -s /boot/Debian/vmlinuz-3.2.0-3-amd64 /boot/Debian/vmlinuz | ||
+ | ln -s /boot/Debian/initrd.img-3.2.0-3-amd64 /boot/Debian/initrd.img | ||
+ | </syntaxhighlight> | ||
+ | ==== SysLinux ==== | ||
+ | <syntaxhighlight lang="bash" line start="1"> | ||
+ | nano /boot/syslinux/syslinux.cfg | ||
+ | </syntaxhighlight> | ||
+ | <small><pre> | ||
+ | LABEL xen | ||
+ | MENU LABEL Debian ^Xen | ||
+ | KERNEL mboot.c32 | ||
+ | APPEND ../Debian/xen.gz dom0_mem=512M,max:512M dom0_max_vcpus=1-2 dom0_vcpus_pin=1 --- ../Debian/vmlinuz root=/dev/sda3 ro quiet elevator=noop --- ../Debian/initrd.img | ||
+ | </pre></small> | ||
+ | === Reboot to XEN === | ||
+ | <syntaxhighlight lang="bash" line start="1"> | ||
+ | shutdown -r now | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Testing === | ||
+ | <syntaxhighlight lang="bash" line start="1"> | ||
+ | xentop | ||
+ | </syntaxhighlight> | ||
+ | <small><pre> | ||
+ | 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 | ||
+ | </pre> | ||
+ | </small> | ||
+ | |||
+ | === Virtual Machine Manager === | ||
==== First VM ==== | ==== First VM ==== | ||
* Prepare the VM directory | * Prepare the VM directory | ||
Line 383: | Line 412: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
- | ==== GUI ==== | + | ==== Virt-Manager GUI ==== |
<syntaxhighlight lang="bash" line start="1"> | <syntaxhighlight lang="bash" line start="1"> | ||
aptitude install virt-manager | aptitude install virt-manager | ||
- | # usermod -a -G libvirt | + | # usermod -a -G libvirt sysop |
+ | mkdir -p /vm/XEN/libvirt/images | ||
+ | virsh pool-edit default | ||
+ | </syntaxhighlight> | ||
+ | <pre> | ||
+ | <path>/vm/XEN/libvirt/images</path> | ||
+ | </pre> | ||
+ | :''Pool default XML configuration edited.'' | ||
+ | <syntaxhighlight lang="bash" line start="5"> | ||
+ | mkdir -p /vm/XEN/libvirt/qemu/dump | ||
+ | nano /etc/libvirt/qemu.conf | ||
+ | </syntaxhighlight> | ||
+ | <pre> | ||
+ | auto_dump_path = "/vm/XEN/libvirt/qemu/dump" | ||
+ | </pre> | ||
+ | <syntaxhighlight lang="bash" line start="7"> | ||
nano /etc/xen/xend-config.sxp | nano /etc/xen/xend-config.sxp | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 392: | Line 436: | ||
(xend-unix-server yes) | (xend-unix-server yes) | ||
</pre> | </pre> | ||
- | <syntaxhighlight lang="bash" line start=" | + | * virt-manager & Debian Wheezy packages are broken : some paths to libraries are invalid |
+ | <syntaxhighlight lang="bash" line start="8"> | ||
+ | # mkdir -p /usr/lib64/xen/bin | ||
+ | # ln -s /usr/lib/xen-4.1/bin/qemu-dm /usr/lib64/xen/bin/qemu-dm | ||
+ | # ln -s /usr/lib/xen-4.1 /usr/lib/xen-default | ||
service xen restart | service xen restart | ||
- | + | virt-manager | |
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 19:38, 23 October 2012
Contents |
Installation
Initialization
Context:
- Create a SSD partition, number 3, formatted with a 6 GB Ext4 file system.
- Attach an existing HDD partition named /vm to store the virtual machines.
Partitioning
fdisk /dev/sda
n 3 [enter] +6G
Formatting
mkfs.ext4 -E discard -L DEBIAN /dev/sda3
mount /dev/disk/by-label/DEBIAN /mnt
ArchLinux as a source
pacman -S abs
pacman -S base-devel
abs
mkdir /tmp/debootstrap
cd /tmp/debootstrap
wget https://aur.archlinux.org/packages/de/debootstrap/PKGBUILD
makepkg -s
pacman -U debootstrap*
Debian as a host
debootstrap --arch=amd64 wheezy /mnt http://ftp.fr.debian.org/debian
LANG=C chroot /mnt /bin/bash
export TERM=xterm-color
cd /dev
MAKEDEV generic
cd /
mkdir /vm
Configuration
Filesystems
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
nano /etc/network/interfaces
auto lo eth0 xenbr0 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 xenbr0 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
nano /etc/resolv.conf
nameserver 192.168.1.1
echo XEN > /etc/hostname
nano /etc/hosts
127.0.0.1 localhost 127.0.0.1 XEN
Kernel
nano /etc/modprobe.d/blacklist.conf
blacklist pcspkr blacklist acpi_cpufreq blacklist bluetooth
Packages
nano /etc/apt/sources.list
deb http://ftp.fr.debian.org/debian wheezy main non-free
aptitude update
Localization
aptitude install locales
dpkg-reconfigure locales
aptitude install console-data
dpkg-reconfigure console-data
Defaults
Locale
nano /etc/default/locale
LANG=en_US.UTF-8
Keyboard
nano /etc/default/keyboard
XKBMODEL="pc105" XKBLAYOUT="fr"
tmp filesystem
nano /etc/default/tmpfs
RAMTMP=yes
HDD temperature
nano /etc/default/tmpfs
RUN_DAEMON="true" DISKS="/dev/sdb"
rcS
nano /etc/default/rcS
TMPTIME=-1
Boot Manager
SysLinux
exit
mkdir /boot/Debian
cp /mnt/boot/vmlinuz-3.2.0-3-amd64 /boot/Debian/
cp /mnt/boot/initrd.img-3.2.0-3-amd64 /boot/Debian/
ln -s /boot/Debian/vmlinuz-3.2.0-3-amd64 /boot/Debian/vmlinuz
ln -s /boot/Debian/initrd.img-3.2.0-3-amd64 /boot/Debian/initrd.img
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
Reboot to Debian
shutdown -r now
Xorg
aptitude install xfce4
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/304.60/NVIDIA-Linux-x86_64-304.60.run
chmod +x NVIDIA-Linux-x86_64-304.60.run
./NVIDIA-Linux-x86_64-304.60.run
nvidia-xconfig
Section "Monitor" Identifier "Monitor0" VendorName "Dell" ModelName "U2711" Option "DPMS" EndSection Section "Device" Identifier "Device0" Driver "nvidia" VendorName "NVIDIA Corporation" EndSection
aptitude install chromium
aptitude install lightdm lightdm-gtk-greeter
echo "/usr/sbin/lightdm" > /etc/X11/default-display-manager
SysOp user
adduser --gid 100 sysop
mkdir /home/sysop/tmp
ln -fs /home/sysop/tmp /home/sysop/.cache
nano /etc/X11/Xsession
ERRFILE=$HOME/tmp/.xsession-errors
nano /etc/fstab
# /etc/fstab # # <file system> <dir> <type> <options> <dump> <pass> tmpfs /home/sysop/tmp tmpfs size=2048M 0 0
XEN
Deployment
aptitude install xen-linux-system-amd64
aptitude install xen-hypervisor-4.1-amd64
aptitude install xen-tools
Append Boot Manager
Copy fresh files
ln -s /usr/lib/syslinux/mboot.c32 /boot/syslinux/mboot.c32
cp /mnt/boot/xen-4.1-amd64.gz /boot/Debian/
cp /mnt/boot/vmlinuz-3.2.0-3-amd64 /boot/Debian/
cp /mnt/boot/initrd.img-3.2.0-3-amd64 /boot/Debian/
ln -s /boot/Debian/xen-4.1-amd64.gz /boot/Debian/xen.gz
ln -s /boot/Debian/vmlinuz-3.2.0-3-amd64 /boot/Debian/vmlinuz
ln -s /boot/Debian/initrd.img-3.2.0-3-amd64 /boot/Debian/initrd.img
SysLinux
nano /boot/syslinux/syslinux.cfg
LABEL xen MENU LABEL Debian ^Xen KERNEL mboot.c32 APPEND ../Debian/xen.gz dom0_mem=512M,max:512M dom0_max_vcpus=1-2 dom0_vcpus_pin=1 --- ../Debian/vmlinuz root=/dev/sda3 ro quiet elevator=noop --- ../Debian/initrd.img
Reboot to XEN
shutdown -r now
Testing
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
First VM
- Prepare the VM directory
ifup xenbr0
brctl show
cd /vm
mkdir XEN
chgrp users XEN
chmod g+w XEN
cd
nano /etc/xen-tools/xen-tools.conf
dir = /vm/XEN
Create a Debian VM
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 ... 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
- Define Video & Audio features
nano /etc/xen/VPC1.cfg
# # Graphics and Audio # stdvga = '1' videoram = '16'
Start the new VM
xm create /etc/xen/VPC1.cfg
Using config file "/etc/xen/VPC1.cfg". Started domain VPC1 (id=3)
List any running VM
xm list
Name ID Mem VCPUs State Time(s) Domain-0 0 4902 8 r----- 101.5 VPC1 3 128 2 -b---- 2.4
Take control of the VM
- Using the console (press CTRL+] to exit)
xm console 3
- Using ssh to remotely connect
ssh root@VPC1
Windowing
- Inside the VM, configure an Internet box
aptitude install xorg
dpkg-reconfigure x11-common
aptitude install dbus
aptitude install twm
echo RandomPlacement >> /etc/X11/twm/system.twmrc
echo 'NoTitle { chromium }' >> /etc/X11/twm/system.twmrc
aptitude install chromium
adduser --gid 100 cyring
exit
- Reconnect as a regular user
ssh cyring:VPC1
echo "chromium &" > .xinitrc
echo "exec twm" >> .xinitrc
startx
Stop the VM
- Nicely shut down the VM
xm shutdown 3
- Remove the VM from the managed environment.
xm delete VPC1
Lost password !
- Mount the VM filesystem
mount /vm/XEN/domains/VPC1/disk.img /mnt
chroot /mnt
- Inside the VM
passwd
exit
- Back to back
umount /vm/XEN/domains/VPC1/disk.img
Virt-Manager GUI
aptitude install virt-manager
# usermod -a -G libvirt sysop
mkdir -p /vm/XEN/libvirt/images
virsh pool-edit default
<path>/vm/XEN/libvirt/images</path>
- Pool default XML configuration edited.
mkdir -p /vm/XEN/libvirt/qemu/dump
nano /etc/libvirt/qemu.conf
auto_dump_path = "/vm/XEN/libvirt/qemu/dump"
nano /etc/xen/xend-config.sxp
(xend-unix-server yes)
- virt-manager & Debian Wheezy packages are broken : some paths to libraries are invalid
# mkdir -p /usr/lib64/xen/bin
# ln -s /usr/lib/xen-4.1/bin/qemu-dm /usr/lib64/xen/bin/qemu-dm
# ln -s /usr/lib/xen-4.1 /usr/lib/xen-default
service xen restart
virt-manager