> For the complete documentation index, see [llms.txt](https://stardustos.gitbook.io/stardust/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stardustos.gitbook.io/stardust/getting-started/using-the-block-device.md).

# Using the Block Device

For development and testing purposes it may be useful to use the underlying block front-end device driver in order to read data from, or write data to an external disk image file. This documentation provides clear instructions on how to configure Stardust to be compiled with support for a rudimentary file system that uses the block device.&#x20;

### Creating the disk image

The first step is to create an adequate disk image file that can be used by Stardust. Please follow these instructions:

#### Create a file which is occupied with zeros

```
$ dd if=/dev/zero of=disk.img count=512 bs=1M
```

This will create a disk image file, but you can change the configuration to alter the size as needed.

#### Create a partition

```
$ fdisk disk.img
```

By executing the above command, a number of questions will be presented in your terminal and the following example shows how to typically answer these questions:

```
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognised partition table.
Created a new DOS disklabel with disk identifier 0x71862b73.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x4573e6f5.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-1048575, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575, default 1048575): 

Created a new partition 1 of type 'Linux' and of size 511 MiB.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): b
Changed type of partition 'AIX bootable' to 'W95 FAT32'.

Command (m for help): w
The partition table has been altered.
Synching disks.
```

#### Create the file system disk image

```
$ mkfs.vfat disk.img
```

Following the execution of the above command, the disk image file will be ready for use.

#### Populating the disk image with some data

If you would like to populate the disk image with some data, you can simply mount the disk image in a local directory, insert data into it and then demount it. In order to mount the disk image you need to execute the following steps for example:

```
$ mkdir mnt
$ sudo mount disk.img mnt
```

Now you can create or copy files in the location where the disk image has been mounted.

Similarly you can demount the disk image using the following command:

```
$ sudo umount mnt
```

### Configuring and building Stardust

In order to configure Stardust's build system to compile the kernel with the front-end block device driver and support for a rudimentary file system you will need to:

* Modify the kernel's configuration header file **config.h** by enabling the labels defined to support both the block front-end device driver and the file system
* Clone the software packages repository which contains the source code of the file system library and set its path correctly in the Makefile of the operating system

Once these steps have been performed you can compile Stardust by executing **make**.

{% hint style="info" %}
Please note that the file system library contains simple tests for reading files from or writing files to the file disk image.
{% endhint %}


---

# 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://stardustos.gitbook.io/stardust/getting-started/using-the-block-device.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.
