mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 10:32:10 +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>
44 lines
1.2 KiB
Bash
Executable file
44 lines
1.2 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 internet access and sshd
|
|
|
|
set -e
|
|
|
|
SRC=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
|
mkdir -p "$SRC/images/network" && cd "$_"
|
|
|
|
if ! [ -f rootfs ]; then
|
|
# ANCHOR: build
|
|
builder_args=(
|
|
# Create user with no password.
|
|
--run-command "useradd -m -g sudo -p '' $USER ; chage -d 0 $USER"
|
|
|
|
# Configure network via netplan config in 01-netcfg.yaml
|
|
--hostname crosvm-test
|
|
--copy-in "$SRC/guest/01-netcfg.yaml:/etc/netplan/"
|
|
|
|
# Install sshd and authorized key for the user.
|
|
--install openssh-server
|
|
--ssh-inject "$USER:file:$HOME/.ssh/id_rsa.pub"
|
|
|
|
-o rootfs
|
|
)
|
|
virt-builder ubuntu-20.04 "${builder_args[@]}"
|
|
# ANCHOR_END: build
|
|
|
|
virt-builder --get-kernel ./rootfs -o .
|
|
fi
|
|
|
|
# ANCHOR: run
|
|
# Use the previously configured crosvm_tap device for networking.
|
|
cargo run -- run \
|
|
--disable-sandbox \
|
|
--rwroot ./rootfs \
|
|
--initrd ./initrd.img-* \
|
|
--tap-name crosvm_tap \
|
|
-p "root=/dev/vda5" \
|
|
./vmlinuz-*
|
|
# ANCHOR_END: run
|