How to use the command 'VBoxManage unregistervm' (with examples)

How to use the command 'VBoxManage unregistervm' (with examples)

The ‘VBoxManage unregistervm’ command is used to unregister a virtual machine (VM) in VirtualBox. With this command, you can remove a VM from the VirtualBox environment and optionally delete associated files such as hard disk image files, saved state files, VM logs, and XML VM machine files. This article will provide examples for each of the use cases of the ‘VBoxManage unregistervm’ command.

Use case 1: Unregister an existing VM

Code:

VBoxManage unregistervm uuid|vm_name

Motivation: This use case is useful when you want to unregister a VM without deleting any associated files. By unregistering a VM, you can remove it from the VirtualBox environment but still keep the files intact.

Explanation:

  • ‘uuid|vm_name’: The ‘uuid’ can be the unique identifier of the VM or the ‘vm_name’ can be the name of the VM. You need to provide either the UUID or the name of the VM that you want to unregister.

Example output:

$ VBoxManage unregistervm "Ubuntu 20.04"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
VM 'Ubuntu 20.04' has been successfully unregistered.

Use case 2: Delete hard disk image files, all saved state files, VM logs, and XML VM machine files

Code:

VBoxManage unregistervm uuid|vm_name --delete

Motivation: In some cases, you may want to completely remove a VM and all associated files from the VirtualBox environment. This includes deleting hard disk image files, saved state files, VM logs, and XML VM machine files. This use case allows you to accomplish that.

Explanation:

  • ‘uuid|vm_name’: Same as in the previous use case.
  • ‘–delete’: This option tells the command to delete all associated files along with unregistering the VM.

Example output:

$ VBoxManage unregistervm "Ubuntu 20.04" --delete
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Deleting files: /path/to/hard_disk_image.vdi, /path/to/saved_state_file.sav, /path/to/vm_logs.log, /path/to/vm_machine.xml
VM 'Ubuntu 20.04' has been successfully unregistered and all associated files have been deleted.

Use case 3: Delete all files from the VM

Code:

VBoxManage unregistervm uuid|vm_name --delete-all

Motivation: Sometimes, you may want to delete all files related to a VM, even if it is already unregistered. This use case allows you to delete all files, including hard disk image files, saved state files, VM logs, and XML VM machine files, without the need to unregister the VM first.

Explanation:

  • ‘uuid|vm_name’: Same as in the previous use cases.
  • ‘–delete-all’: This option tells the command to delete all associated files, even if the VM is already unregistered.

Example output:

$ VBoxManage unregistervm "Ubuntu 20.04" --delete-all
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Deleting files: /path/to/hard_disk_image.vdi, /path/to/saved_state_file.sav, /path/to/vm_logs.log, /path/to/vm_machine.xml
All files associated with VM 'Ubuntu 20.04' have been successfully deleted.

Conclusion:

The ‘VBoxManage unregistervm’ command provides a way to unregister a VM in VirtualBox and optionally delete associated files. Whether you want to simply unregister a VM, delete associated files, or delete all files, this command offers the flexibility to suit your needs.

Related Posts

Interacting with Amass Database (with examples)

Interacting with Amass Database (with examples)

1: Listing all performed enumerations in the database The -list option in the amass db command allows you to list all the performed enumerations present in the database directory.

Read More
How to use the command "cfprefsd" (with examples)

How to use the command "cfprefsd" (with examples)

The cfprefsd command provides preferences services (CFPreferences, NSUserDefaults) and is used to start the daemon.

Read More
How to use the command 'autoflake' (with examples)

How to use the command 'autoflake' (with examples)

The ‘autoflake’ command is a tool used to remove unused imports and variables from Python code.

Read More