go to virt-top and download a binary package of the virt-top
Creation of vm directory :
localhost ~ # mkdir /var/vm/ localhost ~ # mkdir /var/vm/def-gentoo localhost ~ # dd if=/dev/zero of=/var/vm/def-gentoo/def-gentoo.img bs=1M count=3500 localhost ~ # dd if=/dev/zero of=/var/vm/def-gentoo/def-gentoo.swap bs=1M count=1000 localhost ~ # mkfs.ext4 -N 600000 /var/vm/def-gentoo/def-gentoo.img localhost ~ # mkswap /var/vm/def-gentoo/def-gentoo.swap
This will create a disk image of 3.5G and a swap of 1G.
/var/vm/def-gentoo/def-gentoo.xml
<domain type='kvm'>
<name>def-gentoo</name>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch='x86_64'>hvm</type>
<boot dev='hd'/>
<kernel>/usr/src/bzImage</kernel>
<!--<initrd>/usr/src/initrd</initrd>-->
<cmdline>root=/dev/vda console=ttyS0</cmdline>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu>
<topology sockets='1' cores='2' threads='1' />
</cpu>
<clock offset='localtime' />
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<!-- DRIVES -->
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none' />
<source file='/var/vm/def-gentoo/def-gentoo.img'/>
<!--<shareable/>-->
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' />
<source file='/var/vm/def-gentoo/def-gentoo.swap'/>
<target dev='vdb' bus='virtio'/>
</disk>
<!-- NETWORK -->
<interface type='bridge'>
<mac address='52:54:00:2a:00:02' />
<source bridge='red'/>
<model type='virtio' />
</interface>
<interface type='bridge'>
<mac address='52:54:00:2a:02:02' />
<source bridge='green'/>
<model type='virtio' />
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target port='0'/>
</console>
<graphics type='vnc' port='-1' keymap='fr' listen='127.0.0.1' />
</devices>
</domain>
localhost ~ # mkdir /mnt/gentoo localhost ~ # mount -o loop /var/vm/def-gentoo/def-gentoo.img /mnt/gentoo localhost ~ # cd /mnt/gentoo localhost gentoo # wget ftp://ftp.free.fr/mirrors/ftp.gentoo.org/releases/amd64/current-stage3/stage3-amd64-*.tar.bz2 localhost gentoo # tar xjpf stage3-amd64-*.tar.bz2 localhost gentoo # rm stage3-amd64-*.tar.bz2 localhost gentoo # cd usr/ localhost usr # wget ftp://ftp.free.fr/mirrors/ftp.gentoo.org/snapshots/portage-latest.tar.bz2 localhost usr # tar xjf portage-latest.tar.bz2 localhost usr # rm portage-latest.tar.bz2
... #/dev/BOOT /boot ext2 noauto,noatime 1 2 /dev/vda / ext4 noatime 0 1 /dev/vdb none swap sw 0 0 /dev/cdrom /mnt/cdrom auto noauto,ro 0 0 #/dev/fd0 /mnt/floppy auto noauto 0 0 ...
localhost src # chroot /mnt/gentoo /bin/bash localhost / # env-update && source /etc/profile localhost / # passwd New password: Retype new password: passwd: password updated successfully
Now we are going to add serial output console (uncomment serial console)
... # SERIAL CONSOLES s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100 ...
localhost linux # exit localhost src # cd localhost ~ # umount /mnt/gentoo
add vm to libvirt
localhost src # ln -s /var/vm/def-gentoo.xml /etc/libvirt/qemu/def-gentoo.xml localhost src # ln -s /etc/libvirt/qemu/def-gentoo.xml /etc/libvirt/qemu/autostart/def-gentoo.xml localhost src # /etc/init.d/libvirtd reload localhost src # virsh list --all Id Name State ---------------------------------- - def-gentoo shut off localhost src # virsh create def-gentoo localhost src # virsh console def-gentoo ... This is localhost.unknown_domain (Linux x86_64 2.6.31-xen-r7) 17:24:49 localhost login: root Password:
config_eth0=("192.168.0.254/24")
routes_eth0=("default via 192.168.0.1")nameserver 212.27.40.240 nameserver 212.27.40.241
localhost ~ # /etc/init.d/net.eth0 start
configure make.conf
CFLAGS="-march=core2 -O2 -pipe"
CXXFLAGS="${CFLAGS}"
# WARNING: Changing your CHOST is not something that should be done lightly.
# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.
CHOST="x86_64-pc-linux-gnu"
MAKEOPTS="-j3"
# These are the USE flags that were used in addition to what is provided by the
# profile used for building.
USE="mmx sse sse2 -X unicode ipv6 -fortran"localhost ~ # emerge -vae world
localhost ~ # rm -Rf /usr/portage/distfiles/ localhost ~ # rc-update add sshd default localhost ~ # emerge syslog-ng vixie-cron logrotate localhost ~ # rc-update add syslog-ng default localhost ~ # rc-update add vixie-cron default
localhost ~ # cp /usr/share/zoneinfo/Europe/Paris /etc/localtime
... TIMEZONE="Europe/Paris" ...
localhost ~ # emerge ntp ... localhost ~ # rc-update add ntp-client default localhost ~ # /etc/init.d/ntp-client start
... 127.0.0.1 VMNAME.home.loc VMNAME localhost ...
HOSTNAME="VMNAME"
localhost ~ # hostname VMNAME
<domain type='kvm' id='2'>
<name>2003-def</name>
<memory>262144</memory>
<currentMemory>162144</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch='x86_64'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu>
<topology sockets='1' cores='2' threads='1' />
</cpu>
<clock offset='localtime' />
<on_poweroff>destroy</on_poweroff>
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none' />
<source file='/var/vm/2003-def/2003-def.img'/>
<target dev='hda' bus='virtio'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' />
<source file='/var/vm/2003-def/d.img'/>
<target dev='hdb' bus='virtio'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' />
<source file='/root/FR_WS03VL.iso' />
<target dev='hdc' bus='ide' />
<readonly/>
</disk>
<interface type='bridge'>
<!--<mac address='.......' />-->
<source bridge='red'/>
<target dev='tap0'/>
<model type='virtio' />
</interface>
<serial type='pty'>
<source path='/dev/pts/1'/>
<target port='0'/>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/1'>
<source path='/dev/pts/1'/>
<target port='0'/>
<alias name='serial0'/>
</console>
<sound model='ac97'>
</sound>
<input type='tablet' bus='usb'/>
<graphics type='vnc' port='-1' keymap='fr' listen='127.0.0.1'/>
</devices>
</domain>
localhost src # virsh vncdisplay def-gentoo 127.0.0.1:1
Now we are going to connect to vnc display using ssh to redirect ports :
In putty configuration settings :
Connection → SSH → tunnels
Then use vncviewer.exe to connect to 127.0.0.1:59001
# ssh -L59001:192.168.0.3:5901
and in an other term
# vinagre 127.0.0.1:59001