xref: /aosp_15_r20/external/crosvm/tools/examples/example_desktop (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1#!/bin/bash
2# Copyright 2022 The ChromiumOS Authors
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
10sudo mkdir -p /var/empty
11SRC=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
12mkdir -p "$SRC/images/desktop" && cd "$_"
13
14if ! [ -f rootfs ]; then
15    # ANCHOR: build
16    builder_args=(
17        # Create user with no password.
18        --run-command "useradd -m -g sudo -p '' $USER ; chage -d 0 $USER"
19
20        # Configure network. See ./example_network
21        --hostname crosvm-test
22        --copy-in "$SRC/guest/01-netcfg.yaml:/etc/netplan/"
23
24        # Install a desktop environment to launch
25        --install xfce4
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# Enable the GPU and keyboard/mouse input. Since this will be a much heavier
37# system to run we also need to increase the cpu/memory given to the VM.
38# Note: GDM does not allow you to set your password on first login, you have to
39#       log in on the command line first to set a password.
40cargo run --features=gpu,x,virgl_renderer -- run \
41    --cpus 4 \
42    --mem 4096 \
43    --gpu backend=virglrenderer,width=1920,height=1080 \
44    --display-window-keyboard \
45    --display-window-mouse \
46    --net tap-name=crosvm_tap \
47    --rwdisk ./rootfs \
48    --initrd ./initrd.img-* \
49    -p "root=/dev/vda5" \
50    ./vmlinuz-*
51# ANCHOR_END: run
52