diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-02-16 23:11:12 +0100 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-02-16 23:11:12 +0100 |
commit | e7acb2ed6b15dbd35350516a87e7b77e5ecbca0a (patch) | |
tree | 15dd1775f97a5970eee9b75c302bb810c47e285a /src | |
parent | b1e1075798617cc808cc171e86f182fe22a7de70 (diff) | |
download | notes-e7acb2ed6b15dbd35350516a87e7b77e5ecbca0a.tar.gz notes-e7acb2ed6b15dbd35350516a87e7b77e5ecbca0a.zip |
added qemu notes
Diffstat (limited to 'src')
-rw-r--r-- | src/SUMMARY.md | 1 | ||||
-rw-r--r-- | src/tools/README.md | 1 | ||||
-rw-r--r-- | src/tools/qemu.md | 99 |
3 files changed, 101 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 824570f..d5b1fa7 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -13,6 +13,7 @@ - [gpg](./tools/gpg.md) - [gdb](./tools/gdb.md) - [radare2](./tools/radare2.md) + - [qemu](./tools/qemu.md) - [Resource analysis & monitor](./monitor/README.md) - [lsof](./monitor/lsof.md) diff --git a/src/tools/README.md b/src/tools/README.md index cb7b2b0..e7c7809 100644 --- a/src/tools/README.md +++ b/src/tools/README.md @@ -10,3 +10,4 @@ - [gpg](./gpg.md) - [gdb](./gdb.md) - [radare2](./radare2.md) +- [qemu](./qemu.md) diff --git a/src/tools/qemu.md b/src/tools/qemu.md new file mode 100644 index 0000000..84eccae --- /dev/null +++ b/src/tools/qemu.md @@ -0,0 +1,99 @@ +# qemu(1) + +All the examples & notes use `qemu-system-x86_64` but in most cases +this can be swapped with the system emulator for other architectures. + +## Keybindings + +```markdown +Ctrl+Alt+g release mouse capture from VM + +Ctrl+Alt+1 switch to display of VM +Ctrl+Alt+2 switch to qemu monitor +``` + +## VM config snippet + +Following command-line gives a good starting point to assemble a VM: +```bash +qemu-system-x86_64 \ + -cpu host -enable-kvm -smp 4 \ + -m 8G \ + -vga virtio -display sdl,gl=on \ + -boot menu=on \ + -cdrom <iso> \ + -hda <disk> \ + -device qemu-xhci,id=xhci \ + -device usb-host,bus=xhci.0,vendorid=0x05e1,productid=0x0408,id=capture-card +``` + +### CPU & RAM + +- `-cpu host` emulate host CPU in guest VM +- `-enable-kvm` use KVM instead software models (requires KVM on host machine) +- `-smp <N>` number of guest CPUs +> List available CPUs `qemu-system-x86_64 -cpu help`. + +- `-m 8G` size of guest RAM + +### Graphic & Display + +- `-vga virtio` use virtio as 3D video graphic accelerator (requires virgl in guest) +- `-display sdl,gl=on` use sdl window and enable openGL context + +### Boot Menu + +- `-boot menu=on` enables boot menu to select boot device (enter with `ESC`) + +### Block devices + +- `-cdrom <iso>` attach cdrom drive with iso to a VM +- `-hda <disk>` attach disk drive to a VM +- `-drive file=<file>,format=qcow2` generic way to configure & attach a drive to a VM + +#### Create a disk with [`qemu-img`][doc-qemu-img] +To create a `qcow2` disk (qemu copy-on-write) of size `10G`: +```bash +qemu-img create -f qcow2 disk.qcow2 10G +``` + +The disk does not contain any `partitions` or a `partition table`. +We can format the disk from __within the **guest**__ as following example: +```bash +# Create `gpt` partition table. +sudo parted /dev/sda mktable gpt + +# Create two equally sized primary partitions. +sudo parted /dev/sda mkpart primary 0% 50% +sudo parted /dev/sda mkpart primary 50% 100% + +# Create filesystem on each partition. +sudo mkfs.ext3 /dev/sda1 +sudo mkfs.ext4 /dev/sda2 + +lsblk -f /dev/sda + NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT + sda + ├─sda1 ext3 .... + └─sda2 ext4 .... +``` + +### USB + +#### Host Controller +- `-device qemu-xhci,id=xhci` add XHCI USB controller to the VM (supports USB 3.0, 2.0, 1.1). `id=xhci` creates a usb bus named `xhci`. + +#### USB Device +- `-device usb-host,bus=xhci.0,vendorid=0x05e1,productid=0x0408` pass-through USB device from host identified by vendorid & productid and attach to usb bus `xhci.0` (defined with controller `id`) + +## References +- [QEMU USB][doc-qemu-usb] +- [QEMU IMG][doc-qemu-img] +- [QEMU Tools][doc-qemu-tools] +- [QEMU System][doc-qemu-system] + + +[doc-qemu-usb]: https://github.com/qemu/qemu/blob/master/docs/usb2.txt +[doc-qemu-img]: https://qemu.readthedocs.io/en/latest/tools/qemu-img.html +[doc-qemu-tools]: https://qemu.readthedocs.io/en/latest/tools/index.html +[doc-qemu-system]: https://www.qemu.org/docs/master/system/index.html |