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 simple ubuntu guest OS but no UI, audio or networking. 7 8set -e 9 10SRC=$(realpath "$(dirname "${BASH_SOURCE[0]}")") 11mkdir -p "$SRC/images/simple" && cd "$_" 12 13if ! [ -f rootfs ]; then 14 # ANCHOR: build 15 # Build a simple ubuntu image and create a user with no password. 16 virt-builder ubuntu-20.04 \ 17 --run-command "useradd -m -g sudo -p '' $USER ; chage -d 0 $USER" \ 18 -o ./rootfs 19 # ANCHOR_END: build 20 21 # ANCHOR: kernel 22 virt-builder --get-kernel ./rootfs -o . 23 # ANCHOR_END: kernel 24fi 25 26# ANCHOR: run 27# Run crosvm without sandboxing. 28# The rootfs is an image of a partitioned hard drive, so we need to tell 29# the kernel which partition to use (vda5 in case of ubuntu-20.04). 30cargo run --features=all-linux -- run \ 31 --disable-sandbox \ 32 --rwroot ./rootfs \ 33 --initrd ./initrd.img-* \ 34 -p "root=/dev/vda5" \ 35 ./vmlinuz-* 36# ANCHOR_END: run 37