351.3 QEMU (weight: 4)
Description: Candidates should be able to install, configure, maintain, migrate and troubleshoot QEMU installations.
Key Knowledge Areas:
Understand the architecture of QEMU, including KVM, networking and storage
Start QEMU instances from the command line
Manage snapshots using the QEMU monitor
Install the QEMU Guest Agent and VirtIO device drivers
Troubleshoot QEMU installations, including networking and storage
Awareness of important QEMU configuration parameters
The following is a partial list of the used files, terms and utilities:
Kernel modules: kvm, kvm-intel and kvm-amd
/dev/kvm
QEMU monitor
qemu
qemu-system-x86_64
ip
brctl
tunctl
Modos de funcionamiento de Qemu
- Emulación de sistema completo
- Emulación en modo usuario
- puedes ejecutar binarios nativos de otras plataformas
qemu-user
Tambien se puede utilizar con KVM, Xen y otros
apt install qemu
emular diferentes systemas
qemu-system-{arquitectura}
Principales parametros
qemu-system-x86_64
-boot # opcion de arranque
-cdrom # opcion de cdrom virtual
-m # memoria
-kernel
-initrd
-append # añade parameteros adicionales en el inicio del sistema
-device # añade un dispositivo, red, almacenamiento, entrada, ...
-netdev # opciones de red
-cpu # emular una cpu concreta
-smp cpus= # establece el numero de cpus
-drive # especifica parámetros de emulación del disco duro
-display # tipo de interfaz gráfica: `sdl, curses, vnc, ninguna, ...`
qemu-system-x86_64 -m 2048 -accel kvm -boot d disco_debian
qemu-system-x86_64 -m 2048 -accel kvm -boot d disco_debian -netdev user,id=myusernet -device e1000,netdev=myusernet
virtualizar sobre el software
qemu-img create -f qcow2 disco_debian 12G
qemu-system-x86_64 -m 2048 -cdrom debian-11.5.0-amd64.iso -boot d disco_debian
KVM
Es un módulo de Linux que permite que el SO funcione como un Hipervisor, forma parte del kernel desde la versión 2.6.20
- expone la interfaz
/dev/kvm
que será utilizada por programas en modo usuario como Qemu - delega en otros programas como Qemu la emulación de dispositivos
se necesita los modulos kvm_amd o kvm_intel
➜ ~ lsmod | grep kvm
kvm_amd 118784 0
virtualizar sobre kvm
qemu-img create -f qcow2 disco_debian 12G
qemu-system-x86_64 -m 2048 -accel kvm -cdrom debian-11.5.0-amd64.iso -boot d disco_debian
## Qemu monitor
En una maquina ejecutandose Ctrl + Mayus + Alt
(qemu) info
(qemu) info block
(qemu) change ide1-cd0 /home/user/fileIso.iso
(qemu) screendump NameFileOutPut
(qemu) savevm instantanea
(qemu) info snapshots
(qemu) loadvm instantanea
(qemu) delvm instantanea
(qemu) sendkey h-i
(qemu) info cpus
(qemu) info network
(qemu) info kvm
(qemu) system_powerdown
Qemu user Networking (SLIRP)
Crea una red por defecto donde la MV tiene acceso a la red y al host, pero el host no tiene acceso a la MV
default network - 10.0.2.0/24 - 10.0.2.2 Gateway - 10.0.2.3 DNS
Ejemplo redireccion puerto host:2222 a MV:22
qemu-system-x86_64 -m 2048 -accel kvm -netdev user,id=myusernet,hostfwd=tcp::2222-:22 -device e1000,netdev=myusernet disco_debian
Qemu monitor vutiliza los siguientes archivos
/etc/qemu-ifdown /etc/qemu-ifup
para levantar o apagar interfaces, que podemos modificar si lo necesitamos
Dispositivos TUN/TAP
Son dispositivos de red virtuales que no estan respaldadas por ningún dispositivo físico ( son completamente virtuales )
apt install uml-utilities
# crear red Tun manualmente
trunctl
trunctl -d tap0
# crearla automaticamente al arrancar la maquina
qemu-system-x86_64 -m 2048 -accel kvm -netdev tap,id=mytapnet -device virtio-net,netdev=mytapnet disco_debian
Con esta orden arranca la MV con una interfaz tab, y se a de configurar las ip tanto en host como en invitado, para acceder al exterior se necesita configurar un bridge con la interfaz local.
# En el host
apt install bridge-utils
brctl addbr puente0
brctl show puente0
brctl addif puente0 enp3s0
brctl addif puente0 tap0
ip link set puente0 up
# en el invitado
ip address add 192.168.88.20/24 dev ens3
Quemu guest agent
qemu-guest-agent
-chardev socket,path=/tmp/qga.sock,sever0on,wait=off,id=qga0
-device virtio-serial
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
-D
especifica el fichero log-d
habilita el log para los elementos especificos
ejemplo
qemu-system-x86_64 -m 2048 -accel kvm -device virtio-serial -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 -chardev socket,path=/tmp/qga.sock,sever0on,wait=off,id=qga0 -D logs.txt -d cpu_reset disco_debian