5 releases
Uses new Rust 2024
| 0.1.5 | Mar 27, 2026 |
|---|---|
| 0.1.4 | Mar 27, 2026 |
| 0.1.3 | Mar 27, 2026 |
| 0.1.2 | Feb 26, 2026 |
| 0.1.1 | Feb 26, 2026 |
#2749 in Filesystem
Used in bux
115KB
2.5K
SLoC
bux-e2fs
Ext4 filesystem image creation via libext2fs — static FFI bindings and safe Rust API.
Note: This crate statically links
libext2fsfrom e2fsprogs. For most use cases, prefer the high-levelbuxcrate.
How it works
Pre-generated bindgen bindings are committed in src/bindings.rs so end
users do not need libclang installed. At build time the build script:
- Downloads pre-built static libraries from GitHub Releases (or uses
BUX_E2FS_DIR). - Statically links
libext2fs,libcom_err,libe2p,libuuid, andlibcreate_inode.
Regenerating bindings
To update bindings from the pinned e2fsprogs headers (requires libclang, Linux/macOS only):
BUX_UPDATE_BINDINGS=1 cargo check -p bux-e2fs --features regenerate
Safe API
use bux_e2fs::Ext4Builder;
use std::path::Path;
// Create an ext4 image from a directory (like mke2fs -d)
Ext4Builder::new()
.block_size(4096)
.reserved_ratio(0)
.create_from_dir(
Path::new("/tmp/rootfs"),
Path::new("/tmp/base.raw"),
512 * 1024 * 1024,
)?;
// Inject a file into an existing image (like debugfs write)
Ext4Builder::inject_file(
Path::new("/tmp/base.raw"),
Path::new("/usr/local/bin/bux-guest"),
"usr/local/bin/bux-guest",
)?;
Environment variables
| Variable | Description |
|---|---|
BUX_E2FS_DIR |
Path to a local directory containing pre-built static libraries. Skips downloading. |
BUX_E2FS_VERSION |
Override the e2fsprogs release version (default: crate version). |
BUX_UPDATE_BINDINGS |
Copy generated bindings back to src/bindings.rs (with regenerate feature). |
Supported platforms
| Target | Status |
|---|---|
aarch64-apple-darwin |
✅ |
x86_64-unknown-linux-gnu |
✅ |
aarch64-unknown-linux-gnu |
✅ |
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Dependencies
~0.1–3MB
~54K SLoC