{"record":{"id":"1c9cd4df272c73bf","repo":"hashicorp/vagrant","slug":"the-vagrant-virtual-environment-you-are-trying-to-1c9cd4","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/virtualbox/action/export.rb","lineNumber":18,"sourceCode":"# Copyright IBM Corp. 2010, 2025\n# SPDX-License-Identifier: BUSL-1.1\n\nrequire \"fileutils\"\nrequire 'vagrant/util/platform'\n\nmodule VagrantPlugins\n  module ProviderVirtualBox\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          raise Vagrant::Errors::VMPowerOffToPackage if \\\n            @env[:machine].state.id != :poweroff\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          @env[:machine].provider.driver.export(ovf_path) 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\n          # alone on the line.","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/providers/virtualbox/action/export.rb#L1-L36","documentation":"The VirtualBox Export action refuses to package a machine that is not fully powered off: it checks @env[:machine].state.id != :poweroff and raises VMPowerOffToPackage before invoking driver.export. An .ova export requires the VM stopped because VirtualBox can only snapshot/clone a powered-off disk chain cleanly.","triggerScenarios":"`vagrant package` (or any flow reaching the Export action) while the machine state is running, saved, abend, or paused — anything other than :poweroff.","commonSituations":"Running `vagrant package` right after `vagrant up` without halting; assuming `vagrant suspend` is sufficient (saved state still fails); provisioning automation that packages as a final step without a halt step.","solutions":["Halt the machine first: `vagrant halt` (wait for state 'poweroff'), then `vagrant package`","If halt hangs, force it: `vagrant halt --force`, or power off from VirtualBox GUI/`VBoxManage controlvm <name> poweroff`","In automation scripts, insert `vagrant halt` (and optionally `vagrant halt --force` fallback) before the package step","Check `vagrant status` shows 'poweroff' before packaging"],"exampleFix":"# before:\nvagrant up\nvagrant package --output mybox.box   # -> VMPowerOffToPackage\n\n# after:\nvagrant up\nvagrant ssh -c 'sudo poweroff' || vagrant halt\nvagrant status                        # must show: poweroff\nvagrant package --output mybox.box","handlingStrategy":"validation","validationCode":"# guard the package step in automation\nstate = `vagrant status --machine-readable`.lines.find { |l| l.include?('state-') }\nabort 'VM not powered off - run vagrant halt first' unless state&.include?('poweroff')","typeGuard":"def packageable?(machine)\n  machine.state.id == :poweroff   # only :poweroff passes the Export action check\nend","tryCatchPattern":"begin\n  env.cli('package', '--output', out)\nrescue Vagrant::Errors::VMPowerOffToPackage\n  env.cli('halt')\n  retry\nend","preventionTips":["Make `vagrant halt` an explicit step before package in scripts and pipelines","Check `vagrant status` shows poweroff (not saved) before packaging","Remember suspend is not enough — only a full shutdown exports cleanly"],"tags":["virtualbox","package","machine-state","export"],"backgroundTag":"invalid-machine-state","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}