|  | 
| 1 |  | -# disk-image-step | 
|  | 1 | +# 💡 Dimmer - The Disk Imager | 
|  | 2 | + | 
|  | 3 | +> *Realize bright ideas with less energy!* | 
|  | 4 | +
 | 
|  | 5 | +Dimmer is a tool that uses a simple textual description of a disk image to create actual images. | 
|  | 6 | + | 
|  | 7 | +This tool is incredibly valuable when implementing your own operating system, embedded systems or other kinds of deployment. | 
|  | 8 | + | 
|  | 9 | +## Example | 
|  | 10 | + | 
|  | 11 | +```rb | 
|  | 12 | +mbr-part | 
|  | 13 | +    bootloader paste-file "./syslinux.bin" | 
|  | 14 | +    part # partition 1 | 
|  | 15 | +        type fat16-lba | 
|  | 16 | +        size 25M | 
|  | 17 | +        contains vfat fat16 | 
|  | 18 | +            label "BOOT" | 
|  | 19 | +            copy-dir "/syslinux" "./bootfs/syslinux" | 
|  | 20 | +        endfat | 
|  | 21 | +    endpart | 
|  | 22 | +    part # partition 2 | 
|  | 23 | +        type fat32-lba | 
|  | 24 | +        contains vfat fat32 | 
|  | 25 | +            label "OS" | 
|  | 26 | +            mkdir "/home/dimmer" | 
|  | 27 | +            copy-file "/home/dimmer/.config/dimmer.cfg" "./dimmer.cfg" | 
|  | 28 | +            !include "./rootfs/files.dis" | 
|  | 29 | +        endfat | 
|  | 30 | +    endpart | 
|  | 31 | +    ignore # partition 3 | 
|  | 32 | +    ignore # partition 4 | 
|  | 33 | +``` | 
|  | 34 | + | 
|  | 35 | +## Available Content Types | 
|  | 36 | + | 
|  | 37 | +### Empty Content (`empty`) | 
|  | 38 | + | 
|  | 39 | +This type of content does not change its range at all and keeps it empty. No bytes will be emitted. | 
|  | 40 | + | 
|  | 41 | +```plain | 
|  | 42 | +empty | 
|  | 43 | +``` | 
|  | 44 | + | 
|  | 45 | +### Fill (`fill`) | 
|  | 46 | + | 
|  | 47 | +The *Fill* type will fill the remaining size in its space with the given `<byte>` value. | 
|  | 48 | + | 
|  | 49 | +```plain | 
|  | 50 | +fill <byte> | 
|  | 51 | +``` | 
|  | 52 | + | 
|  | 53 | +### Paste File Contents (`paste-file`) | 
|  | 54 | + | 
|  | 55 | +The *Raw* type will include the file at `<path>` verbatim and will error, if not enough space is available. | 
|  | 56 | + | 
|  | 57 | +`<path>` is relative to the current file. | 
|  | 58 | + | 
|  | 59 | +```plain | 
|  | 60 | +paste-file <path> | 
|  | 61 | +``` | 
|  | 62 | + | 
|  | 63 | +### MBR Partition Table (`mbr-part`) | 
|  | 64 | + | 
|  | 65 | +```plain | 
|  | 66 | +mbr-part | 
|  | 67 | +    [bootloader <content>] | 
|  | 68 | +    [part <…> | ignore] # partition 1 | 
|  | 69 | +    [part <…> | ignore] # partition 2 | 
|  | 70 | +    [part <…> | ignore] # partition 3 | 
|  | 71 | +    [part <…> | ignore] # partition 4 | 
|  | 72 | +``` | 
|  | 73 | + | 
|  | 74 | +```plain | 
|  | 75 | +part | 
|  | 76 | +    type <type-id> | 
|  | 77 | +    [bootable] | 
|  | 78 | +    [size <bytes>] | 
|  | 79 | +    [offset <bytes>] | 
|  | 80 | +    contains <content> | 
|  | 81 | +endpart | 
|  | 82 | +``` | 
|  | 83 | + | 
|  | 84 | +If `bootloader <content>` is given, will copy the `<content>` into the boot block, setting the boot code. | 
|  | 85 | + | 
|  | 86 | +The `mbr-part` component will end after all 4 partitions are specified. | 
|  | 87 | + | 
|  | 88 | +- Each partition must specify the `<type-id>` (see table below) to mark the partition type as well as `contains <content>` which defines what's stored in the partition. | 
|  | 89 | +- If `bootable` is present, the partition is marked as bootable. | 
|  | 90 | +- `size <bytes>` is required for all but the last partition and defines the size in bytes. It can use disk-size specifiers. | 
|  | 91 | +- `offset <bytes>` is required for either all or no partition and defines the disk offset for the partitions. This can be used to explicitly place the partitions. | 
|  | 92 | + | 
|  | 93 | +#### Partition Types | 
|  | 94 | + | 
|  | 95 | +| Type         | ID   | Description                                                                                                                                        | | 
|  | 96 | +| ------------ | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | 
|  | 97 | +| `empty`      | 0x00 | No content                                                                                                                                         | | 
|  | 98 | +| `fat12`      | 0x01 | [FAT12](https://en.wikipedia.org/wiki/FAT12)                                                                                                       | | 
|  | 99 | +| `ntfs`       | 0x07 | [NTFS](https://en.wikipedia.org/wiki/NTFS)                                                                                                         | | 
|  | 100 | +| `fat32-chs`  | 0x0B | [FAT32](https://en.wikipedia.org/wiki/FAT32) with [CHS](https://en.wikipedia.org/wiki/Cylinder-head-sector) addressing                             | | 
|  | 101 | +| `fat32-lba`  | 0x0C | [FAT32](https://en.wikipedia.org/wiki/FAT32) with [LBA](https://en.wikipedia.org/wiki/Logical_block_addressing) addressing                         | | 
|  | 102 | +| `fat16-lba`  | 0x0E | [FAT16B](https://en.wikipedia.org/wiki/File_Allocation_Table#FAT16B) with [LBA](https://en.wikipedia.org/wiki/Logical_block_addressing) addressing | | 
|  | 103 | +| `linux-swap` | 0x82 | [Linux swap space](https://en.wikipedia.org/wiki/Swap_space#Linux)                                                                                 | | 
|  | 104 | +| `linux-fs`   | 0x83 | Any [Linux file system](https://en.wikipedia.org/wiki/File_system#Linux)                                                                           | | 
|  | 105 | +| `linux-lvm`  | 0x8E | [Linux LVM](https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux))                                                                          | | 
|  | 106 | + | 
|  | 107 | +A complete list can be [found on Wikipedia](https://en.wikipedia.org/wiki/Partition_type), but [we do not support that yet](https://github.com/zig-osdev/disk-image-step/issues/8). | 
|  | 108 | + | 
|  | 109 | +### GPT Partition Table (`gpt-part`) | 
|  | 110 | + | 
|  | 111 | +```plain | 
|  | 112 | +
 | 
|  | 113 | +``` | 
|  | 114 | + | 
|  | 115 | +### FAT File System (`vfat`) | 
|  | 116 | + | 
|  | 117 | +```plain | 
|  | 118 | +vfat <type> | 
|  | 119 | +    [label <fs-label>] | 
|  | 120 | +    [fats <fatcount>] | 
|  | 121 | +    [root-size <count>] | 
|  | 122 | +    [sector-align <align>] | 
|  | 123 | +    [cluster-size <size>] | 
|  | 124 | +    <fs-ops...> | 
|  | 125 | +endfat | 
|  | 126 | +``` | 
|  | 127 | + | 
|  | 128 | +| Parameter    | Values                         | Description                                                                                                                                                                                                                                                                                                                                                           | | 
|  | 129 | +| ------------ | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 
|  | 130 | +| `<type>`     | `fat12`, `fat16`, `fat32`      | Selects the type of FAT filesystem that is created                                                                                                                                                                                                                                                                                                                    | | 
|  | 131 | +| `<fatcount>` | `one`, `two`                   | Number of FAT count. Select between small and safe.                                                                                                                                                                                                                                                                                                                   | | 
|  | 132 | +| `<fs-label>` | ascii string <= 11 chars       | Display name of the volume.                                                                                                                                                                                                                                                                                                                                           | | 
|  | 133 | +| `<count>`    | integers <= 32768              | Number of entries in the root directory.                                                                                                                                                                                                                                                                                                                              | | 
|  | 134 | +| `<align>`    | power of two >= 1 and <= 32768 | Specifies alignment of the volume data area (file allocation pool, usually erase block boundary of flash memory media) in unit of sector. The valid value for this member is between 1 and 32768 inclusive in power of 2. If a zero (the default value) or any invalid value is given, the function obtains the block size from lower layer with disk_ioctl function. | | 
|  | 135 | +| `<size>`     | powers of two                  | Specifies size of the allocation unit (cluter) in unit of byte.                                                                                                                                                                                                                                                                                                       | | 
|  | 136 | + | 
|  | 137 | +## Standard Filesystem Operations | 
|  | 138 | + | 
|  | 139 | +All `<path>` values use an absolute unix-style path, starting with a `/` and using `/` as a file separator. | 
|  | 140 | + | 
|  | 141 | +All operations do create the parent directories if necessary. | 
|  | 142 | + | 
|  | 143 | +### Create Directory (`mkdir`) | 
|  | 144 | + | 
|  | 145 | +```plain | 
|  | 146 | +mkdir <path> | 
|  | 147 | +``` | 
|  | 148 | + | 
|  | 149 | +Creates a directory. | 
|  | 150 | + | 
|  | 151 | +### Create File (`create-file`) | 
|  | 152 | + | 
|  | 153 | +```plain | 
|  | 154 | +create-file <path> <size> <content> | 
|  | 155 | +``` | 
|  | 156 | + | 
|  | 157 | +Creates a file in the file system with `<size>` bytes (can use sized spec) and embeds another `<content>` element. | 
|  | 158 | + | 
|  | 159 | +This can be used to construct special or nested files ad-hoc. | 
|  | 160 | + | 
|  | 161 | +### Copy File (`copy-file`) | 
|  | 162 | + | 
|  | 163 | +```plain | 
|  | 164 | +copy-file <path> <host-path> | 
|  | 165 | +``` | 
|  | 166 | + | 
|  | 167 | +Copies a file from `<host-path>` (relative to the current file) into the filesystem at `<path>`. | 
|  | 168 | + | 
|  | 169 | +### Copy Directory (`copy-dir`) | 
|  | 170 | + | 
|  | 171 | +```plain | 
|  | 172 | +copy-file <path> <host-path> | 
|  | 173 | +``` | 
|  | 174 | + | 
|  | 175 | +Copies a directory from `<host-path>` (relative to the current file) *recursively* into the filesystem at `<path>`. | 
|  | 176 | + | 
|  | 177 | +This will include *all files* from `<host-path>`. | 
|  | 178 | + | 
|  | 179 | +## Compiling | 
|  | 180 | + | 
|  | 181 | + | 
|  | 182 | +- Install [Zig 0.14.0](https://ziglang.org/download/). | 
|  | 183 | +- Invoke `zig build -Drelease` in the repository root. | 
|  | 184 | +- Execute `./zig-out/bin/dim --help` to verify your compilation worked. | 
0 commit comments