Skip to content

hyperv-prep: default --mounts to the number of default machine volumes - #30375

Open
zippy1981 wants to merge 1 commit into
podman-container-tools:mainfrom
zippy1981:fix/hyperv-prep-default-mounts
Open

zippy1981 wants to merge 1 commit into
podman-container-tools:mainfrom
zippy1981:fix/hyperv-prep-default-mounts

Conversation

@zippy1981

@zippy1981 zippy1981 commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #30374

What this PR does / why we need it:

podman system hyperv-prep hardcoded --mounts to 2. Since #28573 added the user config directory (/etc/containers) as a third default machine volume, podman machine init needs 3 Fileserver vsock entries, so non-admin users get ErrHypervRegistryInitRequiresElevation right after a successful hyperv-prep.

  • Default --mounts to len(ContainersConfDefaultsRO.Machine.Volumes.Get()), the same defaults machine init --volume uses, so the two cannot drift again.
  • Count existing entries per purpose and only create the missing ones. Machines already reuse existing entries by index (createShares, CheckIfHVSockRegistryEntriesExist), so re-running hyperv-prep, for example with a larger --mounts, no longer piles up duplicates.
  • Wrap ErrHypervRegistryInitRequiresElevation in checkCanCreate with the machine's volume count and the hyperv-prep --mounts N command. errors.Is still matches, so the auto-elevation path and stubber_test.go are unaffected.
  • Update podman-system-hyperv-prep.1.md.

How to verify it

  1. As an administrator: podman system hyperv-prep. With default containers.conf it creates 3 Fileserver entries.
  2. Run it again: no new entries are created.
  3. As a non-admin member of Hyper-V Administrators: podman machine init gets past the registry check.

I built it with GOOS=windows and the remote tags; go vet and compiling the pkg/machine/hyperv tests pass. I have run it on awindows VM.

Tested on Windows Server 2025 (Hyper-V): with 2 Fileserver entries a non-admin machine init fails with the new hint; plain hyperv-prep adds only the missing entry and a re-run adds none; then a non-admin machine init, start and podman info succeed.

Which issue(s) this PR fixes:

Fixes #30374

Special notes for your reviewer:

The default comes from the containers.conf of whoever runs hyperv-prep, usually an administrator. A user with more volumes configured still needs a larger --mounts, and the new error message tells them which number to use.

Does this PR introduce a user-facing change?

`podman system hyperv-prep` now defaults `--mounts` to the number of default machine volumes and only creates missing vsock registry entries, fixing non-admin `podman machine init` failing with "requires admin rights" on Hyper-V.

🤖 Generated with Claude Code but edited by hand

"podman system hyperv-prep" hardcoded --mounts to 2, matching the two
WSL-style default machine volumes on Windows (the home directory and its
drive). The container-libs update in 49ab599 added a third default
volume, the user config directory mounted at /etc/containers. Since then
"podman machine init" asks for 3 Fileserver vsock entries, finds only the 2
that hyperv-prep created, and non-admin users get "the first time Podman
initializes a Hyper-V machine, it requires admin rights" even though
hyperv-prep succeeded.

- Default --mounts to the number of default machine volumes in
  containers.conf, the same list "machine init" uses for --volume.
- Only create the entries that are missing, so hyperv-prep can be re-run
  (for example with a larger --mounts) without piling up duplicate
  entries. Machines already reuse existing entries by index.
- Say how many entries are needed, and the hyperv-prep command that
  creates them, when machine init fails this check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Justin Dearing <zippy181@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hyperv-prep creates 2 Fileserver vsock entries but machine init now needs 3, so non-admin init fails with "requires admin rights"

1 participant