Repository navigation
feat(vm): vm resize sets a stopped VM's vCPUs, memory and disk size for its next cold boot - #343
Open
tonicmuroq wants to merge 3 commits into
Open
tonicmuroq wants to merge 3 commits into
tonicmuroq wants to merge 3 commits into
Conversation
…ot settled vm resize takes --cpu, --memory and --storage, each optional. --storage grows the COW disk and never shrinks it: a raw disk with its ext4 (e2fsck, resize2fs), a qcow2 by virtual size. The disk grows before the record changes, so an interrupted resize is safe to rerun. A VM whose record or live VMM still claims it as up is refused, not only a running one: an error record left by a failed stop kept its compute interval open, and the resize changed the shape under it. The new size passes the create-time floors, the host core count and the kept cgroup knobs. Metering closes the storage interval at the old shape and opens one at the new shape with reason resize. Resize joins the Hypervisor interface since both backends take it from Backend; ExpandQcow2 moves next to the raw COW helpers, and cliutil.FlagSize replaces three copies of the size-flag parse.
… not regrow a cloud-image disk Hardware showed the root filesystem of an Ubuntu cloud-image guest unchanged after a --storage resize: cocoon drops the cidata disk after the first boot, so cloud-init does not run again.
CMGS
force-pushed
the
vm/resize-stopped
branch
from
November 27, 2026 06:21
5107345 to
28de016
Compare
This branch has not been deployed
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.
What
cocoon vm resize VM [--cpu N] [--memory SIZE] [--storage SIZE]changes the size a stopped VM boots at. At least one flag is required and an omitted one keeps the current value. The nextvm startcold-boots from the VM's own disks at the new size.--storagegrows the COW disk and never shrinks it.e2fsck -fp, thenresize2fs), so the guest sees the space at boot.run vm stop first. The new size must pass the create-time floors, the host core count, and the cgroup knobs the VM keeps.resize. A resize to the size the VM already has writes nothing.Why
A box created at 2 vCPU / 4 GB has to move to 4 vCPU / 8 GB with its whole disk. Clone and restore cannot do it: they rebuild the guest from the snapshot's memory image, which fixes vCPUs and memory (their
--cpu/--memorywere removed in #27 for that reason). sandboxd drives this verb from cocoonstack/sandbox#644, on hibernated claims, with--cpuand--memory; that call form is unchanged.Storage is in the same verb because a size class is three numbers, and a box that moves up a class otherwise keeps the smaller disk.
Changes against the first version of this PR
--storage, with the two disk growers.errorrecord left by a failed stop (compute interval still open, sometimes with the VMM alive) was resized: the latercompute.stopthen carried the new shape against a start with the old one.vm createapply (validateHostCPU, the cgroup knobs, the floors); the floors now have one owner,VMConfig.ValidateSize.--cpuand--memoryare optional.Resizeis a method of theHypervisorinterface: both backends take it fromBackend, so an optional interface had no backend that lacked it.ExpandQcow2moves from the Cloud Hypervisor package tohypervisor/disks.go, next to the raw COW helpers.cliutil.FlagSizereplaces three copies of the size-flag parse.For downstream
reasonvalue,resize, on avm.storage.stop/vm.storage.startpair. A consumer that rejects unknown reasons needs it added.vm restorefrom a snapshot taken before the resize brings that snapshot's size and disks back. This is by design; the docs say so.--storageresize:growpart /dev/vda 1 && resize2fs /dev/vda1on an Ubuntu image, Disk Management on Windows.Size and cost
hypervisor/resize.go+90: the verb, the stopped check, the size checks.hypervisor/disks.go+47:growCOW(+28) andExpandQcow2, which moved here fromcloudhypervisor/utils.go(-18 there).cmd/vm+52: the command and its handler.cmd/cliutil+15,cmd/core-1:FlagSize.types/vm.go+8:ValidateSize.vm resizeis an offline verb.--cpualone; 94 ms for vCPUs, memory and a 10G to 20G disk; 91 ms to grow a disk holding 3 GiB of data from 10G to 40G. The grow writes filesystem metadata only (allocated size stays 3.0G).Gates on the pushed head: golangci-lint 0 issues on linux and darwin, fmt, vet,
go mod tidy -diff, asl on both;go test -raceon darwin (39 packages) and in a linux container with e2fsprogs and qemu-utils (40 packages), where the raw-disk test runs the realmkfs.ext4,e2fsckandresize2fs.Coverage
Hardware: bare metal, x86_64, kernel 6.12, XFS; Cloud Hypervisor and Firecracker from the cocoonstack fork
devbuilds; two runs, 148 checks, 1 failure that was a wrong expectation of the test (see the cloud-image row).nproc4, MemTotal 8.2 GB, root filesystem 21.0 GB, marker file keptresize --cpu 4 --memory 8G, thenvm start(the sandboxd flow)errorrecord with the run still openstart 2/4G,stop 2/4G. The first version of this PR accepts it and the ledger readsstart 2/4G,stop 4/8Gstoppedrecord with a live VMMvm stopkills the VMM and the resize then passesresize2fsstand-in kills the CLIvm.storage.stopat the old shape andvm.storage.startat the new one, reasonresize, same timestamp; a no-op resize adds no line--storage10G to 20Gnprocand memory as set; the root filesystem stays 10.2 GB untilgrowpartandresize2fsrun in the guest, then 20.6 GB. The first run expected cloud-init to grow it and failed on that check; the hint and docs were corrected and the case reruncreatingrecorde2fsckleaving errors it cannot fix