Skip to content

fix(aws): derive root block device from AMI, not hardcoded /dev/xvda (#284) - #346

Merged
scttfrdmn merged 1 commit into
mainfrom
spawn/284-root-device
Jul 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
spawn/284-root-device

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #284. Real bug fix — root-volume overrides silently no-op'd on /dev/sda1 AMIs.

Problem

buildBlockDevices hardcoded the root DeviceName to /dev/xvda. AWS AMIs register their root device in Image.RootDeviceName — Amazon Linux uses /dev/xvda, but Ubuntu, Rocky, Debian, and many marketplace AMIs use /dev/sda1. When they differ, the root mapping spawn built didn't match the AMI, so RootVolumeSizeGiB (and EBS encryption / DeleteOnTermination) landed on a non-root device: EC2 kept the AMI's default (often 8–20 GB) root and could attach a stray /dev/xvda volume — no error. A caller asking for a 200 GB Ubuntu root got the default.

Fix

Derive the root device name from the AMI. Refactored rootVolumeSizeFromAMI → rootDeviceInfoFromAMI, which returns (rootName, minGiB) from the same DescribeImages call Launch already made for the #25 snapshot-minimum — no extra API round-trip. buildBlockDevices now takes rootDeviceName and uses it for the root mapping, falling back to /dev/xvda only when the lookup fails/empty. The #25 snapshot-floor behavior is unchanged.

Verification

  • go build ./..., go vet ./pkg/aws, gofmt clean.
  • New TestBuildBlockDevices subtests: /dev/sda1 root carries the size override; empty root name falls back to /dev/xvda. All existing block-device + TestRootVolumeSizeFromMappings tests updated to the new signature and pass; full pkg/aws suite green (excl. pre-existing TestCatalogValid / feat(plugin): permissions declaration block (#388) #392).

Why it matters

Unblocks Prism (github.com/scttfrdmn/prism), which migrated its EC2 lifecycle onto spawn.Client but kept launch on its own path specifically because of this hardcode (its default templates are Ubuntu/Rocky → /dev/sda1). Matching the AMI's root device lets Prism route launch through spawn too.

…284)

buildBlockDevices hardcoded the root DeviceName to /dev/xvda. For AMIs
whose registered root device is /dev/sda1 (Ubuntu, Rocky, Debian, many
marketplace images) the root mapping didn't match the AMI, so
RootVolumeSizeGiB + EBS encryption/DeleteOnTermination landed on a
non-root device — EC2 silently kept the AMI's default (8-20 GB) root and
could attach a stray volume. A caller asking for a 200 GB Ubuntu root got
the default with no error.

Fix: derive the root device name from the AMI's RootDeviceName. Refactored
rootVolumeSizeFromAMI → rootDeviceInfoFromAMI, which returns (rootName,
minGiB) from the SAME DescribeImages call Launch already made for the #25
snapshot-minimum (no extra round-trip). buildBlockDevices now takes
rootDeviceName and uses it for the root mapping, falling back to /dev/xvda
when empty. #25 snapshot-floor behavior is unchanged.

Unblocks Prism (github.com/scttfrdmn/prism), which kept its launch path off
spawn specifically because of this hardcode (its templates are Ubuntu/Rocky).

Verified: go build ./..., go vet, gofmt clean; new TestBuildBlockDevices
subtests (/dev/sda1 carries the override; empty→/dev/xvda fallback) + all
existing block-device/root-size tests pass; full pkg/aws suite green.
@scttfrdmn
scttfrdmn force-pushed the spawn/284-root-device branch from 794784d to 6d93f10 Compare July 12, 2026 18:47
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/client.go 0.00% 10 Missing ⚠️
pkg/aws/ebs.go 50.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 094429a into main Jul 12, 2026
6 of 7 checks passed
@scttfrdmn
scttfrdmn deleted the spawn/284-root-device branch July 12, 2026 18:49
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.

Launch hardcodes root device /dev/xvda → root-volume-size override silently lost on Ubuntu/Rocky (/dev/sda1) AMIs

1 participant