xref: /aosp_15_r20/external/crosvm/tools/examples/example_fs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1#!/bin/bash
2# Copyright 2023 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 shared directory
7
8set -e
9
10SRC=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
11#If "example_simple" is executed, reuse its image. Otherwise, create one.
12mkdir -p "$SRC/images/simple" && cd "$_"
13mkdir -p "host_shared_dir"
14HOST_SHARED_DIR="$SRC/images/simple/host_shared_dir"
15
16if ! [ -f rootfs ]; then
17    # Build a simple ubuntu image and create a user with no password.
18    virt-builder ubuntu-20.04 \
19        --run-command "useradd -m -g sudo -p '' $USER ; chage -d 0 $USER" \
20        -o ./rootfs
21
22    virt-builder --get-kernel ./rootfs -o .
23fi
24
25# Use crosvm/tools/examples/images/simple/host_shared_dir as mount point
26cargo run -- run \
27    --shared-dir "$HOST_SHARED_DIR:my_shared_tag:type=fs" \
28    --rwdisk ./rootfs \
29    --initrd ./initrd.img-* \
30    -p "root=/dev/vda5 " \
31    ./vmlinuz-*
32
33## In guest OS, run following instructions to set up the shared directory
34## sudo su
35## mkdir /tmp/guest_shared_dir
36## mount -t virtiofs my_shared_tag /tmp/guest_shared_dir
37