• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2022 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# Example VM with internet access and sshd
7
8set -e
9
10SRC=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
11mkdir -p "$SRC/images/network" && cd "$_"
12
13if ! [ -f rootfs ]; then
14    # ANCHOR: build
15    builder_args=(
16        # Create user with no password.
17        --run-command "useradd -m -g sudo -p '' $USER ; chage -d 0 $USER"
18
19        # Configure network via netplan config in 01-netcfg.yaml
20        --hostname crosvm-test
21        --copy-in "$SRC/guest/01-netcfg.yaml:/etc/netplan/"
22
23        # Install sshd and authorized key for the user.
24        --install openssh-server
25        --ssh-inject "$USER:file:$HOME/.ssh/id_rsa.pub"
26
27        -o rootfs
28    )
29    virt-builder ubuntu-20.04 "${builder_args[@]}"
30    # ANCHOR_END: build
31
32    virt-builder --get-kernel ./rootfs -o .
33fi
34
35# ANCHOR: run
36# Use the previously configured crosvm_tap device for networking.
37cargo run -- run \
38    --disable-sandbox \
39    --rwroot ./rootfs \
40    --initrd ./initrd.img-* \
41    --tap-name crosvm_tap \
42    -p "root=/dev/vda5" \
43    ./vmlinuz-*
44# ANCHOR_END: run
45