Projet

Général

Profil

Libvirt (ancien) » Historique » Version 9

Version 8 (Mehdi Abaakouk, 07/04/2013 09:21) → Version 9/61 (Mehdi Abaakouk, 07/04/2013 09:34)

h1. Libvirt

h2. Installation VM sans bridge avec routage static (en /32 pour l'ipv4)

h3. Configuration de la libvirt

On créé un réseau libvirt qui fait rien (déjà fait sur n7):

<pre>
cat > dump-net.xml <<EOF
<network ipv6='yes'>
<name>dump-net</name>
<bridge name='dumpbr0' />
</network>
EOF

virsh net-define dump-net.xml
virsh net-autostart dump-net
virsh net-start dump-net
</pre>

On créé un hook libvirt (déjà fait sur n7):
<pre>
mkdir -p /etc/libvirt/ttnn/hooks
ln -s /etc/libvirt/ttnn/hooks
/etc/libvirt/hooks /etc/libvirt/ttnn
vi /etc/libvirt/hooks/qemu
----8<--------------->8----
#!/bin/bash

name="$1"
operation="$2"
suboperation="$3"

[ "$operation" != "start" ] && exit 0
[ "$suboperation" != "begin" ] && exit 0

# get interface from the libvirt xml
interface=$(cat - | sed -ne "/vnet/s/.*dev='\([^']*\)'.*/\1/gp")

[ -f /etc/libvirt/ttnn/${name}.conf ] && source /etc/libvirt/ttnn/${name}.conf

[ "$ip" -o "$ip6" ] && brctl delif dumpbr0 $interface
[ "$ip" ] && ip route add $ip/32 dev $interface
[ "$ip6" ] && ip route add $ip6/56 dev $interface
[ "$ip6" ] && ip -6 addr add fe80::31/64 dev $interface
exit 0
----8<--------------->8----
</pre>

h3. Preparation de l'installer

Pour une squeeze on met à jour virtinst (déjà fait sur n7):

<pre>
wget http://ftp.us.debian.org/debian/pool/main/v/virtinst/virtinst_0.600.3-3_all.deb http:// u/debian/pool/main/v/virtinst/virtinst_0.600.1-3_all.deb
dpkg -i virtinst_0.600.3-3_all.deb virtinst_0.600.1-3_all.deb
</pre>

On install le preseed.cfg attaché à la page dans /etc/libvirt/preseed.cfg (déjà fait sur n7)

h4. Installation d'une VM

Creation du disk (déjà fait sur n7):
<pre>
lvcreate -n picttn -L 50G /dev/raid5
</pre>

Configuration du routage static:

<pre>
vi /etc/libvirt/ttnn/picttn.conf
ip="91.224.148.252"
ip6="2a01:6600:8080:FC00::"
</pre>

Lancement de l'installation via le réseau natter de libvirt
<pre>
virt-install -n picttn -r 2048 --os-type=linux \
--autostart \
--disk /dev/raid5/picttn,bus=virtio,cache=none,io=native \
--network network=default,model=virtio \
--nographics \
--wait -1 \
--location http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/ \
--serial pty \
--initrd-inject /etc/libvirt/ttnn/preseed.cfg \
--initrd-inject /etc/libvirt/ttnn/picttn.conf \
--initrd-inject /etc/libvirt/ttnn/postinstall.sh \
--extra-args "console=ttyS0,9600n8 DEBIAN_FRONTEND=text auto priority=critical hostname=picttn domain=le-pic.org"
</pre>

Une fois l'installation terminée, on change la conf réseau:

<pre>
virsh detach-interface picttn --type network --persistent
virsh attach-interface picttn --type network --source default --persistent
</pre>

On peux démarrer la VM
<pre>
virsh start picttn
virsh console picttn
</pre>

Ensuite on peux se connecte à la VM
<pre>
ssh root@2a01:6600:8080:FC00::1
</pre>

h5. Gestion des confiugrations:

le répertoire /etc/libvirt/ttnn/ est géré sous git