Skip to content

Add support for mounting block devices into containers#145

Merged
akerouanton merged 2 commits intocontainerd:mainfrom
Kern--:block-mounts
Apr 3, 2026
Merged

Add support for mounting block devices into containers#145
akerouanton merged 2 commits intocontainerd:mainfrom
Kern--:block-mounts

Conversation

@Kern--
Copy link
Copy Markdown
Contributor

@Kern-- Kern-- commented Apr 3, 2026

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.

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>
Copilot AI review requested due to automatic review settings April 3, 2026 16:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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>
@akerouanton akerouanton merged commit 8493dd7 into containerd:main Apr 3, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants