Skip to content

When --nested-virtualization is set, prepare the KVM group in user-data #93

Open

Description

@scttfrdmn

Problem

When you launch a Linux builder with --nested-virtualization (spawn#91) to do
nested KVM work (e.g. building a Windows AMI per infra/amis/windows/, #83), the
host exposes /dev/kvm — but it's root:kvm 0660, so an ordinary login user
can't open it until they're in the kvm group.

The manual fix is sudo usermod -aG kvm $USER, but group membership only
applies to new logins
— the SSH session you ran it from still can't access
/dev/kvm, so the first packer build / qemu-system-x86_64 dies with:

Could not access KVM kernel module: Permission denied
qemu-system-x86_64: failed to initialize kvm: Permission denied

You then have to reconnect or wrap the build in sg kvm -c '...'. This bit us
during the first real #83 build run.

Proposal

When --nested-virtualization is set, have spawn's Linux user-data add the
login user to the kvm group at boot. user-data runs as root before the
user's first SSH login, so by the time they connect the group is already active
in their session — no usermod, no reconnect, no sg kvm dance.

Roughly, in the Linux user-data builder when nested virt is requested:

# nested virtualization: let the login user reach /dev/kvm without a re-login
if [ -e /dev/kvm ]; then
  groupadd -f kvm
  usermod -aG kvm "$LOGIN_USER"
fi

Notes / scope:

  • Only emit this when NestedVirtualization is true (no reason to touch the kvm
    group otherwise).
  • Don't install qemu/packer for them — toolchain choice is the user's (Ubuntu
    vs other); just make /dev/kvm reachable. Keep the README's explicit install
    steps.
  • Linux-only (the flag is meaningless for the Windows guest case).
  • $LOGIN_USER is whatever spawn already injects the SSH key for.

Acceptance

  • spawn launch ... --nested-virtualization → SSH in → id -nG includes kvm
    on the first session, and test -w /dev/kvm succeeds without sudo/sg.
  • No kvm-group changes when --nested-virtualization is absent.

Refs #83, #91.

Activity

  1. added
    area:launch
    on Jun 12, 2026
  2. added this to the Later milestone on Oct 19, 2026
  3. modified the milestones: Later, Post-1.0 on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:launch

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions