feat: use cpio crate for initramfs creation

Add the `cpio` crate as dependency, removing e2fsprogs external dependency.
This commit is contained in:
2026-06-16 20:31:25 +02:00
parent 4f44af4449
commit 931a6dcfd5
5 changed files with 163 additions and 221 deletions
+8 -13
View File
@@ -187,7 +187,7 @@ No action required. Modern qemu-user-static packages register binfmt_misc with t
## QEMU System Emulation Mode
When `--kernel` is specified, ecr switches from namespace/chroot mode to QEMU system emulation. The extracted rootfs is converted to a disk image and booted with the provided kernel.
When `--kernel` is specified, ecr switches from namespace/chroot mode to QEMU system emulation. The extracted rootfs is converted to a gzipped CPIO initramfs and booted with the provided kernel.
### Usage
@@ -201,24 +201,20 @@ ecr --kernel /boot/vmlinuz debian -- /bin/sh -c "echo hello"
1. Download/cache rootfs tarball (same as namespace mode)
2. Extract tarball to temporary directory
3. Create ext4 disk image from rootfs using `mke2fs -d` (requires `e2fsprogs`)
3. Create gzipped CPIO initramfs from rootfs
4. Launch QEMU with:
- `-kernel <path>` - provided kernel
- `-append "root=/dev/vda rw console=ttyS0"` - kernel command line
- `-initrd initramfs.cpio.gz` - rootfs as initramfs
- `-append "console=ttyS0 rdinit=/bin/sh"` - kernel command line
- `-m <memory>` - memory size (default 2G)
- `-nographic` - console on stdio
- `-drive file=rootfs.img,format=raw,if=virtio` - rootfs disk
- `-display none -serial mon:stdio` - console on stdio
- `-netdev user,id=net0 -device virtio-net-pci,netdev=net0` - network
5. Wait for QEMU to exit
6. Cleanup temporary files
### Disk Image Creation
### Initramfs Creation
The rootfs directory is converted to an ext4 disk image using `mke2fs -t ext4 -d <rootfs>`. This requires the `e2fsprogs` package:
- Ubuntu/Debian: `sudo apt install e2fsprogs`
- Arch: `sudo pacman -S e2fsprogs`
- Alpine: `sudo apk add e2fsprogs`
The rootfs directory is converted to a gzipped CPIO archive (newc format) using the `cpio` crate.
### Architecture Support
@@ -234,8 +230,7 @@ The rootfs directory is converted to an ext4 disk image using `mke2fs -t ext4 -d
### Requirements
- QEMU system emulator installed (`qemu-system-<arch>`)
- `e2fsprogs` for disk image creation
- Kernel with virtio support (for disk and network drivers)
- Kernel with required drivers (serial console, virtio-net for network)
### Differences from Namespace Mode