Skip to content

Commit f891b97

Browse files
committed
Update architecture document with formatting improvements
1 parent e9331c6 commit f891b97

1 file changed

Lines changed: 38 additions & 3 deletions

File tree

docs/ARCHITECTURE.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document describes the architecture and design decisions of the handbuilt-l
44

55
## System Architecture
66

7-
```
7+
```sh
88
┌─────────────────────────────────────────────────────────────┐
99
│ Docker Build Process │
1010
├─────────────────────────────────────────────────────────────┤
@@ -35,6 +35,7 @@ This document describes the architecture and design decisions of the handbuilt-l
3535
### 1. Build System
3636

3737
#### Dockerfile
38+
3839
Multi-stage build with 8 distinct stages:
3940

4041
1. **builder-base**: Base image with build dependencies
@@ -47,6 +48,7 @@ Multi-stage build with 8 distinct stages:
4748
8. **runtime**: Final minimal runtime image
4849

4950
#### Benefits
51+
5052
- **Layer caching**: Faster rebuilds
5153
- **Parallel builds**: Independent stages can build concurrently
5254
- **Size optimization**: Final image only contains necessary artifacts
@@ -57,12 +59,14 @@ Multi-stage build with 8 distinct stages:
5759
**Source**: torvalds/linux (latest)
5860

5961
**Configuration**: `linux.config`
62+
6063
- Minimal feature set
6164
- x86_64 architecture
6265
- Required drivers only
6366
- No unnecessary modules
6467

6568
**Build Process**:
69+
6670
```bash
6771
make olddefconfig
6872
make -j$(nproc)
@@ -76,11 +80,13 @@ strip --strip-debug arch/x86/boot/bzImage
7680
**Source**: git.busybox.net/busybox (latest)
7781

7882
**Configuration**: `busybox.config`
83+
7984
- Essential utilities only
8085
- Static linking
8186
- Minimal size
8287

8388
**Provides**:
89+
8490
- Shell (sh)
8591
- Core utilities (ls, cp, mv, etc.)
8692
- System utilities (mount, ps, top, etc.)
@@ -93,13 +99,15 @@ strip --strip-debug arch/x86/boot/bzImage
9399
**File**: `init.sh`
94100

95101
**Responsibilities**:
102+
96103
- Mount essential filesystems (/proc, /sys, /dev, /tmp, /run)
97104
- Populate /dev with device nodes
98105
- Set hostname
99106
- Configure environment
100107
- Start shell (PID 1)
101108

102109
**Design Philosophy**:
110+
103111
- Simple and transparent
104112
- No complex service management
105113
- Easy to understand and modify
@@ -112,6 +120,7 @@ strip --strip-debug arch/x86/boot/bzImage
112120
**Configuration**: `syslinux.cfg`
113121

114122
**Boot Process**:
123+
115124
1. BIOS/UEFI loads bootloader
116125
2. Bootloader loads kernel (bzImage)
117126
3. Kernel decompresses and initializes
@@ -123,35 +132,44 @@ strip --strip-debug arch/x86/boot/bzImage
123132
### 6. Build Scripts
124133

125134
#### build.sh
135+
126136
Creates bootable disk image with:
137+
127138
- Error handling and validation
128139
- Logging with colors
129140
- Command-line options
130141
- Cleanup on exit
131142

132143
#### scripts/
144+
133145
- `extract.sh`: Extract artifacts from Docker
134146
- `test.sh`: Automated testing
135147
- `clean.sh`: Cleanup build artifacts
136148

137149
### 7. Automation
138150

139151
#### Makefile
152+
140153
Provides convenient targets for:
154+
141155
- Building Docker image
142156
- Extracting artifacts
143157
- Running tests
144158
- QEMU testing
145159
- Cleanup operations
146160

147161
#### docker-compose.yml
162+
148163
Defines services:
164+
149165
- `builder`: Builds distribution
150166
- `dev`: Development environment
151167
- `qemu`: Testing environment
152168

153169
#### GitHub Actions
170+
154171
Automated CI/CD pipeline:
172+
155173
- Build on every push
156174
- Run tests
157175
- Security scanning
@@ -162,7 +180,7 @@ Automated CI/CD pipeline:
162180

163181
### Build Flow
164182

165-
```
183+
```sh
166184
Source Code
167185
168186
Docker Build
@@ -187,7 +205,7 @@ Docker Build
187205

188206
### Boot Flow
189207

190-
```
208+
```sh
191209
Power On
192210
193211
BIOS/UEFI
@@ -212,18 +230,21 @@ Shell
212230
## Security Considerations
213231

214232
### Build-time Security
233+
215234
- Multi-stage builds isolate build environment
216235
- No build tools in final image
217236
- Minimal dependencies
218237
- Regular source updates
219238

220239
### Runtime Security
240+
221241
- Non-root user in Docker
222242
- Minimal attack surface
223243
- No network services by default
224244
- Read-only root filesystem possible
225245

226246
### Supply Chain Security
247+
227248
- Verified source repositories
228249
- Checksums for downloads
229250
- Security scanning in CI
@@ -232,18 +253,21 @@ Shell
232253
## Performance Optimizations
233254

234255
### Build Performance
256+
235257
- Layer caching
236258
- Parallel compilation
237259
- Build cache mounts
238260
- Incremental builds
239261

240262
### Runtime Performance
263+
241264
- Static linking (no dynamic loading overhead)
242265
- Minimal kernel
243266
- Fast boot time (~1-2 seconds)
244267
- Low memory footprint (~10-20MB)
245268

246269
### Size Optimizations
270+
247271
- Strip debug symbols
248272
- Minimal kernel configuration
249273
- Single BusyBox binary
@@ -252,6 +276,7 @@ Shell
252276
## Extensibility
253277

254278
### Adding Packages
279+
255280
```dockerfile
256281
# In busybox-builder stage
257282
RUN cd /build/initramfs && \
@@ -260,18 +285,23 @@ RUN cd /build/initramfs && \
260285
```
261286

262287
### Custom Init Scripts
288+
263289
Modify `init.sh` or add to `/etc/init.d/`
264290

265291
### Kernel Modules
292+
266293
Enable in `linux.config`:
294+
267295
```bash
268296
make menuconfig
269297
# Enable desired modules
270298
cp .config linux.config
271299
```
272300

273301
### Network Services
302+
274303
Add to `init.sh`:
304+
275305
```bash
276306
# Start network
277307
ifconfig eth0 up
@@ -284,23 +314,27 @@ httpd -h /www
284314
## Testing Strategy
285315

286316
### Unit Tests
317+
287318
- Script syntax validation
288319
- File existence checks
289320
- Format validation
290321

291322
### Integration Tests
323+
292324
- Full build process
293325
- Docker image testing
294326
- Artifact extraction
295327

296328
### System Tests
329+
297330
- QEMU boot testing
298331
- Functional testing
299332
- Performance benchmarks
300333

301334
## Future Enhancements
302335

303336
### Planned Features
337+
304338
- [ ] UEFI boot support
305339
- [ ] ARM architecture support
306340
- [ ] Package manager integration
@@ -309,6 +343,7 @@ httpd -h /www
309343
- [ ] Persistent storage support
310344

311345
### Under Consideration
346+
312347
- [ ] Systemd alternative
313348
- [ ] Container runtime
314349
- [ ] Full development environment

0 commit comments

Comments
 (0)