Libvirt (ancien) » Historique » Version 28
Mehdi Abaakouk, 19/03/2014 11:25
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 | 28 | Mehdi Abaakouk | h2. Backup d'un VM n7 |
17 | 28 | Mehdi Abaakouk | |
18 | 28 | Mehdi Abaakouk | sur h2: |
19 | 28 | Mehdi Abaakouk | |
20 | 28 | Mehdi Abaakouk | # VM=XXX.gz; cd /backup/libvirt-n7-vm-raw/20140319/ ; if [ ! -f ${VM} ]; then socat -u tcp4-listen:50555 - > $VM ; zcat $VM | md5sum -; du -hs *; else echo $VM already present;fi |
21 | 28 | Mehdi Abaakouk | |
22 | 28 | Mehdi Abaakouk | sur la machine n7: |
23 | 28 | Mehdi Abaakouk | |
24 | 28 | Mehdi Abaakouk | # virsh shutdown XXX |
25 | 28 | Mehdi Abaakouk | # LV=XXX; cat /dev/raid5/$LV | gzip --fast|socat -u - tcp4:h2.tetaneutral.net:50555;md5sum /dev/raid5/$LV |
26 | 28 | Mehdi Abaakouk | |
27 | 28 | Mehdi Abaakouk | |
28 | 1 | Mehdi Abaakouk | h2. Installation VM sans bridge avec routage static (en /32 pour l'ipv4) |
29 | 1 | Mehdi Abaakouk | |
30 | 28 | 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/ |
31 | 11 | Mehdi Abaakouk | |
32 | 28 | Mehdi Abaakouk | Le répertoire /etc/libvirt/ttnn cité plustard est géré dans ce git. |
33 | 1 | Mehdi Abaakouk | |
34 | 1 | Mehdi Abaakouk | h3. Configuration de la libvirt |
35 | 1 | Mehdi Abaakouk | |
36 | 28 | Mehdi Abaakouk | On créé un réseau libvirt qui fait rien (déjà fait sur n7): |
37 | 1 | Mehdi Abaakouk | |
38 | 10 | Mehdi Abaakouk | <pre> |
39 | 1 | Mehdi Abaakouk | cat > libvirt_dump_network.xml <<EOF |
40 | 1 | Mehdi Abaakouk | <network ipv6='yes'> |
41 | 6 | Mehdi Abaakouk | <name>dump-net</name> |
42 | 1 | Mehdi Abaakouk | <bridge name='dumpbr0' /> |
43 | 1 | Mehdi Abaakouk | </network> |
44 | 1 | Mehdi Abaakouk | EOF |
45 | 10 | Mehdi Abaakouk | |
46 | 1 | Mehdi Abaakouk | virsh net-define libvirt_dump_network.xml |
47 | 1 | Mehdi Abaakouk | virsh net-autostart dump-net |
48 | 1 | Mehdi Abaakouk | virsh net-start dump-net |
49 | 1 | Mehdi Abaakouk | </pre> |
50 | 1 | Mehdi Abaakouk | |
51 | 28 | Mehdi Abaakouk | On créé un hook libvirt (déjà fait sur n7): |
52 | 1 | Mehdi Abaakouk | <pre> |
53 | 9 | Mehdi Abaakouk | mkdir -p /etc/libvirt/ttnn/hooks |
54 | 9 | Mehdi Abaakouk | ln -s /etc/libvirt/ttnn/hooks /etc/libvirt/hooks |
55 | 1 | Mehdi Abaakouk | vi /etc/libvirt/hooks/qemu |
56 | 1 | Mehdi Abaakouk | ----8<--------------->8---- |
57 | 1 | Mehdi Abaakouk | #!/bin/bash |
58 | 1 | Mehdi Abaakouk | |
59 | 1 | Mehdi Abaakouk | name="$1" |
60 | 1 | Mehdi Abaakouk | operation="$2" |
61 | 1 | Mehdi Abaakouk | suboperation="$3" |
62 | 1 | Mehdi Abaakouk | |
63 | 7 | Mehdi Abaakouk | [ "$operation" != "start" ] && exit 0 |
64 | 1 | Mehdi Abaakouk | [ "$suboperation" != "begin" ] && exit 0 |
65 | 1 | Mehdi Abaakouk | |
66 | 1 | Mehdi Abaakouk | # get interface from the libvirt xml |
67 | 1 | Mehdi Abaakouk | interface=$(cat - | sed -ne "/vnet/s/.*dev='\([^']*\)'.*/\1/gp") |
68 | 5 | Mehdi Abaakouk | |
69 | 5 | Mehdi Abaakouk | [ -f /etc/libvirt/ttnn/${name}.conf ] && source /etc/libvirt/ttnn/${name}.conf |
70 | 5 | Mehdi Abaakouk | |
71 | 1 | Mehdi Abaakouk | [ "$ip" -o "$ip6" ] && brctl delif dumpbr0 $interface |
72 | 1 | Mehdi Abaakouk | [ "$ip" ] && ip route add $ip/32 dev $interface |
73 | 1 | Mehdi Abaakouk | [ "$ip6" ] && ip route add $ip6/56 dev $interface |
74 | 1 | Mehdi Abaakouk | [ "$ip6" ] && ip -6 addr add fe80::31/64 dev $interface |
75 | 1 | Mehdi Abaakouk | exit 0 |
76 | 1 | Mehdi Abaakouk | ----8<--------------->8---- |
77 | 1 | Mehdi Abaakouk | </pre> |
78 | 1 | Mehdi Abaakouk | |
79 | 1 | Mehdi Abaakouk | |
80 | 4 | Mehdi Abaakouk | h3. Preparation de l'installer |
81 | 1 | Mehdi Abaakouk | |
82 | 28 | Mehdi Abaakouk | Pour une squeeze on met à jour virtinst (déjà fait sur n7): |
83 | 1 | Mehdi Abaakouk | |
84 | 9 | Mehdi Abaakouk | <pre> |
85 | 9 | Mehdi Abaakouk | wget http://ftp.us.debian.org/debian/pool/main/v/virtinst/virtinst_0.600.3-3_all.deb |
86 | 1 | Mehdi Abaakouk | dpkg -i virtinst_0.600.3-3_all.deb |
87 | 1 | Mehdi Abaakouk | </pre> |
88 | 1 | Mehdi Abaakouk | |
89 | 28 | Mehdi Abaakouk | On install le preseed.cfg attaché à la page dans /etc/libvirt/preseed.cfg (déjà fait sur n7) |
90 | 1 | Mehdi Abaakouk | |
91 | 1 | Mehdi Abaakouk | h4. Installation d'une VM |
92 | 4 | Mehdi Abaakouk | |
93 | 28 | Mehdi Abaakouk | Creation du disk (déjà fait sur n7): |
94 | 1 | Mehdi Abaakouk | <pre> |
95 | 1 | Mehdi Abaakouk | lvcreate -n picttn -L 50G /dev/raid5 |
96 | 1 | Mehdi Abaakouk | </pre> |
97 | 5 | Mehdi Abaakouk | |
98 | 5 | Mehdi Abaakouk | Configuration du routage static: |
99 | 5 | Mehdi Abaakouk | |
100 | 1 | Mehdi Abaakouk | <pre> |
101 | 5 | Mehdi Abaakouk | vi /etc/libvirt/ttnn/picttn.conf |
102 | 16 | Mehdi Abaakouk | # le /32 ipv4 |
103 | 1 | Mehdi Abaakouk | ip="91.224.148.252" |
104 | 16 | Mehdi Abaakouk | # le /56 ipv6 |
105 | 5 | Mehdi Abaakouk | ip6="2a01:6600:8080:FC00::" |
106 | 5 | Mehdi Abaakouk | </pre> |
107 | 8 | Mehdi Abaakouk | |
108 | 28 | Mehdi Abaakouk | Lancement de l'installation via le réseau natter de libvirt |
109 | 1 | Mehdi Abaakouk | <pre> |
110 | 1 | Mehdi Abaakouk | virt-install -n picttn -r 2048 --os-type=linux \ |
111 | 8 | Mehdi Abaakouk | --autostart \ |
112 | 1 | Mehdi Abaakouk | --disk /dev/raid5/picttn,bus=virtio,cache=none,io=native \ |
113 | 13 | Mehdi Abaakouk | --network network=default,model=virtio \ |
114 | 8 | Mehdi Abaakouk | --nographics \ |
115 | 6 | Mehdi Abaakouk | --noreboot \ |
116 | 1 | Mehdi Abaakouk | --wait -1 \ |
117 | 1 | Mehdi Abaakouk | --location http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/ \ |
118 | 6 | Mehdi Abaakouk | --serial pty \ |
119 | 8 | Mehdi Abaakouk | --initrd-inject /etc/libvirt/ttnn/preseed.cfg \ |
120 | 7 | Mehdi Abaakouk | --initrd-inject /etc/libvirt/ttnn/picttn.conf \ |
121 | 1 | Mehdi Abaakouk | --initrd-inject /etc/libvirt/ttnn/postinstall.sh \ |
122 | 1 | Mehdi Abaakouk | --extra-args "console=ttyS0,9600n8 DEBIAN_FRONTEND=text auto priority=critical hostname=picttn domain=le-pic.org" |
123 | 8 | Mehdi Abaakouk | </pre> |
124 | 8 | Mehdi Abaakouk | |
125 | 28 | Mehdi Abaakouk | Une fois l'installation terminée, on change la conf réseau: |
126 | 1 | Mehdi Abaakouk | |
127 | 14 | Mehdi Abaakouk | <pre> |
128 | 8 | Mehdi Abaakouk | EDITOR="sed -ie s/default/dump-net/g" virsh edit picttn |
129 | 8 | Mehdi Abaakouk | </pre> |
130 | 1 | Mehdi Abaakouk | |
131 | 28 | Mehdi Abaakouk | On peux démarrer la VM |
132 | 8 | Mehdi Abaakouk | <pre> |
133 | 8 | Mehdi Abaakouk | virsh start picttn |
134 | 3 | Mehdi Abaakouk | virsh console picttn |
135 | 1 | Mehdi Abaakouk | </pre> |
136 | 1 | Mehdi Abaakouk | |
137 | 28 | Mehdi Abaakouk | Ensuite on peux se connecte à la VM |
138 | 17 | Laurent GUERBY | <pre> |
139 | 17 | Laurent GUERBY | ssh root@2a01:6600:8080:FC00::1 |
140 | 17 | Laurent GUERBY | </pre> |
141 | 17 | Laurent GUERBY | |
142 | 28 | Mehdi Abaakouk | Le /etc/network/interfaces IPv4 après installation |
143 | 21 | Laurent GUERBY | |
144 | 21 | Laurent GUERBY | <pre> |
145 | 21 | Laurent GUERBY | iface eth0 inet static |
146 | 21 | Laurent GUERBY | address 91.224.148.xxx |
147 | 1 | Mehdi Abaakouk | netmask 32 |
148 | 1 | Mehdi Abaakouk | up ip route add 91.224.148.0/32 dev eth0 |
149 | 1 | Mehdi Abaakouk | up ip route add default via 91.224.148.0 |
150 | 1 | Mehdi Abaakouk | |
151 | 1 | Mehdi Abaakouk | iface eth0 inet6 static |
152 | 21 | Laurent GUERBY | address 2a01:6600:8080:xx00::1 |
153 | 1 | Mehdi Abaakouk | netmask 56 |
154 | 21 | Laurent GUERBY | gateway fe80::31 |
155 | 21 | Laurent GUERBY | pre-up /sbin/sysctl -w net.ipv6.conf.eth0.accept_ra=0 |
156 | 17 | Laurent GUERBY | pre-up /sbin/sysctl -w net.ipv6.conf.eth0.autoconf=0 |
157 | 19 | Laurent GUERBY | |
158 | 19 | Laurent GUERBY | </pre> |
159 | 19 | Laurent GUERBY | |
160 | 19 | Laurent GUERBY | h2. Misc |
161 | 19 | Laurent GUERBY | |
162 | 28 | Mehdi Abaakouk | <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 |
163 | 28 | Mehdi Abaakouk | <H4Mm3r> le disk se créé mais dans le XML le format est à RAW |
164 | 28 | Mehdi Abaakouk | <H4Mm3r> si tu le créé à l'avance avec qemu-img create -f qcow2 |
165 | 19 | Laurent GUERBY | <H4Mm3r> et que tu lance ta commande --disk /vmroot/testnat.qcow2,format=qcow2 |
166 | 28 | Mehdi Abaakouk | <guerby> ok donc c'etait bien ça :) |
167 | 19 | Laurent GUERBY | <guerby> bbl (miam) |
168 | 28 | Mehdi Abaakouk | <H4Mm3r> dans le fichier XML le format est à RAW |
169 | 28 | Mehdi Abaakouk | <H4Mm3r> il faut en effet dumper un XML, modifier la valeur à QCOW2 |
170 | 28 | Mehdi Abaakouk | <H4Mm3r> et créer la VM depuis ce XML |
171 | 19 | Laurent GUERBY | <H4Mm3r> virsh create file.xml |
172 | 20 | Joris Michaux | <H4Mm3r> pourqu'enfin il comprenne que c'est du QCOW... |
173 | 28 | Mehdi Abaakouk | <H4Mm3r> et là mon disk fait bien 265ko, mais est détecté comme 12G :D |
174 | 20 | Joris Michaux | |
175 | 20 | Joris Michaux | h2. HOWTO by H4Mm3r (under contruction) |
176 | 20 | Joris Michaux | |
177 | 20 | Joris Michaux | h3. Usefull links |
178 | 20 | Joris Michaux | |
179 | 20 | Joris Michaux | #### Misc |
180 | 20 | Joris Michaux | |
181 | 20 | Joris Michaux | #OS Type |
182 | 20 | Joris Michaux | http://rhevdup.blogspot.fr/2012/05/list-available-os-types-for-kvm-on-rhel.html |
183 | 20 | Joris Michaux | |
184 | 20 | Joris Michaux | #Libvirt TTN |
185 | 20 | Joris Michaux | http://chiliproject.tetaneutral.net/projects/tetaneutral/wiki/Libvirt |
186 | 20 | Joris Michaux | |
187 | 20 | Joris Michaux | #### KVM management |
188 | 20 | Joris Michaux | |
189 | 20 | Joris Michaux | #Install QEMU KVM + LIBVIRT |
190 | 20 | Joris Michaux | http://www.howtoforge.com/virtualization-with-kvm-on-a-debian-squeeze-server |
191 | 20 | Joris Michaux | |
192 | 20 | Joris Michaux | #Edit XML file |
193 | 20 | Joris Michaux | http://vladnevzorov.com/2011/02/11/how-to-change-configuration-of-kvm-virtual-machine/ |
194 | 20 | Joris Michaux | |
195 | 20 | Joris Michaux | #Clone a KVM |
196 | 20 | Joris Michaux | https://help.ubuntu.com/community/KVM/CreateGuests#Cloning_a_virtual_machine |
197 | 20 | Joris Michaux | http://linux.die.net/man/1/virt-clone |
198 | 20 | Joris Michaux | |
199 | 20 | Joris Michaux | #### Network |
200 | 20 | Joris Michaux | |
201 | 20 | Joris Michaux | #NAT |
202 | 20 | Joris Michaux | http://www.linuxquestions.org/questions/linux-networking-3/kvm-qemu-and-nat-on-the-host-machine-mini-tutorial-697980/ |
203 | 20 | Joris Michaux | http://wiki.libvirt.org/page/Networking |
204 | 20 | Joris Michaux | http://libvirt.org/formatnetwork.html#examplesNAT |
205 | 20 | Joris Michaux | https://help.ubuntu.com/community/KVM/Networking |
206 | 20 | Joris Michaux | |
207 | 20 | Joris Michaux | #Bridge |
208 | 20 | Joris Michaux | http://toast.djw.org.uk/qemu.html |
209 | 20 | Joris Michaux | http://www.mediaonfire.com/en/tech_tips/QEMUNetworking.html (bridge, nat, arp) |
210 | 20 | Joris Michaux | |
211 | 20 | Joris Michaux | #### Improve performance |
212 | 20 | Joris Michaux | http://blog.bodhizazen.net/linux/improve-kvm-performance/ |
213 | 20 | Joris Michaux | http://www.linux-kvm.org/page/Tuning_KVM |
214 | 20 | Joris Michaux | http://www.ezunix.org/index.php?title=Boost_performance_of_KVM_guests |
215 | 20 | Joris Michaux | |
216 | 20 | Joris Michaux | #### Storage |
217 | 20 | Joris Michaux | http://doc.opensuse.org/products/draft/SLES/SLES-kvm_sd_draft/cha.libvirt.storage.html |
218 | 20 | Joris Michaux | |
219 | 20 | Joris Michaux | h3. HOWTO |
220 | 20 | Joris Michaux | |
221 | 20 | Joris Michaux | <pre> |
222 | 20 | Joris Michaux | [H] = Host |
223 | 20 | Joris Michaux | [G] = Guest |
224 | 20 | Joris Michaux | [XML] = XML content |
225 | 20 | Joris Michaux | "command" |
226 | 20 | Joris Michaux | </pre> |
227 | 20 | Joris Michaux | |
228 | 20 | Joris Michaux | #### Diskfile Storage |
229 | 20 | Joris Michaux | |
230 | 20 | Joris Michaux | #Create qcow2 disk |
231 | 20 | Joris Michaux | <pre> |
232 | 20 | Joris Michaux | [H] "qemu-img create -f qcow2 /path/to/disk.qcow2 $SIZE" (ex: 20G) |
233 | 20 | Joris Michaux | [H] "chmod +x /path/to/disk.qcow2" |
234 | 20 | Joris Michaux | </pre> |
235 | 20 | Joris Michaux | |
236 | 20 | Joris Michaux | #Convert raw to qcow2 |
237 | 20 | Joris Michaux | <pre> |
238 | 20 | Joris Michaux | [H] "qemu-img convert -O qcow2 disk.img disk.qcow2" |
239 | 20 | Joris Michaux | </pre> |
240 | 20 | Joris Michaux | |
241 | 20 | Joris Michaux | #Disable cache to improve performance |
242 | 20 | Joris Michaux | <pre> |
243 | 20 | Joris Michaux | [XML] <driver name='qemu' type='qcow2' cache='none'/> |
244 | 20 | Joris Michaux | </pre> |
245 | 20 | Joris Michaux | |
246 | 20 | Joris Michaux | #### LVM Storage |
247 | 20 | Joris Michaux | |
248 | 20 | Joris Michaux | <pre> |
249 | 20 | Joris Michaux | [H] Create "/etc/libvirt/storage/vmdata.xml" file : |
250 | 20 | Joris Michaux | <pool type="logical"> |
251 | 20 | Joris Michaux | <name>my_pool</name> |
252 | 20 | Joris Michaux | <source> |
253 | 20 | Joris Michaux | <device path="/path/to/dev"/> |
254 | 20 | Joris Michaux | </source> |
255 | 20 | Joris Michaux | <target> |
256 | 20 | Joris Michaux | <path>/target/path/path> (LV will be created there) |
257 | 20 | Joris Michaux | </target> |
258 | 20 | Joris Michaux | </pool> |
259 | 20 | Joris Michaux | [H] "virsh pool-define /etc/libvirt/storage/my_pool.xml" |
260 | 20 | Joris Michaux | [H] "virsh pool-start my_pool" |
261 | 20 | Joris Michaux | [H] "virsh pool-autostart my_pool" |
262 | 20 | Joris Michaux | [H] "virsh pool-info my_pool" |
263 | 20 | Joris Michaux | [H] "virsh vol-create-as my_pool my_logical_volume 12G" |
264 | 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" |
265 | 20 | Joris Michaux | </pre> |
266 | 20 | Joris Michaux | |
267 | 20 | Joris Michaux | h3. Create KVM |
268 | 20 | Joris Michaux | |
269 | 20 | Joris Michaux | #Bridged with TAP + LVM |
270 | 20 | Joris Michaux | <pre> |
271 | 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" |
272 | 20 | Joris Michaux | </pre> |
273 | 20 | Joris Michaux | |
274 | 20 | Joris Michaux | #TAP (if you want to rename the default "vnetX" interface by "tapX" |
275 | 20 | Joris Michaux | <pre> |
276 | 20 | Joris Michaux | [H] "virsh dumpxml my_guest > my_guest.xml |
277 | 20 | Joris Michaux | [H] "virsh undefine my_guest" |
278 | 20 | Joris Michaux | [H] Edit the my_guest.xml file to rename VNETX by TAPX |
279 | 20 | Joris Michaux | [H] "virsh define my_guest.xml" |
280 | 20 | Joris Michaux | [H] "virsh start my_guest" |
281 | 20 | Joris Michaux | </pre> |
282 | 20 | Joris Michaux | |
283 | 20 | Joris Michaux | #NATed + LVM |
284 | 20 | Joris Michaux | <pre> |
285 | 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" |
286 | 20 | Joris Michaux | </pre> |
287 | 20 | Joris Michaux | |
288 | 20 | Joris Michaux | #Clone VM |
289 | 20 | Joris Michaux | <pre> |
290 | 20 | Joris Michaux | [H] Create the LVM dest |
291 | 20 | Joris Michaux | [H] Pause the KVM "virsh suspend my_kvm" |
292 | 20 | Joris Michaux | [H] virt-clone -o my_orig_kvm -n my_cloned_kvm -f=/path/to/lvm/dev |
293 | 20 | Joris Michaux | [G] Go and change the hostname and resolv.conf |
294 | 20 | Joris Michaux | </pre> |
295 | 20 | Joris Michaux | |
296 | 20 | Joris Michaux | h3. Command explanation |
297 | 20 | Joris Michaux | |
298 | 20 | Joris Michaux | #Bridged with tap |
299 | 20 | Joris Michaux | <pre> |
300 | 20 | Joris Michaux | virt-install -d --hvm --vnc --name=testlvm \ |
301 | 20 | Joris Michaux | --vcpus=4 --cpuset=0-4 \ |
302 | 20 | Joris Michaux | --ram 2048 \ |
303 | 20 | Joris Michaux | --disk vol=vmdata/testlvm,bus=virtio,cache=none \ |
304 | 20 | Joris Michaux | --network bridge=br0,model=virtio \ |
305 | 20 | Joris Michaux | -c /data/isos/debian-testing-amd64-netinst.iso \ |
306 | 20 | Joris Michaux | --keymap=fr --os-type=linux --os-variant=debiansqueeze --noautoconsole |
307 | 20 | Joris Michaux | </pre> |
308 | 20 | Joris Michaux | |
309 | 20 | Joris Michaux | #NATed |
310 | 20 | Joris Michaux | <pre> |
311 | 20 | Joris Michaux | virt-install -d --hvm --vnc --name=testlvm \ |
312 | 20 | Joris Michaux | --vcpus=4 --cpuset=0-4 \ |
313 | 20 | Joris Michaux | --ram 2048 \ |
314 | 20 | Joris Michaux | --disk vol=vmdata/testlvm,bus=virtio,cache=none \ |
315 | 20 | Joris Michaux | --network network=frp_network,model=virtio \ |
316 | 20 | Joris Michaux | -c /data/isos/debian-testing-amd64-netinst.iso \ |
317 | 20 | Joris Michaux | --keymap=fr --os-type=linux --os-variant=debiansqueeze --noautoconsole |
318 | 20 | Joris Michaux | </pre> |
319 | 20 | Joris Michaux | |
320 | 20 | Joris Michaux | [OLD QCOW2] |
321 | 20 | Joris Michaux | <pre> |
322 | 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" |
323 | 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" |
324 | 20 | Joris Michaux | </pre> |
325 | 20 | Joris Michaux | |
326 | 20 | Joris Michaux | #Start a KVM |
327 | 20 | Joris Michaux | <pre> |
328 | 20 | Joris Michaux | [H] "virsh start my_kvm" |
329 | 20 | Joris Michaux | </pre> |
330 | 20 | Joris Michaux | |
331 | 20 | Joris Michaux | #Stop node |
332 | 20 | Joris Michaux | <pre> |
333 | 20 | Joris Michaux | [H] Soft : "virsh shutdown my_kvm" |
334 | 20 | Joris Michaux | [H] Hard : "virsh destroy my_kvm" |
335 | 20 | Joris Michaux | </pre> |
336 | 20 | Joris Michaux | |
337 | 20 | Joris Michaux | #Suppr node del |
338 | 20 | Joris Michaux | <pre> |
339 | 20 | Joris Michaux | [H] "virsh undefine node" (+ remove files) |
340 | 20 | Joris Michaux | </pre> |
341 | 20 | Joris Michaux | |
342 | 20 | Joris Michaux | #Rename node |
343 | 20 | Joris Michaux | <pre> |
344 | 20 | Joris Michaux | [H] "virsh dumpxml my_kvm > foo.xml" |
345 | 20 | Joris Michaux | [H] <edit foo.xml, change the name, move storage> |
346 | 20 | Joris Michaux | [H] "virsh undefine my_kvm" |
347 | 20 | Joris Michaux | [H] "virsh define foo.xml" |
348 | 20 | Joris Michaux | </pre> |
349 | 20 | Joris Michaux | |
350 | 20 | Joris Michaux | # Connect to virsh qemu |
351 | 20 | Joris Michaux | <pre> |
352 | 20 | Joris Michaux | [H] "virsh --connect qemu:///system" |
353 | 20 | Joris Michaux | [H] "virsh # help" |
354 | 20 | Joris Michaux | </pre> |
355 | 20 | Joris Michaux | |
356 | 20 | Joris Michaux | #Start a network |
357 | 20 | Joris Michaux | <pre> |
358 | 20 | Joris Michaux | [H] "virsh net-start my_network" |
359 | 20 | Joris Michaux | </pre> |
360 | 20 | Joris Michaux | |
361 | 20 | Joris Michaux | #Configure VNC |
362 | 20 | Joris Michaux | |
363 | 20 | Joris Michaux | <pre> |
364 | 20 | Joris Michaux | [H] Edit /etc/libvirt/qemu.conf and set vnc_listen = "your.ip.addd" |
365 | 20 | Joris Michaux | [H] You need to restart service "/etc/init.d/libvirtd restart" |
366 | 20 | Joris Michaux | [H] "ps aux | grep -i kvm" (find vnc display for your KVM) |
367 | 20 | Joris Michaux | </pre> |
368 | 20 | Joris Michaux | |
369 | 20 | Joris Michaux | #Connect to a KVM through VNC |
370 | 20 | Joris Michaux | |
371 | 20 | Joris Michaux | <pre> |
372 | 20 | Joris Michaux | tightvncviewer -compresslevel 7 -encodings "copyrect tight hextile zlib corre rre raw" x.xxx.xxx.xxx:x |
373 | 20 | Joris Michaux | </pre> |
374 | 20 | Joris Michaux | |
375 | 20 | Joris Michaux | #Keyboard FR for KVM |
376 | 20 | Joris Michaux | <pre> |
377 | 20 | Joris Michaux | [H] "virsh edit my_kvm" |
378 | 20 | Joris Michaux | [XML] <graphics type='vnc' port='-1' autoport='yes' keymap='fr'/> |
379 | 20 | Joris Michaux | </pre> |
380 | 20 | Joris Michaux | |
381 | 20 | Joris Michaux | #Create your own NAT network |
382 | 20 | Joris Michaux | <pre> |
383 | 20 | Joris Michaux | [H] Create your_nat.xml file : |
384 | 20 | Joris Michaux | [XML] <network> |
385 | 20 | Joris Michaux | <name>frp_network</name> |
386 | 20 | Joris Michaux | <forward mode='nat'/> |
387 | 20 | Joris Michaux | <bridge name='br1' stp='on' delay='0' /> |
388 | 20 | Joris Michaux | <ip address='10.16.42.1' netmask='255.255.255.0'> |
389 | 20 | Joris Michaux | <dhcp> |
390 | 20 | Joris Michaux | <range start='10.16.42.2' end='10.16.42.50' /> |
391 | 20 | Joris Michaux | </dhcp> |
392 | 20 | Joris Michaux | </ip> |
393 | 20 | Joris Michaux | </network> |
394 | 20 | Joris Michaux | [H] "virsh net-define your_nat.xml" |
395 | 20 | Joris Michaux | [H] "virsh net-start your_nat.xml" |
396 | 20 | Joris Michaux | [H] "virsh net-autostart your_nat.xml" |
397 | 20 | Joris Michaux | [XML] Network type "interface type = network, source network=your_nat" |
398 | 20 | Joris Michaux | </pre> |
399 | 20 | Joris Michaux | |
400 | 20 | Joris Michaux | #IBM advisements to improve performance |
401 | 20 | Joris Michaux | <pre> |
402 | 20 | Joris Michaux | [H] Use LVM (or other direct access to HDD) for VMs storage (from 45 to 3' to install a VM) |
403 | 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") |
404 | 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") |
405 | 22 | Mehdi Abaakouk | [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") |
406 | 22 | Mehdi Abaakouk | </pre> |
407 | 22 | Mehdi Abaakouk | |
408 | 22 | Mehdi Abaakouk | |
409 | 22 | Mehdi Abaakouk | |
410 | 22 | Mehdi Abaakouk | h2. PC velizy |
411 | 22 | Mehdi Abaakouk | |
412 | 22 | Mehdi Abaakouk | |
413 | 22 | Mehdi Abaakouk | <pre> |
414 | 22 | Mehdi Abaakouk | root@tetaneutral1:~# fdisk /dev/sdb |
415 | 22 | Mehdi Abaakouk | |
416 | 22 | Mehdi Abaakouk | Command (m for help): p |
417 | 22 | Mehdi Abaakouk | |
418 | 22 | Mehdi Abaakouk | Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes |
419 | 22 | Mehdi Abaakouk | 255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors |
420 | 22 | Mehdi Abaakouk | Units = sectors of 1 * 512 = 512 bytes |
421 | 22 | Mehdi Abaakouk | Sector size (logical/physical): 512 bytes / 512 bytes |
422 | 22 | Mehdi Abaakouk | I/O size (minimum/optimal): 512 bytes / 512 bytes |
423 | 22 | Mehdi Abaakouk | Disk identifier: 0x9bf0c7df |
424 | 22 | Mehdi Abaakouk | |
425 | 22 | Mehdi Abaakouk | Device Boot Start End Blocks Id System |
426 | 22 | Mehdi Abaakouk | |
427 | 22 | Mehdi Abaakouk | Command (m for help): n |
428 | 22 | Mehdi Abaakouk | Partition type: |
429 | 22 | Mehdi Abaakouk | p primary (0 primary, 0 extended, 4 free) |
430 | 22 | Mehdi Abaakouk | e extended |
431 | 22 | Mehdi Abaakouk | Select (default p): p |
432 | 22 | Mehdi Abaakouk | Partition number (1-4, default 1): |
433 | 22 | Mehdi Abaakouk | Using default value 1 |
434 | 22 | Mehdi Abaakouk | First sector (2048-3907029167, default 2048): |
435 | 22 | Mehdi Abaakouk | Using default value 2048 |
436 | 22 | Mehdi Abaakouk | Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167): |
437 | 22 | Mehdi Abaakouk | Using default value 3907029167 |
438 | 22 | Mehdi Abaakouk | |
439 | 22 | Mehdi Abaakouk | Command (m for help): n |
440 | 22 | Mehdi Abaakouk | Partition type: |
441 | 22 | Mehdi Abaakouk | p primary (1 primary, 0 extended, 3 free) |
442 | 22 | Mehdi Abaakouk | e extended |
443 | 22 | Mehdi Abaakouk | Select (default p): ^C |
444 | 22 | Mehdi Abaakouk | root@tetaneutral1:~# fdisk /dev/sdb |
445 | 22 | Mehdi Abaakouk | |
446 | 22 | Mehdi Abaakouk | Command (m for help): n |
447 | 22 | Mehdi Abaakouk | Partition type: |
448 | 22 | Mehdi Abaakouk | p primary (0 primary, 0 extended, 4 free) |
449 | 22 | Mehdi Abaakouk | e extended |
450 | 22 | Mehdi Abaakouk | Select (default p): p |
451 | 22 | Mehdi Abaakouk | Partition number (1-4, default 1): 1 |
452 | 22 | Mehdi Abaakouk | First sector (2048-3907029167, default 2048): |
453 | 22 | Mehdi Abaakouk | Using default value 2048 |
454 | 22 | Mehdi Abaakouk | Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167): |
455 | 22 | Mehdi Abaakouk | Using default value 3907029167 |
456 | 22 | Mehdi Abaakouk | |
457 | 22 | Mehdi Abaakouk | Command (m for help): p |
458 | 22 | Mehdi Abaakouk | |
459 | 22 | Mehdi Abaakouk | Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes |
460 | 22 | Mehdi Abaakouk | 255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors |
461 | 22 | Mehdi Abaakouk | Units = sectors of 1 * 512 = 512 bytes |
462 | 22 | Mehdi Abaakouk | Sector size (logical/physical): 512 bytes / 512 bytes |
463 | 22 | Mehdi Abaakouk | I/O size (minimum/optimal): 512 bytes / 512 bytes |
464 | 22 | Mehdi Abaakouk | Disk identifier: 0x9bf0c7df |
465 | 22 | Mehdi Abaakouk | |
466 | 22 | Mehdi Abaakouk | Device Boot Start End Blocks Id System |
467 | 22 | Mehdi Abaakouk | /dev/sdb1 2048 3907029167 1953513560 83 Linux |
468 | 22 | Mehdi Abaakouk | |
469 | 22 | Mehdi Abaakouk | Command (m for help): m |
470 | 22 | Mehdi Abaakouk | Command action |
471 | 22 | Mehdi Abaakouk | a toggle a bootable flag |
472 | 22 | Mehdi Abaakouk | b edit bsd disklabel |
473 | 22 | Mehdi Abaakouk | c toggle the dos compatibility flag |
474 | 22 | Mehdi Abaakouk | d delete a partition |
475 | 22 | Mehdi Abaakouk | l list known partition types |
476 | 22 | Mehdi Abaakouk | m print this menu |
477 | 22 | Mehdi Abaakouk | n add a new partition |
478 | 22 | Mehdi Abaakouk | o create a new empty DOS partition table |
479 | 22 | Mehdi Abaakouk | p print the partition table |
480 | 22 | Mehdi Abaakouk | q quit without saving changes |
481 | 22 | Mehdi Abaakouk | s create a new empty Sun disklabel |
482 | 22 | Mehdi Abaakouk | t change a partition's system id |
483 | 22 | Mehdi Abaakouk | u change display/entry units |
484 | 22 | Mehdi Abaakouk | v verify the partition table |
485 | 22 | Mehdi Abaakouk | w write table to disk and exit |
486 | 22 | Mehdi Abaakouk | x extra functionality (experts only) |
487 | 22 | Mehdi Abaakouk | |
488 | 22 | Mehdi Abaakouk | Command (m for help): t |
489 | 22 | Mehdi Abaakouk | Selected partition 1 |
490 | 22 | Mehdi Abaakouk | Hex code (type L to list codes): L |
491 | 22 | Mehdi Abaakouk | |
492 | 22 | Mehdi Abaakouk | 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris |
493 | 22 | Mehdi Abaakouk | 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- |
494 | 22 | Mehdi Abaakouk | 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- |
495 | 22 | Mehdi Abaakouk | 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- |
496 | 22 | Mehdi Abaakouk | 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx |
497 | 22 | Mehdi Abaakouk | 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data |
498 | 22 | Mehdi Abaakouk | 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . |
499 | 22 | Mehdi Abaakouk | 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility |
500 | 22 | Mehdi Abaakouk | 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt |
501 | 22 | Mehdi Abaakouk | 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access |
502 | 22 | Mehdi Abaakouk | a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O |
503 | 22 | Mehdi Abaakouk | b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor |
504 | 22 | Mehdi Abaakouk | c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs |
505 | 22 | Mehdi Abaakouk | e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT |
506 | 22 | Mehdi Abaakouk | f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ |
507 | 22 | Mehdi Abaakouk | 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b |
508 | 22 | Mehdi Abaakouk | 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor |
509 | 22 | Mehdi Abaakouk | 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor |
510 | 22 | Mehdi Abaakouk | 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary |
511 | 22 | Mehdi Abaakouk | 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS |
512 | 22 | Mehdi Abaakouk | 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE |
513 | 22 | Mehdi Abaakouk | 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto |
514 | 22 | Mehdi Abaakouk | 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep |
515 | 22 | Mehdi Abaakouk | 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT |
516 | 22 | Mehdi Abaakouk | 1e Hidden W95 FAT1 80 Old Minix |
517 | 22 | Mehdi Abaakouk | Hex code (type L to list codes): 8e |
518 | 22 | Mehdi Abaakouk | Changed system type of partition 1 to 8e (Linux LVM) |
519 | 22 | Mehdi Abaakouk | |
520 | 22 | Mehdi Abaakouk | Command (m for help): w |
521 | 22 | Mehdi Abaakouk | The partition table has been altered! |
522 | 22 | Mehdi Abaakouk | |
523 | 22 | Mehdi Abaakouk | Calling ioctl() to re-read partition table. |
524 | 22 | Mehdi Abaakouk | Syncing disks. |
525 | 22 | Mehdi Abaakouk | </pre> |
526 | 1 | Mehdi Abaakouk | <pre> |
527 | 23 | Mehdi Abaakouk | pvcreate /dev/sdb1 |
528 | 24 | Mehdi Abaakouk | vgcreate vm-velizy /dev/sdb1 |
529 | 1 | Mehdi Abaakouk | lvcreate -n velizy-vm1 -L 50G vm-velizy |
530 | 25 | Mehdi Abaakouk | apt-get install virtinst |
531 | 1 | Mehdi Abaakouk | |
532 | 25 | Mehdi Abaakouk | |
533 | 27 | Mehdi Abaakouk | /root/preseed.cfg @ http://git.tetaneutral.net/libvirt.git/ |
534 | 27 | Mehdi Abaakouk | |
535 | 1 | Mehdi Abaakouk | replace the late-command line at the end of the file by: |
536 | 27 | Mehdi Abaakouk | d-i preseed/late_command string cp -f /postinstall-velizy.sh /target/; in-target bash /postinstall-velizy.sh |
537 | 25 | Mehdi Abaakouk | |
538 | 25 | Mehdi Abaakouk | |
539 | 25 | Mehdi Abaakouk | vmname=velizy-vm1 |
540 | 25 | Mehdi Abaakouk | ip=192.166.143.24 |
541 | 25 | Mehdi Abaakouk | |
542 | 25 | Mehdi Abaakouk | virt-install -n $vmname -r 2048 --os-type=linux \ |
543 | 25 | Mehdi Abaakouk | --debug \ |
544 | 25 | Mehdi Abaakouk | --autostart \ |
545 | 25 | Mehdi Abaakouk | --disk /dev/vm-velizy/$vmname,bus=virtio,cache=none,io=native \ |
546 | 25 | Mehdi Abaakouk | --network bridge=br0,model=virtio \ |
547 | 25 | Mehdi Abaakouk | --nographics \ |
548 | 25 | Mehdi Abaakouk | --noreboot \ |
549 | 25 | Mehdi Abaakouk | --wait -1 \ |
550 | 1 | Mehdi Abaakouk | --location http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/ \ |
551 | 27 | Mehdi Abaakouk | --serial pty \ |
552 | 25 | Mehdi Abaakouk | --initrd-inject /root/preseed.cfg \ |
553 | 1 | Mehdi Abaakouk | --initrd-inject /root/postinstall-velizy.sh \ |
554 | 27 | Mehdi Abaakouk | --extra-args "console=ttyS0,9600n8 DEBIAN_FRONTEND=text auto priority=critical hostname=$vmname domain=tetaneutral.net netcfg/get_ipaddress=$ip netcfg/get_netmask=255.255.252.0 netcfg/get_gateway=192.166.143.254 netcfg/get_nameservers=192.166.143.23 netcfg/disable_dhcp=true" |
555 | 27 | Mehdi Abaakouk | |
556 | 27 | Mehdi Abaakouk | </pre> |
557 | 27 | Mehdi Abaakouk | |
558 | 27 | Mehdi Abaakouk | |
559 | 27 | Mehdi Abaakouk | postinstall-velizy.sh |
560 | 27 | Mehdi Abaakouk | <pre> |
561 | 27 | Mehdi Abaakouk | #!/bin/bash |
562 | 27 | Mehdi Abaakouk | sed -i -e 's/^.*Port.*$/Port 2222/' -e 's/^[# ]*PasswordAuthentication.*$/PasswordAuthenticati |
563 | 27 | Mehdi Abaakouk | on no/' /etc/ssh/sshd_config |
564 | 27 | Mehdi Abaakouk | |
565 | 27 | Mehdi Abaakouk | mkdir -p /root/.ssh |
566 | 27 | Mehdi Abaakouk | cat > /root/.ssh/authorized_keys <<EOF |
567 | 27 | Mehdi Abaakouk | ssh-dss AAAAB3NzaC1kc3MAAACBAJtnGLvuz4uVD6fnERDxDi/C0UyzwCiKmgNtEessopREYasAX4Gu6Fg10jAyIL5Nuc |
568 | 27 | Mehdi Abaakouk | 7YDnqj//pOfxNjD7hp99a2ZmkRQgh/ltClxYML9fqhBHgsUCpVse9nOYDHDnDgvXIPRSDUHat2UFpdchHVrFURNLIlZnBz |
569 | 27 | Mehdi Abaakouk | tsr+GCDURTV/AAAAFQD9SrBcH49ltaKOm6V5ssCPmgs1SwAAAIAbAvkQ3/tMzzdACO5B9s5Yb3ZuM7XImm0iqufivVf2Xy |
570 | 27 | Mehdi Abaakouk | 39g8HOBulUsN7eKEGPhVriqNolgIO7q7tVgYAff4/NE4yDP0Kp0SPg4tjt2yFJuL31Y3wzwHjnKrjgNlDSLl3uZnRXSipw |
571 | 27 | Mehdi Abaakouk | UMwGKbdHB6NZSqlq192VKbHilQ00pbiMlAAAAIB5dfB1lVHkJ0o5CcaVQRPbca9DvbbRwnoTSmKHc5DUcqsPqDhS07CkM9 |
572 | 27 | Mehdi Abaakouk | ZcJuY1Nh4wGl4Q9kArj7Tnsvvygf/HReSUcIk4+nbDytJ8/pca/Qx4fzQQyppa94TylN62LSFT6MIJKLoMwYa0dQURT7Mv |
573 | 27 | Mehdi Abaakouk | 5+9Qj2vk5pZ38w2iQ9zVCg== root@h1 |
574 | 27 | Mehdi Abaakouk | EOF |
575 | 25 | Mehdi Abaakouk | |
576 | 25 | Mehdi Abaakouk | passwd -d root |
577 | 1 | Mehdi Abaakouk | </pre> |
578 | 24 | Mehdi Abaakouk | |
579 | 24 | Mehdi Abaakouk | |
580 | 1 | Mehdi Abaakouk | apt-get install debconf-utils |
581 | 1 | Mehdi Abaakouk | debconf-get-selections > preseed.cfg # marche pas |