# Make Xv6 File disk management system

QEMU presents a “legacy” virtio interface and has a virtue disk device. Xv6 implements a driver for this disk device. `virtio_disk.c`

QEMU command `qemu … -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0`

The `fs.img` is actually another xv6 problem built, and ask QEMU to treat it as file system.

### Who builds fs.img?

A program called `mkfs.c` does.

It builds disk layout as: `[ boot block | sb block | log | inode blocks | free bit map | data blocks ]`

The program calls Real OS (not xv6, not QEMU) `create` system call to create a file named `fs.img`. It set all data to this file! `mkfs` writes all the disk layout content, including superblock, inode, bitmaps, etc.

This program runs before kernel starts.

When kernel starts, it will contains this virtual file system already (supported by QEMU)!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiayingp.gitbook.io/build_a_os/file-system/make-xv6-file-disk-management-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
