A minimal initrd for spawning VMs with virtiofs mounted rootfs.
- Single statically liked initrd binary
- Supports kernels with virtiofs being modular
Install the musl target for static linking:
rustup target add x86_64-unknown-linux-muslcargo build --releaseThe statically linked binary will be at target/x86_64-unknown-linux-musl/release/virtintrd.
./mkvirtinitrd target/x86_64-unknown-linux-musl/release/virtintrd /usr/lib/modules/$(uname -r) initrd.imgqemu-system-x86_64 \
-kernel /boot/vmlinuz-$(uname -r) \
-initrd initrd.img \
-append "console=ttyS0" \
-nographicUse the --module= option to include additional kernel modules in the initramfs:
./mkvirtinitrd \
--module=virtio_blk \
--module=ext4 \
--module=nvme \
target/x86_64-unknown-linux-musl/release/virtintrd \
/usr/lib/modules/$(uname -r) \
initrd.imgThe virtiofs module is always included automatically.
The initrd handles a few options:
init: If specified, this is the program run as pid 1, defaults to/bin/sh- 'debug': If specified, debug output is printed
- 'rootfs': If specified, this virtiofs tag is used for the rootfs mount, default is
rootfs mount=foo: If specified the virtiofs tagfoois mounted read-write at/run/mnt/foomount-ro=foo: If specified the virtiofs tagfoois mounted read-only at/run/mnt/foo
Try the chrootvm script which takes a chroot dir, finds the latest kernel in it
(from /usr/lib/modules), dynamically builds a suitable initrd and runs a
program in that kernel with the chroot as rootfs.
For example:
./chrootvm /vcs/other/osbuild/output/build /usr/bin/bashIf no progam is specified, the default is to run /bin/sh.
This also supports --mount a-tag /a/path and --mount-ro a-tag /a/path which creates
additional virtiofs mounts at /run/mnt/tag.
There is also a --debug option which will make the VM print debug output.