{"record":{"id":"60a9502f8655f39a","repo":"hashicorp/vagrant","slug":"the-vagrant-virtual-environment-you-are-trying-to","errorCode":null,"errorMessage":"The Vagrant virtual environment you are trying to package must be powered off.","messagePattern":"The Vagrant virtual environment you are trying to package must be powered off\\.","errorType":"exception","errorClass":"Vagrant::Errors::VMPowerOffToPackage","httpStatus":null,"severity":"error","filePath":"plugins/providers/hyperv/action/export.rb","lineNumber":19,"sourceCode":"# Copyright IBM Corp. 2010, 2025\n# SPDX-License-Identifier: BUSL-1.1\n\nrequire \"fileutils\"\n\nmodule VagrantPlugins\n  module HyperV\n    module Action\n      class Export\n        def initialize(app, env)\n          @app = app\n        end\n\n        def call(env)\n          @env = env\n\n          @env[:ui].info @env[:machine].state.id.to_s\n\n          raise Vagrant::Errors::VMPowerOffToPackage if\n            @env[:machine].state.id != :off\n\n          export\n\n          @app.call(env)\n        end\n\n        def export\n          @env[:ui].info I18n.t(\"vagrant.actions.vm.export.exporting\")\n          export_tmp_dir = Vagrant::Util::Platform.wsl_to_windows_path(@env[\"export.temp_dir\"])\n          @env[:machine].provider.driver.export(export_tmp_dir) do |progress|\n            @env[:ui].rewriting do |ui|\n              ui.clear_line\n              ui.report_progress(progress.percent, 100, false)\n            end\n          end\n\n          # Clear the line a final time so the next data can appear","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/providers/hyperv/action/export.rb#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"Forgetting `vagrant halt` before packaging; automation that packages immediately after `vagrant up`; a machine left in saved state by a host shutdown.","solutions":["Run `vagrant halt` first, then `vagrant package`","Confirm with `vagrant status` that the state is poweroff before packaging","In automation, chain the commands: vagrant halt && vagrant package --output my.box"],"exampleFix":"# before\nvagrant package --output demo.box   # machine running -> VMPowerOffToPackage\n\n# after\nvagrant halt && vagrant package --output demo.box","handlingStrategy":"validation","validationCode":"vagrant status --machine-readable | grep -q ',state,off' || vagrant halt\nvagrant package","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always halt before package in scripts: vagrant halt && vagrant package","Check `vagrant status` in automation and fail fast on non-off states","Package from clean, freshly provisioned, halted machines for reproducible boxes"],"tags":["vagrant","hyperv","package","vm-state"],"backgroundTag":"invalid-vm-state","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}