Skip to content

[codex] feat: support resizable macOS system disks - #33

Draft
czmDeRepository wants to merge 1 commit into
cocoonstack:masterfrom
czmDeRepository:codex/macos-resizable-system-disk
Draft

[codex] feat: support resizable macOS system disks#33
czmDeRepository wants to merge 1 commit into
cocoonstack:masterfrom
czmDeRepository:codex/macos-resizable-system-disk

Conversation

@czmDeRepository

Copy link
Copy Markdown
Contributor

What changed

  • add --storage to macOS VM create/run/clone
  • grow a newly created qcow2 overlay before boot and reject unsafe shrinking
  • persist the resulting virtual disk size in the VM record
  • install an idempotent first-boot LaunchDaemon that expands the root APFS container into newly available space

Why

Cloud images currently impose their original virtual disk size on every VM. Supporting safe growth makes one image reusable across multiple storage specifications without rebuilding the image.

Semantics

  • omitted storage keeps the image virtual size
  • clone inherits the source size unless explicitly overridden
  • requested size may grow but never shrink the image

Validation

  • GOWORK=off go test ./...
  • make fmt-check vet lint
  • bash -n scripts/provision-macos.sh

@CMGS CMGS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

useful feature and the core is right — resizeSystemDisk reuses cocoon's ReadQcow2Header + RunQemuImg, grow-only with a clear reject, and the record carries the size for clone inheritance. gates green incl asl (both GOOS), tests, gofmt.

two cleanups + one nit inline. also, non-blocking: the APFS grow daemon runs diskutil repairDisk on the whole disk (with a piped y) every boot that has free space — a heavy hammer to refresh the GPT; fine functionally, just flagging it since it's the one destructive-looking op on the boot path.

Comment thread cmd/vm/utils.go
return nil
}

func storageFromFlag(cmd *cobra.Command) (int64, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

reuse + consistency: datadisk.go:81 already parses sizes with units.RAMInBytes (accepts 20G). this reimplements it with a strip-trailing-i hack for a k8s-style 100Gi, so the same binary now speaks two size dialects — data disks want 20G, system disk wants 100Gi. pull one helper into utils.go (parseSize(raw) (int64, error)) and use it for both, and pick one spelling for the flag help + docs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

measured to be precise — units.RAMInBytes natively accepts 100G, 100GB, 100GiB and rejects only bare 100Gi (invalid suffix 'gi'). so the strip-i hack exists solely for the k8s spelling. simplest: drop the hack, document --storage as 100G/100GiB (same dialect data disks already speak), one shared parseSize for both. keep Gi-tolerance only if you really want kube-style input, and then in the shared helper so data disks get it too.

Comment thread cmd/vm/utils.go
return n, nil
}

// resizeSystemDisk expands a newly-created overlay to target bytes. A zero

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comment budget: 3 lines → 1. keep the WHY only:
// resizeSystemDisk grows a new overlay to target bytes (0 = keep image size); shrinking is rejected — qemu-img can't prove the guest fs survives.

Comment thread cmd/vm/handler.go

CPUs int `json:"cpus"`
Memory string `json:"memory"`
Storage int64 `json:"storage"` // system-disk virtual size in bytes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

json:"storage" with no omitempty writes "storage":0 into every record that keeps the image size. add ,omitempty — zero already means 'image virtual size'.

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