mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 02:25:23 +00:00
Two examples are added. A simple one and one with network configured. The examples are written in a way they can be integrated with the mdbook to form a tutorial. This will ensure the tutorial code snippets stay up to date. The documentation for networking is added after https://crrev.com/c/3237468 is merged. BUG=b:214104901 TEST=./tools/examples/example_simple Change-Id: I33682878858d8a0324fbb6a87e33cd55b29811b7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3388063 Reviewed-by: Alexandre Courbot <acourbot@chromium.org> Commit-Queue: Dennis Kempin <denniskempin@google.com> Tested-by: Dennis Kempin <denniskempin@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
36 lines
1.1 KiB
Bash
Executable file
36 lines
1.1 KiB
Bash
Executable file
#!/bin/bash
|
|
# Copyright 2022 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
# Example VM with a simple ubuntu guest OS but no UI, audio or networking.
|
|
|
|
set -e
|
|
|
|
SRC=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
|
mkdir -p "$SRC/images/simple" && cd "$_"
|
|
|
|
if ! [ -f rootfs ]; then
|
|
# ANCHOR: build
|
|
# Build a simple ubuntu image and create a user with no password.
|
|
virt-builder ubuntu-20.04 \
|
|
--run-command "useradd -m -g sudo -p '' $USER ; chage -d 0 $USER" \
|
|
-o ./rootfs
|
|
# ANCHOR_END: build
|
|
|
|
# ANCHOR: kernel
|
|
virt-builder --get-kernel ./rootfs -o .
|
|
# ANCHOR_END: kernel
|
|
fi
|
|
|
|
# ANCHOR: run
|
|
# Run crosvm without sandboxing.
|
|
# The rootfs is an image of a partitioned hard drive, so we need to tell
|
|
# the kernel which partition to use (vda5 in case of ubuntu-20.04).
|
|
cargo run --features=all-linux -- run \
|
|
--disable-sandbox \
|
|
--rwroot ./rootfs \
|
|
--initrd ./initrd.img-* \
|
|
-p "root=/dev/vda5" \
|
|
./vmlinuz-*
|
|
# ANCHOR_END: run
|