crosvm/tools/examples/example_network
Elie Kheirallah 1a41931529 tools: examples: network - uncomment RSA and add info
Uncommented the line that injetcs the RSA key to allow for SSH
connections to the VM without initial login.
Add more information that if the file is missing, an initial login to
change passwords is required.

BUG=N/A
TEST=mdbook build

Change-Id: Ie0f94da693e04319b7b098df8bfe044ceeeeb8a9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4698613
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-07-18 22:52:06 +00:00

52 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# Copyright 2022 The ChromiumOS Authors
# 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
sudo mkdir -p /var/empty
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
# $SRC=/path/to/crosvm
--copy-in "$SRC/guest/01-netcfg.yaml:/etc/netplan/"
# Install sshd.
--install openssh-server
-o rootfs
)
# Inject authorized key for the user.
# If the SSH RSA public key file is missing, you will need to login to
# the VM the first time and change passwords before you can login via SSH.
ID_RSA_PUB="$HOME/.ssh/id_rsa.pub"
if [ -r "${ID_RSA_PUB}" ]; then
builder_args+=("--ssh-inject" "${USER}:file:${ID_RSA_PUB}")
fi
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 \
--rwdisk ./rootfs \
--initrd ./initrd.img-* \
--net tap-name=crosvm_tap \
-p "root=/dev/vda5" \
./vmlinuz-*
# ANCHOR_END: run