1# Fs 2 3Crosvm supports 4[virtio-fs](https://docs.oasis-open.org/virtio/virtio/v1.2/csd01/virtio-v1.2-csd01.html#x1-45800011), 5a shared file system that lets virtual machines access a directory tree on the host. It allows the 6guest to access files on the host machine. This section will explain how to create a shared 7directory. You can also find a runnable sample in `tools/examples/example_fs`. 8 9## Creating a Shared Directory on the Host Machine 10 11To create a shared directory, run the following commands in the host machine: 12 13```sh 14mkdir host_shared_dir 15HOST_SHARED_DIR=$(pwd)/host_shared_dir 16crosvm run \ 17 --shared-dir "$HOST_SHARED_DIR:my_shared_tag:type=fs" \ 18 ... # usual crosvm args 19``` 20 21In the `--shared-dir` argument: 22 23- The first field is the directory to be shared (`$HOST_SHARED_DIR` in this example). 24- The second field is the tag that the VM will use to identify the device (`my_shared_tag` in this 25 example). 26- The remaining fields are key-value pairs configuring the shared directory. 27 28To see available options, run `crosvm run --help`. 29 30## Mount the Shared Directory in the Guest OS 31 32Next, switch to the guest OS and run the following commands to set up the shared directory: 33 34```sh 35sudo su 36mkdir /tmp/guest_shared_dir 37mount -t virtiofs my_shared_tag /tmp/guest_shared_dir 38``` 39 40You can now add files to the shared directory. Any files you put in the `guest_shared_dir` will 41appear in the `host_shared_dir` on the host machine, and vice versa. 42 43## Running VirtioFS as root filesystem 44 45It is also possible to boot crosvm directly from a virtio-fs directory, as long as the directory 46structure matches that of a valid rootfs. The outcome is similar to running a chroot but inside a 47VM. 48 49Running VMs with virtio-fs as root filesystem may not be ideal as performance will not be as good as 50running a root disk with virtio-block, but it can be useful to run tests and debug while sharing 51files between host and guest. 52 53You can refer to the [advanced usage](../running_crosvm/advanced_usage.md#with-virtiofs) page for 54the instructions on how to run virtio-fs as rootfs. 55