Libvirt (ancien) » Historique » Version 21
Laurent GUERBY, 14/07/2013 23:04
1 | 1 | Mehdi Abaakouk | h1. Libvirt |
---|---|---|---|
2 | 1 | Mehdi Abaakouk | |
3 | 12 | Mehdi Abaakouk | h2. Resources/Liens |
4 | 12 | Mehdi Abaakouk | |
5 | 18 | Laurent GUERBY | * Virtualisation du routage IPv4 pour les VM http://lists.tetaneutral.net/pipermail/technique/2013-April/000810.html |
6 | 18 | Laurent GUERBY | |
7 | 12 | Mehdi Abaakouk | * libvirt |
8 | 12 | Mehdi Abaakouk | |
9 | 12 | Mehdi Abaakouk | http://builder.virt-tools.org/artifacts/libvirt-virshcmdref/html/index.html |
10 | 12 | Mehdi Abaakouk | http://docs.fedoraproject.org/en-US/Fedora/13/html/Virtualization_Guide/chap-Virtualization-Managing_guests_with_virsh.html |
11 | 12 | Mehdi Abaakouk | |
12 | 12 | Mehdi Abaakouk | * virt-install et preseed sans server web et pxe: |
13 | 12 | Mehdi Abaakouk | |
14 | 12 | Mehdi Abaakouk | http://honk.sigxcpu.org/con/Preseeding_Debian_virtual_machines_with_virt_install.html |
15 | 12 | Mehdi Abaakouk | |
16 | 2 | Mehdi Abaakouk | h2. Installation VM sans bridge avec routage static (en /32 pour l'ipv4) |
17 | 1 | Mehdi Abaakouk | |
18 | 11 | Mehdi Abaakouk | Note: tous les fichiers utilisés et créés ne sont peut être pas à jour, voir ici pour les dernières version: http://git.tetaneutral.net/libvirt.git/ |
19 | 1 | Mehdi Abaakouk | |
20 | 11 | Mehdi Abaakouk | Le répertoire /etc/libvirt/ttnn cité plustard est géré dans ce git. |
21 | 11 | Mehdi Abaakouk | |
22 | 1 | Mehdi Abaakouk | h3. Configuration de la libvirt |
23 | 1 | Mehdi Abaakouk | |
24 | 1 | Mehdi Abaakouk | On créé un réseau libvirt qui fait rien (déjà fait sur n7): |
25 | 1 | Mehdi Abaakouk | |
26 | 1 | Mehdi Abaakouk | <pre> |
27 | 10 | Mehdi Abaakouk | cat > libvirt_dump_network.xml <<EOF |
28 | 1 | Mehdi Abaakouk | <network ipv6='yes'> |
29 | 1 | Mehdi Abaakouk | <name>dump-net</name> |
30 | 6 | Mehdi Abaakouk | <bridge name='dumpbr0' /> |
31 | 1 | Mehdi Abaakouk | </network> |
32 | 1 | Mehdi Abaakouk | EOF |
33 | 1 | Mehdi Abaakouk | |
34 | 10 | Mehdi Abaakouk | virsh net-define libvirt_dump_network.xml |
35 | 1 | Mehdi Abaakouk | virsh net-autostart dump-net |
36 | 1 | Mehdi Abaakouk | virsh net-start dump-net |
37 | 1 | Mehdi Abaakouk | </pre> |
38 | 1 | Mehdi Abaakouk | |
39 | 4 | Mehdi Abaakouk | On créé un hook libvirt (déjà fait sur n7): |
40 | 1 | Mehdi Abaakouk | <pre> |
41 | 9 | Mehdi Abaakouk | mkdir -p /etc/libvirt/ttnn/hooks |
42 | 9 | Mehdi Abaakouk | ln -s /etc/libvirt/ttnn/hooks /etc/libvirt/hooks |
43 | 1 | Mehdi Abaakouk | vi /etc/libvirt/hooks/qemu |
44 | 1 | Mehdi Abaakouk | ----8<--------------->8---- |
45 | 1 | Mehdi Abaakouk | #!/bin/bash |
46 | 1 | Mehdi Abaakouk | |
47 | 1 | Mehdi Abaakouk | name="$1" |
48 | 1 | Mehdi Abaakouk | operation="$2" |
49 | 1 | Mehdi Abaakouk | suboperation="$3" |
50 | 1 | Mehdi Abaakouk | |
51 | 7 | Mehdi Abaakouk | [ "$operation" != "start" ] && exit 0 |
52 | 1 | Mehdi Abaakouk | [ "$suboperation" != "begin" ] && exit 0 |
53 | 1 | Mehdi Abaakouk | |
54 | 1 | Mehdi Abaakouk | # get interface from the libvirt xml |
55 | 1 | Mehdi Abaakouk | interface=$(cat - | sed -ne "/vnet/s/.*dev='\([^']*\)'.*/\1/gp") |
56 | 1 | Mehdi Abaakouk | |
57 | 5 | Mehdi Abaakouk | [ -f /etc/libvirt/ttnn/${name}.conf ] && source /etc/libvirt/ttnn/${name}.conf |
58 | 5 | Mehdi Abaakouk | |
59 | 5 | Mehdi Abaakouk | [ "$ip" -o "$ip6" ] && brctl delif dumpbr0 $interface |
60 | 1 | Mehdi Abaakouk | [ "$ip" ] && ip route add $ip/32 dev $interface |
61 | 1 | Mehdi Abaakouk | [ "$ip6" ] && ip route add $ip6/56 dev $interface |
62 | 1 | Mehdi Abaakouk | [ "$ip6" ] && ip -6 addr add fe80::31/64 dev $interface |
63 | 1 | Mehdi Abaakouk | exit 0 |
64 | 1 | Mehdi Abaakouk | ----8<--------------->8---- |
65 | 1 | Mehdi Abaakouk | </pre> |
66 | 1 | Mehdi Abaakouk | |
67 | 1 | Mehdi Abaakouk | |
68 | 1 | Mehdi Abaakouk | h3. Preparation de l'installer |
69 | 1 | Mehdi Abaakouk | |
70 | 4 | Mehdi Abaakouk | Pour une squeeze on met à jour virtinst (déjà fait sur n7): |
71 | 1 | Mehdi Abaakouk | |
72 | 1 | Mehdi Abaakouk | <pre> |
73 | 9 | Mehdi Abaakouk | wget http://ftp.us.debian.org/debian/pool/main/v/virtinst/virtinst_0.600.3-3_all.deb |
74 | 9 | Mehdi Abaakouk | dpkg -i virtinst_0.600.3-3_all.deb |
75 | 1 | Mehdi Abaakouk | </pre> |
76 | 1 | Mehdi Abaakouk | |
77 | 4 | Mehdi Abaakouk | On install le preseed.cfg attaché à la page dans /etc/libvirt/preseed.cfg (déjà fait sur n7) |
78 | 1 | Mehdi Abaakouk | |
79 | 1 | Mehdi Abaakouk | h4. Installation d'une VM |
80 | 1 | Mehdi Abaakouk | |
81 | 4 | Mehdi Abaakouk | Creation du disk (déjà fait sur n7): |
82 | 1 | Mehdi Abaakouk | <pre> |
83 | 1 | Mehdi Abaakouk | lvcreate -n picttn -L 50G /dev/raid5 |
84 | 1 | Mehdi Abaakouk | </pre> |
85 | 1 | Mehdi Abaakouk | |
86 | 5 | Mehdi Abaakouk | Configuration du routage static: |
87 | 5 | Mehdi Abaakouk | |
88 | 5 | Mehdi Abaakouk | <pre> |
89 | 5 | Mehdi Abaakouk | vi /etc/libvirt/ttnn/picttn.conf |
90 | 16 | Mehdi Abaakouk | # le /32 ipv4 |
91 | 1 | Mehdi Abaakouk | ip="91.224.148.252" |
92 | 16 | Mehdi Abaakouk | # le /56 ipv6 |
93 | 16 | Mehdi Abaakouk | ip6="2a01:6600:8080:FC00::" |
94 | 5 | Mehdi Abaakouk | </pre> |
95 | 5 | Mehdi Abaakouk | |
96 | 8 | Mehdi Abaakouk | Lancement de l'installation via le réseau natter de libvirt |
97 | 6 | Mehdi Abaakouk | <pre> |
98 | 1 | Mehdi Abaakouk | virt-install -n picttn -r 2048 --os-type=linux \ |
99 | 8 | Mehdi Abaakouk | --autostart \ |
100 | 1 | Mehdi Abaakouk | --disk /dev/raid5/picttn,bus=virtio,cache=none,io=native \ |
101 | 8 | Mehdi Abaakouk | --network network=default,model=virtio \ |
102 | 1 | Mehdi Abaakouk | --nographics \ |
103 | 13 | Mehdi Abaakouk | --noreboot \ |
104 | 8 | Mehdi Abaakouk | --wait -1 \ |
105 | 1 | Mehdi Abaakouk | --location http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/ \ |
106 | 6 | Mehdi Abaakouk | --serial pty \ |
107 | 1 | Mehdi Abaakouk | --initrd-inject /etc/libvirt/ttnn/preseed.cfg \ |
108 | 6 | Mehdi Abaakouk | --initrd-inject /etc/libvirt/ttnn/picttn.conf \ |
109 | 1 | Mehdi Abaakouk | --initrd-inject /etc/libvirt/ttnn/postinstall.sh \ |
110 | 8 | Mehdi Abaakouk | --extra-args "console=ttyS0,9600n8 DEBIAN_FRONTEND=text auto priority=critical hostname=picttn domain=le-pic.org" |
111 | 7 | Mehdi Abaakouk | </pre> |
112 | 1 | Mehdi Abaakouk | |
113 | 8 | Mehdi Abaakouk | Une fois l'installation terminée, on change la conf réseau: |
114 | 8 | Mehdi Abaakouk | |
115 | 1 | Mehdi Abaakouk | <pre> |
116 | 14 | Mehdi Abaakouk | EDITOR="sed -ie s/default/dump-net/g" virsh edit picttn |
117 | 8 | Mehdi Abaakouk | </pre> |
118 | 8 | Mehdi Abaakouk | |
119 | 8 | Mehdi Abaakouk | On peux démarrer la VM |
120 | 8 | Mehdi Abaakouk | <pre> |
121 | 8 | Mehdi Abaakouk | virsh start picttn |
122 | 3 | Mehdi Abaakouk | virsh console picttn |
123 | 1 | Mehdi Abaakouk | </pre> |
124 | 1 | Mehdi Abaakouk | |
125 | 8 | Mehdi Abaakouk | Ensuite on peux se connecte à la VM |
126 | 9 | Mehdi Abaakouk | <pre> |
127 | 9 | Mehdi Abaakouk | ssh root@2a01:6600:8080:FC00::1 |
128 | 9 | Mehdi Abaakouk | </pre> |
129 | 17 | Laurent GUERBY | |
130 | 17 | Laurent GUERBY | Le /etc/network/interfaces IPv4 après installation |
131 | 17 | Laurent GUERBY | |
132 | 17 | Laurent GUERBY | <pre> |
133 | 17 | Laurent GUERBY | iface eth0 inet static |
134 | 17 | Laurent GUERBY | address 91.224.148.xxx |
135 | 17 | Laurent GUERBY | netmask 32 |
136 | 17 | Laurent GUERBY | up ip route add 91.224.148.0/32 dev eth0 |
137 | 17 | Laurent GUERBY | up ip route add default via 91.224.148.0 |
138 | 21 | Laurent GUERBY | |
139 | 21 | Laurent GUERBY | iface eth0 inet6 static |
140 | 21 | Laurent GUERBY | address 2a01:6600:8080:xx00::1 |
141 | 21 | Laurent GUERBY | netmask 56 |
142 | 21 | Laurent GUERBY | gateway fe80::31 |
143 | 21 | Laurent GUERBY | pre-up /sbin/sysctl -w net.ipv6.conf.eth0.accept_ra=0 |
144 | 21 | Laurent GUERBY | pre-up /sbin/sysctl -w net.ipv6.conf.eth0.autoconf=0 |
145 | 21 | Laurent GUERBY | |
146 | 17 | Laurent GUERBY | </pre> |
147 | 19 | Laurent GUERBY | |
148 | 19 | Laurent GUERBY | h2. Misc |
149 | 19 | Laurent GUERBY | |
150 | 19 | Laurent GUERBY | <H4Mm3r> si tu lance la création de la VM sans avoir créé le disk --disk /vmroot/testnat.qcow2,format=qcow2,size=12,bus=virtio,cache=writeback |
151 | 19 | Laurent GUERBY | <H4Mm3r> le disk se créé mais dans le XML le format est à RAW |
152 | 19 | Laurent GUERBY | <H4Mm3r> si tu le créé à l'avance avec qemu-img create -f qcow2 |
153 | 19 | Laurent GUERBY | <H4Mm3r> et que tu lance ta commande --disk /vmroot/testnat.qcow2,format=qcow2 |
154 | 19 | Laurent GUERBY | <guerby> ok donc c'etait bien ça :) |
155 | 19 | Laurent GUERBY | <guerby> bbl (miam) |
156 | 19 | Laurent GUERBY | <H4Mm3r> dans le fichier XML le format est à RAW |
157 | 19 | Laurent GUERBY | <H4Mm3r> il faut en effet dumper un XML, modifier la valeur à QCOW2 |
158 | 19 | Laurent GUERBY | <H4Mm3r> et créer la VM depuis ce XML |
159 | 19 | Laurent GUERBY | <H4Mm3r> virsh create file.xml |
160 | 19 | Laurent GUERBY | <H4Mm3r> pourqu'enfin il comprenne que c'est du QCOW... |
161 | 19 | Laurent GUERBY | <H4Mm3r> et là mon disk fait bien 265ko, mais est détecté comme 12G :D |
162 | 20 | Joris Michaux | |
163 | 20 | Joris Michaux | h2. HOWTO by H4Mm3r (under contruction) |
164 | 20 | Joris Michaux | |
165 | 20 | Joris Michaux | h3. Usefull links |
166 | 20 | Joris Michaux | |
167 | 20 | Joris Michaux | #### Misc |
168 | 20 | Joris Michaux | |
169 | 20 | Joris Michaux | #OS Type |
170 | 20 | Joris Michaux | http://rhevdup.blogspot.fr/2012/05/list-available-os-types-for-kvm-on-rhel.html |
171 | 20 | Joris Michaux | |
172 | 20 | Joris Michaux | #Libvirt TTN |
173 | 20 | Joris Michaux | http://chiliproject.tetaneutral.net/projects/tetaneutral/wiki/Libvirt |
174 | 20 | Joris Michaux | |
175 | 20 | Joris Michaux | #### KVM management |
176 | 20 | Joris Michaux | |
177 | 20 | Joris Michaux | #Install QEMU KVM + LIBVIRT |
178 | 20 | Joris Michaux | http://www.howtoforge.com/virtualization-with-kvm-on-a-debian-squeeze-server |
179 | 20 | Joris Michaux | |
180 | 20 | Joris Michaux | #Edit XML file |
181 | 20 | Joris Michaux | http://vladnevzorov.com/2011/02/11/how-to-change-configuration-of-kvm-virtual-machine/ |
182 | 20 | Joris Michaux | |
183 | 20 | Joris Michaux | #Clone a KVM |
184 | 20 | Joris Michaux | https://help.ubuntu.com/community/KVM/CreateGuests#Cloning_a_virtual_machine |
185 | 20 | Joris Michaux | http://linux.die.net/man/1/virt-clone |
186 | 20 | Joris Michaux | |
187 | 20 | Joris Michaux | #### Network |
188 | 20 | Joris Michaux | |
189 | 20 | Joris Michaux | #NAT |
190 | 20 | Joris Michaux | http://www.linuxquestions.org/questions/linux-networking-3/kvm-qemu-and-nat-on-the-host-machine-mini-tutorial-697980/ |
191 | 20 | Joris Michaux | http://wiki.libvirt.org/page/Networking |
192 | 20 | Joris Michaux | http://libvirt.org/formatnetwork.html#examplesNAT |
193 | 20 | Joris Michaux | https://help.ubuntu.com/community/KVM/Networking |
194 | 20 | Joris Michaux | |
195 | 20 | Joris Michaux | #Bridge |
196 | 20 | Joris Michaux | http://toast.djw.org.uk/qemu.html |
197 | 20 | Joris Michaux | http://www.mediaonfire.com/en/tech_tips/QEMUNetworking.html (bridge, nat, arp) |
198 | 20 | Joris Michaux | |
199 | 20 | Joris Michaux | #### Improve performance |
200 | 20 | Joris Michaux | http://blog.bodhizazen.net/linux/improve-kvm-performance/ |
201 | 20 | Joris Michaux | http://www.linux-kvm.org/page/Tuning_KVM |
202 | 20 | Joris Michaux | http://www.ezunix.org/index.php?title=Boost_performance_of_KVM_guests |
203 | 20 | Joris Michaux | |
204 | 20 | Joris Michaux | #### Storage |
205 | 20 | Joris Michaux | http://doc.opensuse.org/products/draft/SLES/SLES-kvm_sd_draft/cha.libvirt.storage.html |
206 | 20 | Joris Michaux | |
207 | 20 | Joris Michaux | h3. HOWTO |
208 | 20 | Joris Michaux | |
209 | 20 | Joris Michaux | <pre> |
210 | 20 | Joris Michaux | [H] = Host |
211 | 20 | Joris Michaux | [G] = Guest |
212 | 20 | Joris Michaux | [XML] = XML content |
213 | 20 | Joris Michaux | "command" |
214 | 20 | Joris Michaux | </pre> |
215 | 20 | Joris Michaux | |
216 | 20 | Joris Michaux | #### Diskfile Storage |
217 | 20 | Joris Michaux | |
218 | 20 | Joris Michaux | #Create qcow2 disk |
219 | 20 | Joris Michaux | <pre> |
220 | 20 | Joris Michaux | [H] "qemu-img create -f qcow2 /path/to/disk.qcow2 $SIZE" (ex: 20G) |
221 | 20 | Joris Michaux | [H] "chmod +x /path/to/disk.qcow2" |
222 | 20 | Joris Michaux | </pre> |
223 | 20 | Joris Michaux | |
224 | 20 | Joris Michaux | #Convert raw to qcow2 |
225 | 20 | Joris Michaux | <pre> |
226 | 20 | Joris Michaux | [H] "qemu-img convert -O qcow2 disk.img disk.qcow2" |
227 | 20 | Joris Michaux | </pre> |
228 | 20 | Joris Michaux | |
229 | 20 | Joris Michaux | #Disable cache to improve performance |
230 | 20 | Joris Michaux | <pre> |
231 | 20 | Joris Michaux | [XML] <driver name='qemu' type='qcow2' cache='none'/> |
232 | 20 | Joris Michaux | </pre> |
233 | 20 | Joris Michaux | |
234 | 20 | Joris Michaux | #### LVM Storage |
235 | 20 | Joris Michaux | |
236 | 20 | Joris Michaux | <pre> |
237 | 20 | Joris Michaux | [H] Create "/etc/libvirt/storage/vmdata.xml" file : |
238 | 20 | Joris Michaux | <pool type="logical"> |
239 | 20 | Joris Michaux | <name>my_pool</name> |
240 | 20 | Joris Michaux | <source> |
241 | 20 | Joris Michaux | <device path="/path/to/dev"/> |
242 | 20 | Joris Michaux | </source> |
243 | 20 | Joris Michaux | <target> |
244 | 20 | Joris Michaux | <path>/target/path/path> (LV will be created there) |
245 | 20 | Joris Michaux | </target> |
246 | 20 | Joris Michaux | </pool> |
247 | 20 | Joris Michaux | [H] "virsh pool-define /etc/libvirt/storage/my_pool.xml" |
248 | 20 | Joris Michaux | [H] "virsh pool-start my_pool" |
249 | 20 | Joris Michaux | [H] "virsh pool-autostart my_pool" |
250 | 20 | Joris Michaux | [H] "virsh pool-info my_pool" |
251 | 20 | Joris Michaux | [H] "virsh vol-create-as my_pool my_logical_volume 12G" |
252 | 20 | Joris Michaux | [H] You must create a LV to be able to give it to a KVM "virsh vol-create-as my_pool my_vol 12G --format=lvm2" |
253 | 20 | Joris Michaux | </pre> |
254 | 20 | Joris Michaux | |
255 | 20 | Joris Michaux | h3. Create KVM |
256 | 20 | Joris Michaux | |
257 | 20 | Joris Michaux | #Bridged with TAP + LVM |
258 | 20 | Joris Michaux | <pre> |
259 | 20 | Joris Michaux | [H] "virt-install -d --hvm --vnc --name=my_kvm --vcpus=4 --cpuset=0-4 --ram 2048 --disk vol=my_pool/my_vol,bus=virtio,cache=none --network bridge=my_bridge,model=virtio -c /path/to/distrib.iso --keymap=fr --os-type=linux --noautoconsole" |
260 | 20 | Joris Michaux | </pre> |
261 | 20 | Joris Michaux | |
262 | 20 | Joris Michaux | #TAP (if you want to rename the default "vnetX" interface by "tapX" |
263 | 20 | Joris Michaux | <pre> |
264 | 20 | Joris Michaux | [H] "virsh dumpxml my_guest > my_guest.xml |
265 | 20 | Joris Michaux | [H] "virsh undefine my_guest" |
266 | 20 | Joris Michaux | [H] Edit the my_guest.xml file to rename VNETX by TAPX |
267 | 20 | Joris Michaux | [H] "virsh define my_guest.xml" |
268 | 20 | Joris Michaux | [H] "virsh start my_guest" |
269 | 20 | Joris Michaux | </pre> |
270 | 20 | Joris Michaux | |
271 | 20 | Joris Michaux | #NATed + LVM |
272 | 20 | Joris Michaux | <pre> |
273 | 20 | Joris Michaux | [H] "virt-install -d --hvm --vnc --name=my_kvm --vcpus=4 --cpuset=0-4 --ram 2048 --disk vol=my_pool/my_vol,bus=virtio,cache=none --network network=my_network,model=virtio -c /path/to/distrib.iso --keymap=fr --os-type=linux --noautoconsole" |
274 | 20 | Joris Michaux | </pre> |
275 | 20 | Joris Michaux | |
276 | 20 | Joris Michaux | #Clone VM |
277 | 20 | Joris Michaux | <pre> |
278 | 20 | Joris Michaux | [H] Create the LVM dest |
279 | 20 | Joris Michaux | [H] Pause the KVM "virsh suspend my_kvm" |
280 | 20 | Joris Michaux | [H] virt-clone -o my_orig_kvm -n my_cloned_kvm -f=/path/to/lvm/dev |
281 | 20 | Joris Michaux | [G] Go and change the hostname and resolv.conf |
282 | 20 | Joris Michaux | </pre> |
283 | 20 | Joris Michaux | |
284 | 20 | Joris Michaux | h3. Command explanation |
285 | 20 | Joris Michaux | |
286 | 20 | Joris Michaux | #Bridged with tap |
287 | 20 | Joris Michaux | <pre> |
288 | 20 | Joris Michaux | virt-install -d --hvm --vnc --name=testlvm \ |
289 | 20 | Joris Michaux | --vcpus=4 --cpuset=0-4 \ |
290 | 20 | Joris Michaux | --ram 2048 \ |
291 | 20 | Joris Michaux | --disk vol=vmdata/testlvm,bus=virtio,cache=none \ |
292 | 20 | Joris Michaux | --network bridge=br0,model=virtio \ |
293 | 20 | Joris Michaux | -c /data/isos/debian-testing-amd64-netinst.iso \ |
294 | 20 | Joris Michaux | --keymap=fr --os-type=linux --os-variant=debiansqueeze --noautoconsole |
295 | 20 | Joris Michaux | </pre> |
296 | 20 | Joris Michaux | |
297 | 20 | Joris Michaux | #NATed |
298 | 20 | Joris Michaux | <pre> |
299 | 20 | Joris Michaux | virt-install -d --hvm --vnc --name=testlvm \ |
300 | 20 | Joris Michaux | --vcpus=4 --cpuset=0-4 \ |
301 | 20 | Joris Michaux | --ram 2048 \ |
302 | 20 | Joris Michaux | --disk vol=vmdata/testlvm,bus=virtio,cache=none \ |
303 | 20 | Joris Michaux | --network network=frp_network,model=virtio \ |
304 | 20 | Joris Michaux | -c /data/isos/debian-testing-amd64-netinst.iso \ |
305 | 20 | Joris Michaux | --keymap=fr --os-type=linux --os-variant=debiansqueeze --noautoconsole |
306 | 20 | Joris Michaux | </pre> |
307 | 20 | Joris Michaux | |
308 | 20 | Joris Michaux | [OLD QCOW2] |
309 | 20 | Joris Michaux | <pre> |
310 | 20 | Joris Michaux | [H] "virt-install --connect qemu:///system -n puppetnode1 -r 1024 --vcpus=4 --cpuset=4-7 --disk path=/vmroot/puppetnode1.qcow2 -c /data/isos/debian-6.0.6-amd64-netinst.iso --vnc --keymap=fr --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network network=default --hvm" |
311 | 20 | Joris Michaux | [H] "virt-install --connect qemu:///system -n testnat -r 1024 --vcpus=2 --cpuset=2-3 --disk /vmroot/testnat.qcow2,format=qcow2,size=12,bus=virtio,cache=writeback -c /data/isos/debian-6.0.6-amd64-netinst.iso --vnc --keymap=fr --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network bridge=br0 --hvm" |
312 | 20 | Joris Michaux | </pre> |
313 | 20 | Joris Michaux | |
314 | 20 | Joris Michaux | #Start a KVM |
315 | 20 | Joris Michaux | <pre> |
316 | 20 | Joris Michaux | [H] "virsh start my_kvm" |
317 | 20 | Joris Michaux | </pre> |
318 | 20 | Joris Michaux | |
319 | 20 | Joris Michaux | #Stop node |
320 | 20 | Joris Michaux | <pre> |
321 | 20 | Joris Michaux | [H] Soft : "virsh shutdown my_kvm" |
322 | 20 | Joris Michaux | [H] Hard : "virsh destroy my_kvm" |
323 | 20 | Joris Michaux | </pre> |
324 | 20 | Joris Michaux | |
325 | 20 | Joris Michaux | #Suppr node del |
326 | 20 | Joris Michaux | <pre> |
327 | 20 | Joris Michaux | [H] "virsh undefine node" (+ remove files) |
328 | 20 | Joris Michaux | </pre> |
329 | 20 | Joris Michaux | |
330 | 20 | Joris Michaux | #Rename node |
331 | 20 | Joris Michaux | <pre> |
332 | 20 | Joris Michaux | [H] "virsh dumpxml my_kvm > foo.xml" |
333 | 20 | Joris Michaux | [H] <edit foo.xml, change the name, move storage> |
334 | 20 | Joris Michaux | [H] "virsh undefine my_kvm" |
335 | 20 | Joris Michaux | [H] "virsh define foo.xml" |
336 | 20 | Joris Michaux | </pre> |
337 | 20 | Joris Michaux | |
338 | 20 | Joris Michaux | # Connect to virsh qemu |
339 | 20 | Joris Michaux | <pre> |
340 | 20 | Joris Michaux | [H] "virsh --connect qemu:///system" |
341 | 20 | Joris Michaux | [H] "virsh # help" |
342 | 20 | Joris Michaux | </pre> |
343 | 20 | Joris Michaux | |
344 | 20 | Joris Michaux | #Start a network |
345 | 20 | Joris Michaux | <pre> |
346 | 20 | Joris Michaux | [H] "virsh net-start my_network" |
347 | 20 | Joris Michaux | </pre> |
348 | 20 | Joris Michaux | |
349 | 20 | Joris Michaux | #Configure VNC |
350 | 20 | Joris Michaux | |
351 | 20 | Joris Michaux | <pre> |
352 | 20 | Joris Michaux | [H] Edit /etc/libvirt/qemu.conf and set vnc_listen = "your.ip.addd" |
353 | 20 | Joris Michaux | [H] You need to restart service "/etc/init.d/libvirtd restart" |
354 | 20 | Joris Michaux | [H] "ps aux | grep -i kvm" (find vnc display for your KVM) |
355 | 20 | Joris Michaux | </pre> |
356 | 20 | Joris Michaux | |
357 | 20 | Joris Michaux | #Connect to a KVM through VNC |
358 | 20 | Joris Michaux | |
359 | 20 | Joris Michaux | <pre> |
360 | 20 | Joris Michaux | tightvncviewer -compresslevel 7 -encodings "copyrect tight hextile zlib corre rre raw" x.xxx.xxx.xxx:x |
361 | 20 | Joris Michaux | </pre> |
362 | 20 | Joris Michaux | |
363 | 20 | Joris Michaux | #Keyboard FR for KVM |
364 | 20 | Joris Michaux | <pre> |
365 | 20 | Joris Michaux | [H] "virsh edit my_kvm" |
366 | 20 | Joris Michaux | [XML] <graphics type='vnc' port='-1' autoport='yes' keymap='fr'/> |
367 | 20 | Joris Michaux | </pre> |
368 | 20 | Joris Michaux | |
369 | 20 | Joris Michaux | #Create your own NAT network |
370 | 20 | Joris Michaux | <pre> |
371 | 20 | Joris Michaux | [H] Create your_nat.xml file : |
372 | 20 | Joris Michaux | [XML] <network> |
373 | 20 | Joris Michaux | <name>frp_network</name> |
374 | 20 | Joris Michaux | <forward mode='nat'/> |
375 | 20 | Joris Michaux | <bridge name='br1' stp='on' delay='0' /> |
376 | 20 | Joris Michaux | <ip address='10.16.42.1' netmask='255.255.255.0'> |
377 | 20 | Joris Michaux | <dhcp> |
378 | 20 | Joris Michaux | <range start='10.16.42.2' end='10.16.42.50' /> |
379 | 20 | Joris Michaux | </dhcp> |
380 | 20 | Joris Michaux | </ip> |
381 | 20 | Joris Michaux | </network> |
382 | 20 | Joris Michaux | [H] "virsh net-define your_nat.xml" |
383 | 20 | Joris Michaux | [H] "virsh net-start your_nat.xml" |
384 | 20 | Joris Michaux | [H] "virsh net-autostart your_nat.xml" |
385 | 20 | Joris Michaux | [XML] Network type "interface type = network, source network=your_nat" |
386 | 20 | Joris Michaux | </pre> |
387 | 20 | Joris Michaux | |
388 | 20 | Joris Michaux | #IBM advisements to improve performance |
389 | 20 | Joris Michaux | <pre> |
390 | 20 | Joris Michaux | [H] Use LVM (or other direct access to HDD) for VMs storage (from 45 to 3' to install a VM) |
391 | 20 | Joris Michaux | [H] Set the swappiness value to 0 ("echo 0 > /proc/sys/vm/swappiness" && edit "/etc/sysctl.conf" and add "vm.swappiness=0") |
392 | 20 | Joris Michaux | [H] Disable zone_reclaim ("echo 0 > /proc/sys/vm/zone_reclaim_mode" && edit "/etc/sysctl.conf" and add "vm.zone_reclaim_mode=0") |
393 | 20 | Joris Michaux | [H] Enable KSM ("echo 1 > /sys/kernel/mm/ksm/run") and set the check time to 200ms ("echo 200 > /sys/kernel/mm/ksm/sleep_millisecs") |
394 | 20 | Joris Michaux | </pre> |