• 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 a full desktop
7
8set -e
9
10SRC=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
11mkdir -p "$SRC/images/desktop" && 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. See ./example_network
20        --hostname crosvm-test
21        --copy-in "$SRC/guest/01-netcfg.yaml:/etc/netplan/"
22
23        # Install a desktop environment to launch
24        --install xfce4
25
26        -o rootfs
27    )
28    virt-builder ubuntu-20.04 "${builder_args[@]}"
29    # ANCHOR_END: build
30
31    virt-builder --get-kernel ./rootfs -o .
32fi
33
34# ANCHOR: run
35# Enable the GPU and keyboard/mouse input. Since this will be a much heavier
36# system to run we also need to increase the cpu/memory given to the VM.
37# Note: GDM does not allow you to set your password on first login, you have to
38#       log in on the command line first to set a password.
39cargo run --features=gpu,x,virgl_renderer -- run \
40    --cpus 4 \
41    --mem 4096 \
42    --disable-sandbox \
43    --gpu backend=virglrenderer,width=1920,height=1080 \
44    --display-window-keyboard \
45    --display-window-mouse \
46    --tap-name crosvm_tap \
47    --rwroot ./rootfs \
48    --initrd ./initrd.img-* \
49    -p "root=/dev/vda5" \
50    ./vmlinuz-*
51# ANCHOR_END: run
52