Add support for mounting block devices into containers#145
Merged
akerouanton merged 2 commits intocontainerd:mainfrom Apr 3, 2026
Merged
Add support for mounting block devices into containers#145akerouanton merged 2 commits intocontainerd:mainfrom
akerouanton merged 2 commits intocontainerd:mainfrom
Conversation
When a container is created with ext4 mounts, the shim now transforms the OCI spec ext4 mounts into virtio-block devices before VM launch. A shared disk allocator assigns sequential virtio-block letters (vda, vdb,...) across rootfs and mounted disks — rootfs disks are allocated first, so other mounts always follow sequentially (e.g. vdc+). For each mount, the shim adds the device and rewrites the OCI mount to bind from the VM-side mountpoint (/mnt/sdX) Inside the VM, vminit receives a set of block devices to mount at startup and mounts the device at the corresponding mountpoint. The container then sees a normal bind mount at its target path. The maximum total virtio disk count (rootfs + volumes combined) was also raised to 25. Signed-off-by: Kern Walster <kern.walster@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds support for mounting ext4 block device volumes into containers by implementing a new in-VM mount service and refactoring the mounting architecture. Previously, virtiofs bind mounts were configured via vminitd command-line arguments. This change migrates them to an RPC-based approach and adds native support for ext4 block devices, which are transformed into bind mounts after being mounted at the device level.
Changes:
- New Mount service plugin that handles mounting filesystems inside VMs via TTRPC RPC
- Refactored mount handling to use RPC instead of vminitd command-line flags
- Added blockMounter type to transform ext4 mounts into virtio-block devices
- Introduced diskAllocator to manage sequential device letter allocation across rootfs and volume disks
- Increased maximum virtio disk count from 10 (volumes-only) to 25 (total)
- Updated tests to verify both bind mount and block mount transformations
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| plugins/services/mount/service.go | New TTRPC mount service for in-VM mounting |
| internal/shim/task/service.go | Integrates mount service RPC calls into task creation flow |
| internal/shim/task/mount.go | Adds blockMounter and refactors to use diskAllocator for device assignment |
| internal/shim/task/mount_test.go | Comprehensive tests for blockMounter and updated bindMounter tests |
| internal/shim/task/mount_linux.go | Updates setupMounts signature to accept diskAllocator |
| internal/shim/task/mount_other.go | Updates setupMounts signature for non-Linux builds |
| cmd/vminitd/main.go | Imports mount service plugin and removes -mount flag handling |
| cmd/vminitd/bind_mounts.go | Removed - mount logic now handled via RPC service |
| api/proto/nerdbox/services/mount/v1/mount.proto | New proto definitions for Mount service |
| api/services/mount/v1/* | Generated protobuf and TTRPC code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
akerouanton
approved these changes
Apr 3, 2026
Previously, bind mounts and block device mounts added command line args to vminit to mount virtio-fs/virtio-block devices in the VM before starting the container. This moves the responsibility to a new Mount service that gets called after the VM is running, but before starting the container. Signed-off-by: Kern Walster <kern.walster@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change adds support for mounting ext4 block files from the host to the container. It does this by adding a virtio-block device to the VM and rewriting the mount from the bundle into a bind mount inside the vm. It also calls in to a new mount service to do the in-VM mount before starting the container.
It also migrates virtio-fs mounts from vm init args into the mount service.