hashicorp/vagrant · error · Vagrant::Errors::VMPowerOffToPackage

The Vagrant virtual environment you are trying to package mu

Error message

The Vagrant virtual environment you are trying to package must be powered off.

What it means

The Hyper-V Export action (used by `vagrant package`) prints the machine's current state and raises VMPowerOffToPackage unless state.id is exactly :off - Hyper-V cannot export a running or saved VM, so packaging requires the machine powered off first.

Source

Thrown at plugins/providers/hyperv/action/export.rb:19

# Copyright IBM Corp. 2010, 2025
# SPDX-License-Identifier: BUSL-1.1

require "fileutils"

module VagrantPlugins
  module HyperV
    module Action
      class Export
        def initialize(app, env)
          @app = app
        end

        def call(env)
          @env = env

          @env[:ui].info @env[:machine].state.id.to_s

          raise Vagrant::Errors::VMPowerOffToPackage if
            @env[:machine].state.id != :off

          export

          @app.call(env)
        end

        def export
          @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
          export_tmp_dir = Vagrant::Util::Platform.wsl_to_windows_path(@env["export.temp_dir"])
          @env[:machine].provider.driver.export(export_tmp_dir) do |progress|
            @env[:ui].rewriting do |ui|
              ui.clear_line
              ui.report_progress(progress.percent, 100, false)
            end
          end

          # Clear the line a final time so the next data can appear

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Run `vagrant halt` first, then `vagrant package`
  2. Confirm with `vagrant status` that the state is poweroff before packaging
  3. In automation, chain the commands: vagrant halt && vagrant package --output my.box

Example fix

# before
vagrant package --output demo.box   # machine running -> VMPowerOffToPackage

# after
vagrant halt && vagrant package --output demo.box
Defensive patterns

Strategy: validation

Validate before calling

vagrant status --machine-readable | grep -q ',state,off' || vagrant halt
vagrant package

Prevention

When it happens

Trigger: Running `vagrant package` (or any action chain containing Export) while the Hyper-V machine is running, saved, or paused - anything other than the :off state.

Common situations: Forgetting `vagrant halt` before packaging; automation that packages immediately after `vagrant up`; a machine left in saved state by a host shutdown.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/60a9502f8655f39a. Report an issue: GitHub.