crosvm/tools/examples/example_network
Yuanchu Xie 4071d1ef5e examples: use rwdisk instead of rwroot
rwroot automatically adds root=/dev/vd[a-z], but the example image
actually uses /dev/vda5. This leads to confusion when two root= kernel
command line arguments are passed in and only one of them works.

Therefore we use rwdisk instead which doesn't add the kernel argument.

BUG=b:236198584
TEST=mdbook builds, examples build and run

Change-Id: I9bfc05445b1e2aef197a43ee647d7c784d50dad7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708365
Commit-Queue: Yuanchu Xie <yuanchu@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-17 17:43:41 +00:00

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 \
--rwdisk ./rootfs \
--initrd ./initrd.img-* \
--tap-name crosvm_tap \
-p "root=/dev/vda5" \
./vmlinuz-*
# ANCHOR_END: run