diff options
author | johannst <johannst@users.noreply.github.com> | 2021-07-29 21:33:05 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2021-07-29 21:33:05 +0000 |
commit | 86bbee3264360de8ab5f8d2b277ac7d1045d0b80 (patch) | |
tree | 15e1f8862b44af3367de5ee55f4bc9b4415adee9 /tools | |
parent | 7dd27f2a72395e51db76ee344ffba56279d5c6ff (diff) | |
download | notes-86bbee3264360de8ab5f8d2b277ac7d1045d0b80.tar.gz notes-86bbee3264360de8ab5f8d2b277ac7d1045d0b80.zip |
deploy: d086ca4c6179628546796e60bfade25be061f045
Diffstat (limited to 'tools')
-rw-r--r-- | tools/awk.html | 7 | ||||
-rw-r--r-- | tools/qemu.html | 157 |
2 files changed, 117 insertions, 47 deletions
diff --git a/tools/awk.html b/tools/awk.html index 139ec07..3087bd7 100644 --- a/tools/awk.html +++ b/tools/awk.html @@ -223,6 +223,11 @@ For floats one can use <code>%N.Mf</code>, <code>N</code> is the total number in <code>M</code>.</p> </li> <li> +<p><code>sprintf("fmt", expr, ...)</code></p> +<p>Format the expressions according to the format string. Similar as <code>printf</code>, +but this is a function and return value can be assigned to a variable.</p> +</li> +<li> <p><code>strftime("fmt")</code></p> <p>Print time stamp formatted by <code>fmt</code>.</p> <ul> @@ -246,7 +251,7 @@ prints the whole record.</p> <h3><a class="header" href="#access-last-fields-in-records" id="access-last-fields-in-records">Access last fields in records</a></h3> <pre><code class="language-bash">echo 'a b c d e f' | awk '{ print $NF $(NF-1) }' </code></pre> -<p>Access last fields with arithmetic on the <code>NR</code> number of fields variable.</p> +<p>Access last fields with arithmetic on the <code>NF</code> number of fields variable.</p> <h3><a class="header" href="#capture-in-variables" id="capture-in-variables">Capture in variables</a></h3> <pre><code class="language-bash"># /proc/<pid>/status # Name: cat diff --git a/tools/qemu.html b/tools/qemu.html index 03fd8bc..fc88733 100644 --- a/tools/qemu.html +++ b/tools/qemu.html @@ -169,44 +169,55 @@ Ctrl+a c switch between monitor and console </code></pre> <h2><a class="header" href="#vm-config-snippet" id="vm-config-snippet">VM config snippet</a></h2> <p>Following command-line gives a good starting point to assemble a VM:</p> -<pre><code class="language-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 +<pre><code>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 </code></pre> <h3><a class="header" href="#cpu--ram" id="cpu--ram">CPU & RAM</a></h3> -<ul> -<li><code>-cpu host</code> emulate host CPU in guest VM</li> -<li><code>-enable-kvm</code> use KVM instead software models (requires KVM on host machine)</li> -<li><code>-smp <N></code> number of guest CPUs</li> -</ul> -<blockquote> -<p>List available CPUs <code>qemu-system-x86_64 -cpu help</code>.</p> -</blockquote> -<ul> -<li><code>-m 8G</code> size of guest RAM</li> -</ul> +<pre><code class="language-bash"># Emulate host CPU in guest VM, enabling all supported host featured (requires KVM). +# List available CPUs `qemu-system-x86_64 -cpu help`. +-cpu host + +# Enable KVM instead software emulation. +-enable-kvm + +# Configure number of guest CPUs. +-smp <N> + +# Configure size of guest RAM. +-m 8G +</code></pre> <h3><a class="header" href="#graphic--display" id="graphic--display">Graphic & Display</a></h3> -<ul> -<li><code>-vga virtio</code> use virtio as 3D video graphic accelerator (requires virgl in guest)</li> -<li><code>-display sdl,gl=on</code> use sdl window and enable openGL context</li> -</ul> +<pre><code class="language-bash"># Use sdl window as display and enable openGL context. +-display sdl,gl=on + +# Use vnc server as display (eg on display `:42` here). +-display vnc=localhost:42 + +# Confifure virtio as 3D video graphic accelerator (requires virgl in guest). +-vga virtio +</code></pre> <h3><a class="header" href="#boot-menu" id="boot-menu">Boot Menu</a></h3> -<ul> -<li><code>-boot menu=on</code> enables boot menu to select boot device (enter with <code>ESC</code>)</li> -</ul> +<pre><code class="language-bash"># Enables boot menu to select boot device (enter with `ESC`). +-boot menu=on +</code></pre> <h3><a class="header" href="#block-devices" id="block-devices">Block devices</a></h3> -<ul> -<li><code>-cdrom <iso></code> attach cdrom drive with iso to a VM</li> -<li><code>-hda <disk></code> attach disk drive to a VM</li> -<li><code>-drive file=<file>,format=qcow2</code> generic way to configure & attach a drive to a VM</li> -</ul> -<h4><a class="header" href="#create-a-disk-with-a-hrefhttpsqemureadthedocsioenlatesttoolsqemu-imghtmlqemu-imga" id="create-a-disk-with-a-hrefhttpsqemureadthedocsioenlatesttoolsqemu-imghtmlqemu-imga">Create a disk with <a href="https://qemu.readthedocs.io/en/latest/tools/qemu-img.html"><code>qemu-img</code></a></a></h4> +<pre><code class="language-bash"># Attach cdrom drive with iso to a VM. +-cdrom <iso> + +# Attach disk drive to a VM. +-hda <disk> + +# Generic way to configure & attach a drive to a VM. +-drive file=<file>,format=qcow2 +</code></pre> +<h4><a class="header" href="#create-a-disk-with-a-hrefhttpsqemu-projectgitlabioqemutoolsqemu-imghtmlqemu-imga" id="create-a-disk-with-a-hrefhttpsqemu-projectgitlabioqemutoolsqemu-imghtmlqemu-imga">Create a disk with <a href="https://qemu-project.gitlab.io/qemu/tools/qemu-img.html"><code>qemu-img</code></a></a></h4> <p>To create a <code>qcow2</code> disk (qemu copy-on-write) of size <code>10G</code>:</p> <pre><code class="language-bash">qemu-img create -f qcow2 disk.qcow2 10G </code></pre> @@ -231,24 +242,78 @@ lsblk -f /dev/sda </code></pre> <h3><a class="header" href="#usb" id="usb">USB</a></h3> <h4><a class="header" href="#host-controller" id="host-controller">Host Controller</a></h4> -<ul> -<li><code>-device qemu-xhci,id=xhci</code> add XHCI USB controller to the VM (supports USB 3.0, 2.0, 1.1). <code>id=xhci</code> creates a usb bus named <code>xhci</code>.</li> -</ul> +<pre><code class="language-bash"># Add XHCI USB controller to the VM (supports USB 3.0, 2.0, 1.1). +# `id=xhci` creates a usb bus named `xhci`. +-device qemu-xhci,id=xhci +</code></pre> <h4><a class="header" href="#usb-device" id="usb-device">USB Device</a></h4> -<ul> -<li><code>-device usb-host,bus=xhci.0,vendorid=0x05e1,productid=0x0408</code> pass-through USB device from host identified by vendorid & productid and attach to usb bus <code>xhci.0</code> (defined with controller <code>id</code>)</li> -</ul> +<pre><code class="language-bash"># Pass-through USB device from host identified by vendorid & productid and +# attach to usb bus `xhci.0` (defined with controller `id`). +-device usb-host,bus=xhci.0,vendorid=0x05e1,productid=0x0408 +</code></pre> <h2><a class="header" href="#debugging" id="debugging">Debugging</a></h2> -<ul> -<li><code>-gdb tcp::<port></code> open gdbstub on tcp <code><port></code> (<code>-s</code> shorthand for <code>-gdb tcp::1234</code>).</li> -<li><code>-S</code> freeze CPU at startup.</li> -</ul> +<pre><code class="language-bash"># Open gdbstub on tcp `<port>` (`-s` shorthand for `-gdb tcp::1234`). +-gdb tcp::<port> + +# Freeze guest CPU at startup and wait for debugger connection. +-S +</code></pre> +<h2><a class="header" href="#io-redirection" id="io-redirection">IO redirection</a></h2> +<pre><code class="language-bash"># Create raw tcp server for `serial IO` and wait until a client connects +# before executing the guest. +-serial tcp:localhost:12345,server,wait + +# Create telnet server for `serial IO` and wait until a client connects +# before executing the guest. +-serial telnet:localhost:12345,server,wait + +# Configure redirection for the QEMU `mointor`, arguments similar to `-serial` +# above. +-monitor ... +</code></pre> +<blockquote> +<p>In <code>server</code> mode use <code>nowait</code> to execute guest without waiting for a client +connection.</p> +</blockquote> +<h2><a class="header" href="#network" id="network">Network</a></h2> +<pre><code class="language-bash"># Redirect host tcp port `1234` to guest port `4321`. +-nic user,hostfwd=tcp:localhost:1234-:4321 +</code></pre> +<h2><a class="header" href="#shared-drives" id="shared-drives">Shared drives</a></h2> +<pre><code class="language-bash"># Attach a `virtio-9p-pci` device to the VM. +# The guest requires 9p support and can mount the shared drive as: +# mount -t 9p -o trans=virtio someName /mnt +-virtfs local,id=someName,path=<someHostPath>,mount_tag=someName,security_model=none +</code></pre> +<h2><a class="header" href="#tracing" id="tracing">Tracing</a></h2> +<pre><code class="language-bash"># List name of all trace points. +-trace help + +# Enable trace points matching pattern and optionally write trace to file. +-trace <pattern>[,file=<file>] + +# Enable trace points for all events listed in the <events> file. +# File must contain one event/pattern per line. +-trace events=<events> +</code></pre> +<h2><a class="header" href="#appendix-direct-kernel-boot" id="appendix-direct-kernel-boot">Appendix: Direct <code>Kernel</code> boot</a></h2> +<p>Example command line to directly boot a <code>Kernel</code> with an <code>initrd</code> ramdisk.</p> +<pre><code class="language-bash">qemu-system-x86_64 \ + -cpu host \ + -enable-kvm \ + -kernel <dir>/arch/x86/boot/bzImage \ + -append "earlyprintk=ttyS0 console=ttyS0 nokaslr init=/init debug" \ + -initrd <dir>/initramfs.cpio.gz \ + ... +</code></pre> +<p>Instructions to build a minimal <a href="https://blog.memzero.de/kernel-debugging-qemu"><code>Kernel</code> and <code>initrd</code></a>.</p> <h2><a class="header" href="#references" id="references">References</a></h2> <ul> <li><a href="https://github.com/qemu/qemu/blob/master/docs/usb2.txt">QEMU USB</a></li> -<li><a href="https://qemu.readthedocs.io/en/latest/tools/qemu-img.html">QEMU IMG</a></li> -<li><a href="https://qemu.readthedocs.io/en/latest/tools/index.html">QEMU Tools</a></li> -<li><a href="https://www.qemu.org/docs/master/system/index.html">QEMU System</a></li> +<li><a href="https://qemu-project.gitlab.io/qemu/tools/qemu-img.html">QEMU IMG</a></li> +<li><a href="https://qemu-project.gitlab.io/qemu/tools/index.html">QEMU Tools</a></li> +<li><a href="https://qemu-project.gitlab.io/qemu/system/index.html">QEMU System</a></li> +<li><a href="https://qemu-project.gitlab.io/qemu/system/invocation.html">QEMU Invocation (command line args)</a></li> </ul> </main> |