> For the complete documentation index, see [llms.txt](https://xiayingp.gitbook.io/build_a_os/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiayingp.gitbook.io/build_a_os/file-system/make-xv6-file-disk-management-system.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
