LinuxCommandLibrary

vagrant-halt

Stops a running Vagrant virtual machine

TLDR

Halt the currently running Vagrant machine gracefully

$ vagrant halt
copy

Halt a specific machine by its ID or name gracefully
$ vagrant halt [id_or_name]
copy

Forcefully halt the current running machine(s) (This can affect multiple running machines if they are part of the same Vagrant environment)
$ vagrant halt [[-f|--force]]
copy

Forcefully halt a specific machine by its ID or name
$ vagrant halt [[-f|--force]] [id_or_name]
copy

SYNOPSIS

vagrant halt [vm-name] [--force]

PARAMETERS

vm-name
    Optional. Specifies the name of the virtual machine to halt. This is useful in multi-machine environments where you might want to stop only a specific VM. If omitted, Vagrant will attempt to halt the primary or all defined machines, depending on configuration.

--force, -f
    Forces the machine to power off immediately, skipping the graceful shutdown process. This is akin to pulling the power plug and should be used with caution, as it can lead to data loss or file system corruption if the guest OS is in an unstable state.

DESCRIPTION

The `vagrant halt` command is used to gracefully shut down and power off the running virtual machine(s) managed by Vagrant. It initiates a proper shutdown sequence within the guest operating system, similar to clicking 'Shut Down' from within the VM or executing a `shutdown -h now` command. This ensures that the operating system has a chance to properly close applications, flush data to disk, and unmount file systems, minimizing the risk of data corruption.

Unlike `vagrant suspend` (which saves the machine's state to disk for a quick resume) or `vagrant destroy` (which completely deletes the VM and all its associated data), `vagrant halt` is intended for simply turning off the machine while keeping its disk image and configuration intact for future use. If the graceful shutdown fails within a timeout period, Vagrant will automatically resort to a forceful power-off to ensure the machine stops.

CAVEATS

Using the `--force` option can lead to data loss or file system corruption, as it bypasses the operating system's graceful shutdown procedures.
For graceful shutdown to function correctly, Vagrant Guest Additions should be installed and running within the virtual machine. If guest additions are not present or the guest OS is unresponsive, Vagrant will eventually time out and perform a forceful power-off regardless.

GRACEFUL SHUTDOWN MECHANISM

When `vagrant halt` is executed without the `--force` flag, Vagrant first attempts to communicate with the guest operating system (typically via SSH or Vagrant Guest Additions) to send a shutdown command. This allows the OS to perform an orderly shutdown, including unmounting file systems and stopping services. Only if this graceful attempt fails or times out does Vagrant resort to directly instructing the hypervisor to power off the machine.

MULTI-MACHINE ENVIRONMENTS

In Vagrant environments with multiple defined virtual machines, running `vagrant halt` without specifying a vm-name will typically attempt to halt all active machines defined in the `Vagrantfile`. To halt a specific machine, its name must be provided as an argument, e.g., `vagrant halt webserver`.

HISTORY

Vagrant, created by Mitchell Hashimoto, began development in 2010. The `vagrant halt` command has been a fundamental and indispensable part of Vagrant's core functionality since its early versions. It embodies Vagrant's philosophy of providing a simple, consistent, and intuitive command-line interface for managing virtual development environments, abstracting away the complexities of underlying hypervisors and ensuring proper VM lifecycle management.

SEE ALSO

vagrant up, vagrant suspend, vagrant resume, vagrant destroy, vagrant reload

Copied to clipboard