VBOXMANAGE - Base Guide
VM Management
Create a Virtual Machine
To create a new virtual machine from scratch: VBoxManage createvm --name "MyVM" --register
Example for adding a VM with specific settings: VBoxManage createvm --name "LinuxVM" --ostype "Linux_64" --register VBoxManage modifyvm "LinuxVM" --memory 2048 --cpus 2 --nic1 nat
Modify Virtual Machine
You can modify various properties of a VM, such as memory, CPU, or network settings.
Change memory allocation: VBoxManage modifyvm "LinuxVM" --memory 4096
Change number of CPUs: VBoxManage modifyvm "LinuxVM" --cpus 4
Start, Pause, and Stop a VM
Start a VM in headless mode: VBoxManage startvm "LinuxVM" --type headless
Pause a running VM: VBoxManage controlvm "LinuxVM" pause
Stop a VM gracefully: VBoxManage controlvm "LinuxVM" acpipowerbutton
Force stop a VM (hard shutdown): VBoxManage controlvm "LinuxVM" poweroff
Snapshot Management
Create a snapshot of a running VM: VBoxManage snapshot "LinuxVM" take "Snapshot1" --description "Before update"
Restore a snapshot: VBoxManage snapshot "LinuxVM" restore "Snapshot1"
List all snapshots for a VM: VBoxManage snapshot "LinuxVM" list
VM State and Saving
Save the current state of a VM: VBoxManage controlvm "LinuxVM" savestate
Delete a Virtual Machine
To completely delete a VM and all associated files: VBoxManage unregistervm "LinuxVM" --delete
Storage Management
Create a Virtual Disk
Create a new virtual hard disk (VHD): VBoxManage createhd --filename "/path/to/vm.vdi" --size 10240
Create a dynamic disk (size grows as data is added): VBoxManage createhd --filename "/path/to/vm.vdi" --size 10240 --variant Standard
Create a fixed-size disk: VBoxManage createhd --filename "/path/to/vm.vdi" --size 10240 --variant Fixed
Attach Storage to VM
Attach a virtual disk to a VM: VBoxManage storageattach "LinuxVM" --storagectl "SATA" --port 0 --device 0 --type hdd --medium "/path/to/vm.vdi"
Attach an ISO image to a VM (for installation): VBoxManage storageattach "LinuxVM" --storagectl "IDE" --port 0 --device 0 --type dvd --medium "/path/to/iso.iso"
Detach Storage from VM
Detach a virtual disk: VBoxManage storageattach "LinuxVM" --storagectl "SATA" --port 0 --device 0 --medium none
Network Management
Create and Attach Network Interfaces
Create a NAT network interface: VBoxManage modifyvm "LinuxVM" --nic1 nat
Create a bridged network interface: VBoxManage modifyvm "LinuxVM" --nic1 bridged --bridgeadapter1 "eth0"
Create an internal network interface: VBoxManage modifyvm "LinuxVM" --nic1 intnet
Modify Network Settings
Set the MAC address of a network interface: VBoxManage modifyvm "LinuxVM" --macaddress1 "080027001234"
View Network Configurations
Display network settings for a VM: VBoxManage showvminfo "LinuxVM" --details
Security Concepts
Virtual Machine Isolation
Ensure that VMs are isolated from each other to prevent unauthorized access. VirtualBox provides network modes like NAT and internal networks for this purpose.
Example of an isolated internal network: VBoxManage modifyvm "LinuxVM" --nic1 intnet
Securing VirtualBox Hosts
When running VirtualBox on Linux, it is essential to limit the access to the VirtualBox process to trusted users only. Use appropriate file permissions for VirtualBox configuration files and VM disks.
Check file permissions of VM files: ls -l /path/to/vm.vdi
To change file permissions: chmod 600 /path/to/vm.vdi
Virtual Machine Encryption
You can encrypt a virtual disk to protect its contents.
Enable disk encryption: VBoxManage encryptvm "LinuxVM" --password "securepassword"
Decrypt the virtual disk (requires password): VBoxManage decryptvm "LinuxVM" --password "securepassword"
Troubleshooting
VM Fails to Start =
If the VM fails to start, check the logs for errors: VBoxManage showvminfo "LinuxVM" --log
Ensure the VM has sufficient memory and CPU resources.
Network Issues in VM =
Verify the network interface settings for your VM: VBoxManage showvminfo "LinuxVM" --details
Check for correct bridged or NAT network settings and ensure the host machine has a working network connection.
VM Performance Issues =
If a VM is running slow, check if there are sufficient resources:
- Allocate more CPU or memory:
VBoxManage modifyvm "LinuxVM" --memory 4096 --cpus 2
- Check I/O performance of the virtual disk:
VBoxManage showvminfo "LinuxVM" --details
Disk Space Issues =
Ensure there is enough space for the virtual disk image on the host system.
Check disk space usage: df -h
Error: "Failed to open a session for the virtual machine" =
This could be due to permissions or resource issues. Ensure you have proper permissions to access the VM's files and that VirtualBox services are running correctly.
Check VirtualBox process: ps aux | grep VirtualBox
Restart the VirtualBox service: sudo systemctl restart vboxdrv
