### Run Crosvm Example Script (Network) Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Execute the network example script directly. This script automates the setup of networking and launching a VM with network capabilities. ```bash ./tools/examples/example_network ``` -------------------------------- ### Run Crosvm Example Script (Desktop) Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Execute the desktop example script directly. This script automates the setup for running a VM with a graphical user interface. ```bash ./tools/examples/example_desktop ``` -------------------------------- ### Run VM with Balloon Socket Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/balloon.md Start a virtual machine and specify the VM socket for balloon device control. This is the initial setup step. ```sh crosvm run \ -s ${CROSVM_SOCKET} \ # usual crosvm args /path/to/bzImage ``` -------------------------------- ### Build and Install Sommelier Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/wayland.md Compile the sommelier Wayland proxy and install it to the guest system. The binary will be placed in /usr/local/bin. ```bash meson compile -C build sudo meson install -C build ``` -------------------------------- ### Install and Build Libvda Source: https://github.com/crosvm/crosvm/blob/main/media/libvda/README.md Installs the libvda.so library to the host environment and then builds the Rust crate using cargo. ```shell (chroot)$ sudo emerge chromeos-base/libvda # Install libvda.so to host. # Build (chroot)$ cargo build # Unit tests (chroot)$ cargo test ``` -------------------------------- ### Install Development Packages on Debian/Ubuntu Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Run the setup script to install necessary packages for crosvm development on Debian derivatives like Ubuntu or gLinux. ```sh ./tools/setup ``` -------------------------------- ### Run VM with PCI Hotplug Slots and Control Socket Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/index.md Start a VM with a specified number of PCI hotplug slots and a control socket for sending hotplug commands. This example demonstrates the command-line arguments required. ```sh VM_SOCKET=/run/crosvm.socket crosvm run \ -s ${VM_SOCKET} \ --pci-hotplug-slots 3 # usual crosvm args ``` -------------------------------- ### Install QEMU and Upload Prebuilts Source: https://github.com/crosvm/crosvm/blob/main/e2e_tests/README.md Prepare the environment for building and uploading aarch64 images by installing QEMU-user-static and registering binfmt_misc entries. Then, execute the script to build and upload new prebuilt artifacts. ```sh # Install QEMU-user-static to build aarch64 images $ sudo apt install binfmt-support qemu-user-static # Register binfmt_misc entries $ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # Build and upload the new artifacts $ ./guest_under_test/upload_prebuilts.sh ``` -------------------------------- ### Run Crosvm Example Script (Simple Guest) Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Execute the simple guest OS example script directly. This script automates the process of building, extracting, and running a basic VM. ```bash ./tools/examples/example_simple ``` -------------------------------- ### Example Key-Value String Source: https://github.com/crosvm/crosvm/blob/main/serde_keyvalue/README.md Demonstrates a common format for command-line parameters that this crate can deserialize. ```text --foo type=bar,active,nb_threads=8 ``` -------------------------------- ### Install Crosvm Architecture Packages Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Installs the necessary packages for aarch64 and riscv64 architectures using provided setup scripts. ```sh ./tools/setup-aarch64 ``` ```sh ./tools/setup-riscv64 ``` -------------------------------- ### Prepare for Building Crosvm on the Host Source: https://github.com/crosvm/crosvm/blob/main/infra/README.recipes.md Use this context manager to prepare the host system for building crosvm. It installs the required Rust version via rustup but does not install other dependencies. ```python with api.crosvm.host_build_context(): api.step("build crosvm", ["cargo build"]) ``` -------------------------------- ### Setup Sommelier Build with Meson Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/wayland.md Configure the sommelier build using meson, disabling tests. This step verifies required libraries. ```bash cd platform2/vm_tools/sommelier/ meson setup build -Dwith_tests=false ``` -------------------------------- ### Build VM Image with ncat Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/vsock.md Build a VM image with ncat installed, which is required for vsock communication examples. This command creates a simple Ubuntu image and adds a user. ```sh virt-builder ubuntu-20.04 \ --run-command "useradd -m -g sudo -p '' $USER ; chage -d 0 $USER" \ -o ./rootfs \ --install ncat ``` -------------------------------- ### Start Development Container Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Launch the development container, which includes pre-installed packages and tools for crosvm development. ```sh ./tools/dev_container ``` -------------------------------- ### Create and Inspect ext2 File System Source: https://github.com/crosvm/crosvm/blob/main/ext2/README.md Demonstrates creating an ext2 file system image using the `mkfs.rs` example and then inspecting it with `dumpe2fs`. This is useful for debugging the ext2 crate itself. ```console $ cargo run --release --example mkfs -- --path disk.img Create disk.img $ dumpe2fs disk.img dumpe2fs 1.47.0 (5-Feb-2023) Filesystem volume name: Last mounted on: Filesystem UUID: c6e49d8f-106f-4472-b0e8-6babcc3fa496 Filesystem magic number: 0xEF53 ... ``` -------------------------------- ### Install Passt for Podman Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Install the 'passt' package, which is required for Podman to access KVM from within the development container. ```sh sudo apt install passt ``` -------------------------------- ### Install Crosvm Dependencies Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/windows.md Installs necessary tools and sets up environment variables for building crosvm on Windows. May prompt for Visual Studio Community Edition installation. ```powershell Set-ExecutionPolicy Unrestricted -Scope CurrentUser ./tools/install-deps.ps1 ``` -------------------------------- ### Custom Multitouchscreen Configuration Example Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/input.md A portion of an example JSON configuration file for a custom multitouchscreen input device. This configures supported events, device name, serial, properties, and axis information. ```json { "events": { "touch": { "type": "multitouch", "max_touches": 10 } }, "name": "my-custom-multitouch", "serial": "my-custom-serial-123", "properties": { "touch_screen": true, "pointer": false }, "axis_info": { "x": { "min": 0, "max": 1920 }, "y": { "min": 0, "max": 1080 } } } ``` -------------------------------- ### Create and Mount Rootfs Disk Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/custom_kernel_rootfs.md Create a 20GB ext4 disk image, mount it, and use debootstrap to install a Debian stable rootfs. Ensure `$CHROOT_PATH` is defined. ```bash truncate -s 20G debian.ext4 mkfs.ext4 debian.ext4 mkdir -p "${CHROOT_PATH}" sudo mount debian.ext4 "${CHROOT_PATH}" sudo debootstrap stable "${CHROOT_PATH}" http://deb.debian.org/debian/ ``` -------------------------------- ### Start Vhost-User Block Backend Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/vhost_user.md Starts the vhost-user block backend, which listens for connections from a VMM process on the specified socket path. The backend will expose the provided disk image. ```sh VHOST_USER_SOCK=/tmp/vhost-user.socket # Start vhost-user block backend listening on $VHOST_USER_SOCK crosvm devices --block vhost=${VHOST_USER_SOCK},path=disk.img ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/crosvm/crosvm/blob/main/tools/contrib/memstats_chart/README.md Installs necessary Python libraries for data visualization using pip. ```sh pip install -r ./requirements.txt ``` -------------------------------- ### Install Msys2 Packages on Windows Source: https://github.com/crosvm/crosvm/blob/main/third_party/libslirp-rs/README.md Installs necessary packages for building libslirp on Windows using Msys2. Ensure Msys2's bin directory is in your PATH. ```sh pacman -S mingw-w64-x86_64-meson ninja git mingw-w64-x86_64-gcc mingw-w64-x86_64-glib2 mingw-w64-x86_64-pkg-config ``` -------------------------------- ### Install MinGW64 and Wine Dependencies Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Installs dependencies required for limited testing of crosvm on Windows using mingw64 and wine on Linux. ```sh ./tools/setup-mingw64 ``` -------------------------------- ### Start Crosvm Package with Cros Workon Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/integration/chromeos.md Use this command to start the crosvm package for development within a ChromeOS chroot environment. ```bash (chroot)$ cros_workon --board=${BOARD} start chromeos-base/crosvm ``` -------------------------------- ### x86_64 Common Device Policy Example Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/appendix/seccomp.md An example of the common device seccomp policy for the x86_64 architecture. Each line specifies a syscall and a boolean expression to control its usage. ```policy accept4: 1 accept: 1 access: 1 adjtimex: 1 ``` -------------------------------- ### Start crosvm with Control Socket Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/usb.md Start the crosvm process with a control socket enabled to allow runtime device management. This is a prerequisite for attaching USB devices. ```shell $ crosvm run -s /run/crosvm.sock ${USUAL_CROSVM_ARGS} ``` -------------------------------- ### Install Crun Runtime for Podman Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Install the 'crun' runtime for Podman. This is necessary to preserve user's supplemental groups when accessing KVM from the development container on Linux systems. ```sh sudo apt install crun ``` -------------------------------- ### Basic SCSI Block Device Setup Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/scsi.md Exposes a disk image as a SCSI block device (e.g., /dev/sda). This is the fundamental way to attach a disk image via SCSI. ```sh crosvm run \ --scsi-block disk.img ... # usual crosvm args ``` -------------------------------- ### Run Local Webserver for Flamegraph Source: https://github.com/crosvm/crosvm/blob/main/tools/contrib/cros_tracing_analyser/README.md Starts a simple Python HTTP server to host the flamegraph visualization. Access the flamegraph at http://localhost:8000/flamegraph.html. ```bash python3 -m http.server ``` -------------------------------- ### Example VirtioFS trace events Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/tracing.md Sample output showing virtiofs tracing events captured from the trace_pipe. These events indicate operations like entering and exiting the 'release' context. ```text <...>-3802142 [011] ..... 2179601.746212: tracing_mark_write: fuse server: handle_message: in_header=InHeader { len: 64, opcode: 18, unique: 814, nodeid: 42, uid: 0, gid: 0, pid: 0, padding: 0 } <...>-3802142 [011] ..... 2179601.746226: tracing_mark_write: 503 VirtioFs Enter: release - (self.tag: "mtdroot")(inode: 42)(handle: 35) <...>-3802142 [011] ..... 2179601.746244: tracing_mark_write: 503 VirtioFs Exit: release ``` -------------------------------- ### Start VMM with Vhost-User Block Frontend Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/vhost_user.md Launches a VMM process that connects to the vhost-user block backend via the specified socket. This exposes the disk image to the guest OS as a block device. ```sh crosvm run \ --vhost-user block,socket="${VHOST_USER_SOCK}" \ \ /path/to/bzImage ``` -------------------------------- ### Prepare for Building Crosvm in a Dev Container Source: https://github.com/crosvm/crosvm/blob/main/infra/README.recipes.md Use this context manager to set up the environment for building crosvm within a development container. It handles source preparation and system setup. ```python with api.crosvm.container_build_context(): api.crosvm.step_in_container("build crosvm", ["cargo build"]) ``` -------------------------------- ### SCSI Root Filesystem Setup Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/scsi.md Configures a SCSI block device to be used as the guest's root filesystem. This automatically sets the kernel parameter 'root=/dev/sdX' and applies 'ro' or 'rw' based on other flags. ```sh crosvm run \ --scsi-block disk.img,root ... # usual crosvm args ``` -------------------------------- ### Run Xeyes via Sommelier with Xwayland Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/wayland.md Launch the xeyes X application through sommelier, utilizing Xwayland for compatibility. Ensure Xwayland is installed in the guest. ```bash sommelier -X --xwayland-path=/usr/bin/Xwayland xeyes ``` -------------------------------- ### Start Crosvm with TAP Network Device Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/net.md Command to launch Crosvm, specifying the pre-configured TAP interface to be used for the guest's network. ```sh crosvm run \ ... \ --net tap-name=crosvm_tap \ ... ``` -------------------------------- ### Run Crosvm with Video Decoder Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/video.md Starts crosvm with the video decoder device enabled using the FFmpeg backend. Requires a compatible guest kernel. ```bash crosvm run --disable-sandbox --video-decoder=ffmpeg -c 4 -m 2048 --block /path/to/disk.img,root --serial type=stdout,hardware=virtio-console,console=true,stdin=true /path/to/bzImage ``` -------------------------------- ### Listen on Host Vsock Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/vsock.md Start listening on a specific port using ncat on the host's vsock device. This prepares the host to receive connections from the guest. ```sh PORT=11111 # Listen at host ncat -l --vsock ${PORT} ``` -------------------------------- ### Boot a Kernel Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/advanced_usage.md Run a basic virtual machine with a kernel and default devices. Ensure KERNEL_PATH points to your compressed kernel image (e.g., bzImage). ```sh crosvm run "${KERNEL_PATH}" ``` -------------------------------- ### Build VM Image with Netplan Configuration Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Build the VM image including the netplan configuration for static IP assignment. This ensures the guest VM has network connectivity upon boot. ```bash virt-builder ubuntu-22.04 --size 20G --format qcow2 --output ubuntu-22.04.qcow2 --run-command 'cp /guest/01-netcfg.yaml /etc/netplan/01-netcfg.yaml' ``` -------------------------------- ### Launch Build with JSON Input Source: https://github.com/crosvm/crosvm/blob/main/infra/README.md Use this command to launch a build, providing a `job.json` file as input. Ensure the JSON file is correctly piped to `led launch`. ```shell led launch < job.json ``` -------------------------------- ### Install Matplotlib for Python Source: https://github.com/crosvm/crosvm/blob/main/tools/contrib/cros_tracing_analyser/README.md Installs the matplotlib Python library, which is required for generating histogram plots from the generated JSON data. ```bash sudo apt-get install python3-matplotlib ``` -------------------------------- ### Enable virtio-pmem and Share Host Directory Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/pmem/pmem_ext2.md Use the `--pmem-ext2` flag with the path to the host directory to enable sharing. The actual file data is read from disk only when accessed by the guest. ```console mkdir host_shared_dir HOST_SHARED_DIR=$(pwd)/host_shared_dir echo "Hello!" > $HOST_SHARED_DIR/test.txt crosvm run \ --pmem-ext2 "$HOST_SHARED_DIR" \ # usual crosvm args ``` -------------------------------- ### Run VM with Disk Image as Rootfs (Read-Only) Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/advanced_usage.md Boot a VM using a disk image as the root filesystem. The 'root' flag designates it as the primary root, and 'ro' makes it read-only for the guest. The image must be formatted for kernel readability (e.g., squashfs, ext4). ```sh crosvm run -b "${ROOT_IMAGE},root,ro" "${KERNEL_PATH}" ``` -------------------------------- ### Clean Development Container Artifacts Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Start the development container with the '--clean' flag to remove existing container and build artifacts and start fresh. ```sh ./tools/dev_container --clean ``` -------------------------------- ### Create and Format a Disk Image Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/block.md Use `fallocate` to create a disk image file and `mkfs.ext4` to format it with the ext4 filesystem. ```sh fallocate -l 1G disk.img mkfs.ext4 disk.img ``` -------------------------------- ### Example Good Commit Message Source: https://github.com/crosvm/crosvm/blob/main/CONTRIBUTING.md An example of a well-formatted commit message following crosvm's guidelines, including a subject, body, BUG, TEST, and Change-Id. ```text devices: vhost: user: vmm: Add Connection type This abstracts away the cross-platform differences: cfg(any(target_os = "android", target_os = "linux")) uses a Unix domain domain stream socket to connect to the vhost-user backend, and cfg(windows) uses a Tube. BUG=b:249361790 TEST=tools/presubmit --all Change-Id: I47651060c2ce3a7e9f850b7ed9af8bd035f82de6 ``` -------------------------------- ### Install Gerrit Commit Message Hook Source: https://github.com/crosvm/crosvm/blob/main/CONTRIBUTING.md Installs the gerrit commit message hook to automatically add a 'Change-Id' to commit messages, which is required for Gerrit to track changes. ```bash ./tools/cl install ``` -------------------------------- ### Crosvm Block Option Example Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/options.md An example of invoking the `--block` option with explicit key-value pairs. The `path` is required, while others like `root` and `block-size` are optional. ```sh --block path=/path/to/bzImage,root=true,block-size=4096 ``` -------------------------------- ### Create Netplan Configuration for Guest Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Create a netplan configuration file within the guest VM to assign a static IP address. This enables network access from the host to the guest. ```bash mkdir guest/ touch guest/01-netcfg.yaml ``` -------------------------------- ### Run VM with Disk Image as Rootfs (Writable) Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/advanced_usage.md Boot a VM using a disk image as a writable root filesystem. Remove the 'ro' flag from the read-only configuration. Be aware of potential corruption risks with writable disks. ```sh crosvm run -b "${ROOT_IMAGE},root" "${KERNEL_PATH}" ``` -------------------------------- ### Launch a Simple VM with Crosvm Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Launch a virtual machine using crosvm with the prepared kernel and rootfs. The VM will use the host's username and prompt for a password on first login. ```bash crosvm run --kernel kernel --mem 1G --disk ubuntu-22.04.qcow2 ``` -------------------------------- ### Edit and Launch Build Recipe Source: https://github.com/crosvm/crosvm/blob/main/infra/README.md This snippet demonstrates how to override a build recipe and its parameters using `led edit`. It first fetches a builder, then edits the recipe and parameters, and finally launches the modified build. ```shell led get-builder luci.crosvm.ci:linux_x86_64 | led edit -r new_recipe -p new_recipe_parameters=value | led edit-recipe-bundle | led launch ``` -------------------------------- ### Build Crosvm Documentation Locally Source: https://github.com/crosvm/crosvm/blob/main/CONTRIBUTING.md Navigate to the docs/book directory and run the mdbook build command to render the documentation locally. The output will be available in docs/book/book/html/. ```shell cd docs/book/ mdbook build ``` -------------------------------- ### Build VM Image with Desktop Environment Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Prepare a VM image that includes a desktop environment. This is a prerequisite for enabling GUI support in crosvm. ```bash virt-builder ubuntu-22.04 --size 20G --format qcow2 --output ubuntu-22.04.qcow2 --install 'xorg,ubuntu-desktop' ``` -------------------------------- ### Launch Post-Submit Build with Local Recipes Source: https://github.com/crosvm/crosvm/blob/main/infra/README.md Test local recipe changes on a post-submit builder by launching a build using 'led'. This command uses the current 'main' revision of crosvm with your local recipe changes. ```shell led get-builder luci.crosvm.ci:linux_x86_64 \ | led edit-recipe-bundle \ | led launch ``` -------------------------------- ### Inspect CBOR Snapshot Files with cbor-cli Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/architecture/snapshotting.md Use the `cbor-cli` tool to inspect CBOR encoded snapshot files by exporting them to JSON format. Ensure `cbor-cli` is installed via `cargo install cbor-cli`. ```bash $ cbor export --format=json /tmp/crosvm-snapshot/irqchip | jq { "mp_state": [ "Halted", "Halted", "Halted", "Halted" ], "pit_state": { ... ``` -------------------------------- ### Launch VM with GUI Support (Virglrenderer) Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Launch crosvm with GUI support using the virglrenderer backend. This directs the VM's GPU output to an X11 window on the host. ```bash crosvm run --kernel kernel --mem 2G --disk ubuntu-22.04.qcow2 --gpu display=on,backend=virgl ``` -------------------------------- ### Build libslirp on Windows Source: https://github.com/crosvm/crosvm/blob/main/third_party/libslirp-rs/README.md Clones the libslirp repository, configures the build using Meson, and compiles the library. The built library will be placed in the 'build' directory. ```sh git clone https://gitlab.freedesktop.org/slirp/libslirp.git cd libslirp meson build ninja -C build ``` -------------------------------- ### Create New Feature Branch Source: https://github.com/crosvm/crosvm/blob/main/CONTRIBUTING.md Starts work on a new feature by creating a new branch that tracks the 'origin/main' branch. ```bash git checkout -b myfeature --track origin/main ``` -------------------------------- ### Build Guest OS Image with virt-builder Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Use virt-builder to prepare a customized VM image for use with crosvm. This is a prerequisite for running a guest OS. ```bash virt-builder ubuntu-22.04 --size 20G --format qcow2 --output ubuntu-22.04.qcow2 ``` -------------------------------- ### Monitor Syslog in Test VM Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/testing/index.md Start printing syslog messages in real-time within the test VM to monitor system activity. ```console crosvm@testvm-x8664:~$ journalctl -f ``` -------------------------------- ### Extract Kernel and Initrd from VM Image Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Extract the kernel and initrd binaries from the prepared VM image. Crosvm boots directly from the kernel. ```bash virt-extract-kernel ubuntu-22.04.qcow2 kernel ``` -------------------------------- ### Get Video Decoder Info Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/video.md Uses v4l2-ctl to display information about the virtio video decoder device, including driver and capabilities. ```bash v4l2-ctl -d/dev/video0 --info ``` -------------------------------- ### Emerge Crosvm Package Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/integration/chromeos.md Installs the crosvm package on a ChromeOS chroot using emerge. The -j flag specifies the number of parallel jobs. ```bash (chroot)$ emerge-${BOARD} chromeos-base/crosvm -j 10 ``` -------------------------------- ### List HID Raw Devices in Guest Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/virtual_u2f.md Confirm that the correct hidraw device has been created within the guest's `/dev/` tree. ```shell $ ls /dev/hidraw* /dev/hidraw0 ``` -------------------------------- ### Launch VM with Network Support Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Launch crosvm with network support enabled, utilizing the pre-configured TAP device. This allows the VM to access the network. ```bash crosvm run --kernel kernel --mem 1G --disk ubuntu-22.04.qcow2 --tap crosvm_tap ``` -------------------------------- ### Get Balloon Statistics Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/balloon.md Retrieve the current balloon size statistics for the guest VM. This command helps confirm the balloon's status. ```sh crosvm balloon_stats ${CROSVM_SOCKET} ``` -------------------------------- ### Mount virtio-pmem Device in Guest Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/pmem/pmem_ext2.md Mount the ext2 filesystem from the guest using `mount -t ext2`. The `-o dax` option avoids duplicated page caches between the guest and the host. ```console mkdir /tmp/shared mount -t ext2 -o dax /dev/pmem0 /tmp/shared ls /tmp/shared cat /tmp/shared/test.txt ``` -------------------------------- ### Run Crosvm with Video Encoder Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/video.md Starts crosvm with the video encoder device enabled using the FFmpeg backend. Requires a compatible guest kernel. ```bash crosvm run --disable-sandbox --video-encoder=ffmpeg -c 4 -m 2048 --block /path/to/disk.img,root --serial type=stdout,hardware=virtio-console,console=true,stdin=true /path/to/bzImage ``` -------------------------------- ### Enter Dev Container and Test VM Shell Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/testing/index.md Enter the development container and then the test VM's shell to access its file system and run commands. ```console $ ./tools/dev_container $ ./tools/x86vm shell ``` -------------------------------- ### List Cros Tracing Event Names Source: https://github.com/crosvm/crosvm/blob/main/tools/contrib/cros_tracing_analyser/README.md Lists function names and the sum of their latencies from a trace.dat file. Use this to get an overview of the most time-consuming events. ```bash cargo run -- list --input trace.dat --count 10 ``` -------------------------------- ### Enable host tracing Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/tracing.md Enable tracing on the host system using trace-cmd or by manually writing to the tracing_on file. ```sh sudo echo 1 > /sys/kernel/tracing/tracing_on ``` -------------------------------- ### Rebuild Base Dev Container Image Source: https://github.com/crosvm/crosvm/blob/main/tools/impl/dev_container/README.md Rebuilds the `crosvm_dev_base` image. This is typically done after modifying debian package installation scripts or updating the `base_version` file. ```bash make -C tools/impl/dev_container crosvm_dev_base ``` -------------------------------- ### Generate Perfetto Rust Bindings Source: https://github.com/crosvm/crosvm/blob/main/perfetto/README.md Use this command to generate Rust bindings from the Perfetto C API header. Ensure you are in the crosvm directory and have bindgen installed. ```bash $ bindgen third_party/perfetto/include/perfetto/tracing/ctrace.h --disable-header-comment --no-layout-tests --no-doc-comments --with-derive-default --size_t-is-usize -o ./perfetto/src/bindings.rs ``` -------------------------------- ### Create /var/empty Directory Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Workaround for known issue: Creates the /var/empty directory, which is required for devices to be jailed. ```sh sudo mkdir -p /var/empty ``` -------------------------------- ### List USB Devices in Guest Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/virtual_u2f.md Verify that the virtual U2F device has appeared inside the guest VM with the expected Product and Vendor IDs (18d1:f1d0). ```shell $ lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 002: ID 18d1:f1d0 Google Inc. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub ``` -------------------------------- ### Execute Command within Development Container Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/building_crosvm/linux.md Run a specific command, such as 'cargo build', directly within the development container without starting an interactive shell. ```sh ./tools/dev_container cargo build ``` -------------------------------- ### Build Guest Kernel Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/video.md Builds the virtio_video kernel configuration and compiles the kernel image for use with crosvm. ```bash mkdir build_crosvm_x86 make O=build_crosvm_x86 virtio_video_defconfig make O=build_crosvm_x86 -j16 ``` -------------------------------- ### Build Release Version of crosvm Source: https://github.com/crosvm/crosvm/blob/main/README.md Builds a release version of crosvm using the development container. Ensure you have Podman or Docker installed and a Linux environment with KVM access. ```bash ./tools/dev_container ./tools/build_release ``` -------------------------------- ### Build Cargo in All Containers Source: https://github.com/crosvm/crosvm/blob/main/tools/contrib/minimal_containers/README.md Run 'cargo build' command in all available minimal containers. ```bash ./test-all.sh ``` -------------------------------- ### Configure Network with TAP Device Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Set up a TAP device and routing for network connectivity in the VM. This script creates a 'crosvm_tap' device. ```bash ./tools/examples/setup_network ``` -------------------------------- ### Authenticate Docker for Google Container Registry Source: https://github.com/crosvm/crosvm/blob/main/tools/impl/dev_container/README.md Configures Docker to authenticate with `gcr.io`, which is necessary for uploading container images. This command requires Google Cloud SDK to be installed and configured. ```bash gcloud auth configure-docker gcr.io ``` -------------------------------- ### Configure Keyboard Input Device Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/input.md Adds a keyboard virtio-input device. Requires the path to the event source socket. ```sh crosvm run \ --input keyboard[path=/tmp/keyboard-socket] \ ... ``` -------------------------------- ### Configure Block Device as Root Filesystem Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/block.md Use the `root` flag with the `--block` parameter to designate the disk image as the guest's root filesystem. This automatically adds the appropriate kernel parameter. ```sh crosvm run \ --block disk.img,root ... # usual crosvm args ``` -------------------------------- ### Configure and Build Kernel Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/custom_kernel_rootfs.md Prepare the kernel configuration for a container VM and build the bzImage. The `CHROMEOS_KERNEL_FAMILY` environment variable is used for specific configurations. ```bash cd kernel CHROMEOS_KERNEL_FAMILY=termina ./chromeos/scripts/prepareconfig container-vm-x86_64 make olddefconfig make -j$(nproc) bzImage ``` -------------------------------- ### Create and Configure Host TAP Interface Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/net.md Creates a TAP interface named 'crosvm_tap', assigns an IP address, and brings the interface up. This is the initial step for providing network access to a guest. ```sh sudo ip tuntap add mode tap user $USER vnet_hdr crosvm_tap sudo ip addr add 192.168.10.1/24 dev crosvm_tap sudo ip link set crosvm_tap up ``` -------------------------------- ### SSH into Guest VM Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/example_usage.md Access the guest VM via SSH using its assigned static IP address. Passwordless SSH is enabled if your public SSH key is installed in the VM. ```bash ssh 192.168.10.2 ``` -------------------------------- ### Run Virtqueue Fuzzer Locally Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/testing/fuzzing.md Execute the virtqueue_fuzzer with randomly generated inputs. This command runs indefinitely and can be stopped with Ctrl+C. Ensure 'cargo fuzz' is installed and you are in the crosvm source tree. ```sh cargo +nightly fuzz run virtqueue_fuzzer ``` -------------------------------- ### Enable GDB Debugging for Guest Kernel Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/running_crosvm/advanced_usage.md Start crosvm with GDB remote protocol support enabled using the '--gdb ' flag. This allows debugging the guest kernel on x86_64 or AArch64 architectures. ```sh crosvm run --gdb ${USUAL_CROSVM_ARGS} vmlinux ``` -------------------------------- ### Configure Evdev Input Device Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/input.md Adds an evdev input device to the VM, grabbing the specified event device node from the host. Requires the path to the evdev device. ```sh crosvm run \ --input evdev[path=/dev/input/event0] \ ... ``` -------------------------------- ### Decode H.264 Stream with v4l2r Source: https://github.com/crosvm/crosvm/blob/main/docs/book/src/devices/video.md Clone the v4l2r Rust crate, download an H.264 stream, and use its example program to decode the stream into NV12 format frames. This requires specifying the input format and output file. ```sh git clone https://github.com/Gnurou/v4l2r cd v4l2r wget https://github.com/chromium/chromium/raw/main/media/test/data/test-25fps.h264 cargo run --example simple_decoder test-25fps.h264 /dev/video0 --input_format h264 --save test-25fps.nv12 ```