Skip to content

Comments

LinuxContainer: Add support for optional writable layer#533

Merged
dcantah merged 1 commit intoapple:mainfrom
dcantah:choose-rootfs-size
Feb 19, 2026
Merged

LinuxContainer: Add support for optional writable layer#533
dcantah merged 1 commit intoapple:mainfrom
dcantah:choose-rootfs-size

Conversation

@dcantah
Copy link
Member

@dcantah dcantah commented Feb 18, 2026

This adds support to LinuxContainer to be able to provide an optional writable layer. This is useful as today the rootfs size is determined by the size of the image block itself which is set in stone at unpack time of the image. This leaves a lot to be desired because a user might want a larger or smaller rootfs size, but it's not configurable on a per container basis because of this. To support this, we can pass an additional writable block device that we can overlayfs with the image contents in the guest. All writes will go to this writable layer, and the rootfs size in the container is now whatever size this writable layer is.

The block devices (via our ext4 package, but you could use whatever) are cheap enough to generate on the fly that you can choose whatever size you want easily.

This adds support to LinuxContainer to be able to be provided an
optional writable layer. This is useful as today the rootfs size
is determined by the size of the image block itself which is determined
at unpack time of the image. This leaves a lot to be desired because
a user might want a larger or smaller rootfs size, but it's not configurable
on a per container basis because of this. To support this, we can pass
an additional writable block device that we can overlayfs with the image
contents in the guest. All writes will go to this writable layer, and
the rootfs size in the container is now whatever size this writable layer
is.

The block devices (via our ext4 package, but you could use whatever) are
cheap enough to generate on the fly that you can choose whatever size you
want easily.
// We let the OCI runtime remount as ro, instead of doing it originally.
spec.root?.readonly = self.rootfs.options.contains("ro")
// However, if we have a writable layer, the overlay allows writes so we don't mark it read-only.
spec.root?.readonly = self.rootfs.options.contains("ro") && self.writableLayer == nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Or:

guard !self.rootfs.options.contains("ro") || self.writableLayer == nil else {
    throw ContainerizationError(.invalidArgument, message: "cannot define writable layer with read-only root fs")
}

spec.root?.readonly = self.rootfs.options.contains("ro")

Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to rework the root mount stuff whatever we do here will change. Either approach is correct.

@dcantah dcantah merged commit 061bc0a into apple:main Feb 19, 2026
3 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.

2 participants