Qemu
By Miguel Teixeira
I’ve been using it both personally and professionally, but due to the sheer magnitude of the docs, I’ve decided to make my own cheat sheet.
Never forget that for each and any option you can add ol’ help to provide all options.
Install
On ubuntu
sudo apt install qemu
On arch
sudo pacman -Sy qemu-full
Everywhere
brew install qemu
Desktop
Create an image
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/yournamehereforvirtaccess.qcow2 20G
Run your image with cdrom on first boot
sudo qemu-system-x86_64 # Newer pc's only
-enable-kvm # Not sure but speed
-m 4G # Ram
-smp 4 # The number of cores
-boot menu=on # Good to have when kernel breaks
-drive file=/var/lib/libvirt/images/your_imagecreated.qcow2 # Get your images here for GUI access with [VirtMan](https://virt-manager.org/)
-cpu host # For the cpu config to match the host's
-vga virtio -display sdl,gl=on # Sauce: [Denshi](https://www.youtube.com/watch?v=AAfFewePE7c&t=505s) for this one
-soundhw hda # Audio driver should match the host
-cdrom /Documents/Isos/ # Your boot Iso
-chardev qemu-vdagent,id=ch1,name=vdagent,clipboard=on
-device virtio-serial-pci
-device virtserialport,chardev=ch1,id=ch1,name=com.redhat.spice.0 # Sauce: https://www.kraxel.org/blog/2021/05/qemu-cut-paste/
And just remove -cdrom to run the environment.
sudo qemu-system-x86_64 -enable-kvm -m 4G -smp 4 -boot menu=on -drive file=/var/lib/libvirt/images/your_imagecreated.qcow2 -cpu host -vga virtio -display sdl,gl=on
Be sure to not pick Weyland and instead choose Xorg on the Session Menu. (Unless it matches your hosts’) Results in less crashes.
Sharing data between host and client
Sauce: askUbuntu
sudo setfacl -R -m u:libvirt-qemu:rwx <path-of-the-shared folder>
sudo setfacl -R -m u:libvirt-qemu:rwx /<path-of-the-virtual-disk> (didn't had to)
Add Hardware -> Filesystem -> Mode to Mapped ->
Source path: Browse -> Browse Local -> Select folder -> Host path: /host
sudo mount -t 9p -o trans=virtio,version=9p2000.L /host /home/your-user-name/your-shared-folder-name
Now this folder is a point of access for both host and guest
Clipboard sauce: kraxel
Install on client & host:
- Linux: spice-vdagent
- Windows: spice-guest-tools (untested)
- Apple: https://www.spice-space.org/osx-client.html (untested)
VirtMan -> Display -> Type: spice server -> Video -> Model: QXL
Expected Xml of Hardware added:
<channel type="spicevmc">
<target type="virtio" name="com.redhat.spice.0" state="disconnected"/>
<alias name="channel1"/>
<address type="virtio-serial" controller="0" bus="0" port="2"/>
</channel>
Restart client.
systemctl status spice-vdagentd.service &&
To check if daemon in client is running
systemctl enable spice-vdagentd.service || spice-vdagent -d
If instead, you don’t want to use VirtMan:
qemu-system-x86_64 [ … ]
-chardev qemu-vdagent,id=ch1,name=vdagent,clipboard=on
-device virtio-serial-pci
-device virtserialport,chardev=ch1,id=ch1,name=com.redhat.spice.0
Android stuff
As of writing this there are currently 2 emulator in sdk’s:
- sdk/tools/emulator
- sdk/emulator/emulator
How to list your devices
“$ANDROID_HOME”/emulator/emulator -list-avds
As far as setting your local env, order here is important:
export ANDROID_HOME=~/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=:$PATH:~/Library/Android/sdk/platform-tools export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export ANDROID_SDK_ROOT=~/Library/Android/sdk export ANDROID_AVD_HOME=~/.android/avd
At least when running on emulators, avd is faster at booting.
To run on a single, faster emulation be sure to select the /emulator/emulator Eg:
“$ANDROID_HOME”/emulator/emulator -avd “Nexus_5X_API_28” -gpu on -memory 2500