Last active
April 24, 2024 10:11
-
-
Save githubfoam/20b87e0447f7b579f1be8b02c36b6125 to your computer and use it in GitHub Desktop.
VirtualBox Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
========================================================================================================== | |
# 8. VBoxManage | |
https://www.virtualbox.org/manual/ | |
========================================================================================================== | |
# Networking Modes | |
https://www.virtualbox.org/manual/ch06.html#network_bridged | |
========================================================================================================== | |
Windows Host | |
>vboxmanage --version | |
6.0.12r133076 | |
========================================================================================================== | |
#Bard | |
In VirtualBox, the IP address 10.0.2.2 is used by default for the host machine. This means that if you are running a VM and you want to access a file or resource on the host machine, you can use the IP address 10.0.2.2. | |
For example, if you have a file on your host machine that you want to access from your VM, you can open a file explorer in the VM and navigate to the following path: | |
Code snippet | |
\\\10.0.2.2\path\to\file | |
Use code with caution. Learn more | |
You can also use the IP address 10.0.2.2 to access services that are running on the host machine. For example, if you have a web server running on your host machine, you can access it from your VM by opening a web browser and navigating to the following URL: | |
Code snippet | |
http://10.0.2.2 | |
Use code with caution. Learn more | |
It is important to note that the IP address 10.0.2.2 is only used by default. You can change the IP address of the host machine if you want. To do this, open the VirtualBox Manager and select the Settings option for the VM. In the Network tab, select the Adapter 1 or Adapter 2 drop-down menu and select Manual. Enter the desired IP address in the IP Address field. | |
It is also important to note that the IP address 10.0.2.2 may not be available in all cases. For example, if you are using a DHCP server to assign IP addresses to devices on your network, the IP address 10.0.2.2 may be assigned to another device. In this case, you will need to use the IP address that is assigned to the host machine by the DHCP server. | |
========================================================================================================== | |
#ChatGPT | |
In VirtualBox, the IP address 10.0.2.2 is a special address that allows communication between the host machine (the computer running VirtualBox) and the guest machine (the virtual machine running inside VirtualBox). Here's an explanation of its purpose and usage: | |
Network configuration: By default, VirtualBox sets up a network interface for the guest machine called "NAT" (Network Address Translation). This NAT interface enables the guest machine to access the external network using the host machine's network connection. | |
Host-guest communication: The IP address 10.0.2.2 is automatically assigned to the host machine on the NAT interface within the guest machine. This IP address acts as a gateway or bridge between the guest machine and the host machine. | |
Accessing host services: The guest machine can use the IP address 10.0.2.2 to access services running on the host machine. For example, if there is a web server running on the host machine, the guest machine can access it by connecting to 10.0.2.2 using a web browser. | |
Testing and development: The 10.0.2.2 address is particularly useful during development or testing scenarios when you need the guest machine to communicate with services or applications running on the host machine. It allows easy access to host resources from within the guest machine without requiring additional network configuration. | |
Limitations: It's important to note that the IP address 10.0.2.2 is specific to the VirtualBox NAT configuration and may not be accessible outside of the VirtualBox environment. It is not a universally routable IP address on the external network. | |
Overall, the IP address 10.0.2.2 in VirtualBox provides a convenient means of communication between the guest machine and the host machine, allowing the guest machine to access services or resources running on the host machine during development, testing, or other use cases. | |
========================================================================================================== | |
problem: move/copy VM manually and run | |
Cannot register the DVD image | |
C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso' with UUID {fc087cbc-df04-47b4-b42f-25f614463f78} already exists. | |
fix: edit ".VBOX" file and remove entries between tags | |
<DVDImages> | |
</DVDImages> | |
========================================================================================================== | |
#Bard | |
problem: after move/copy manually VM operation and run | |
explain how to fix this with vboxmanage CLI on windows 10 when booting windows 10 machine on virtualbox:Failed to open virtual machine located in C:/Users/john/VirtualBox VMs/win11/win11/win11.vbox. | |
Cannot register the DVD image 'C:\Users\john\VirtualBox VMs\win11\win11\Unattended-571d7825-4814-4db7-b975-95cd4a9e211b-aux-iso.viso' {c00c976a-e28c-4e6d-8c24-ddc6be861094} because a CD/DVD image 'D:\VirtualBox VMs\win11\win11\Unattended-571d7825-4814-4db7-b975-95cd4a9e211b-aux-iso.viso' with UUID {c00c976a-e28c-4e6d-8c24-ddc6be861094} already exists. | |
Result Code: | |
E_INVALIDARG (0X80070057) | |
Component: | |
VirtualBoxWrap | |
Interface: | |
IVirtualBox {7682d5eb-f00e-44f1-8ca2-99d08b1cd607} | |
> vboxmanage list dvds #list UUID | |
fix: | |
make backup of ".VBOX" file | |
edit ".VBOX" file, remove entries between tags, and boot VM | |
before | |
<AttachedDevice type="HardDisk" hotpluggable="false" port="0" device="0"> | |
<Image uuid="{c00c976a-e28c-4e6d-8c24-ddc6be861094}"/> | |
</AttachedDevice | |
after | |
<AttachedDevice type="HardDisk" hotpluggable="false" port="0" device="0"> | |
</AttachedDevice | |
========================================================================================================== | |
problem: | |
The virtual machine is being powered down, stuck | |
fix: | |
>VBoxManage startvm vbox-docker-01 --type emergencystop | |
========================================================================================================== | |
problem: | |
'VBoxManage' is not recognized as an internal or external command,operable program or batch file. | |
fix: | |
>set PATH=%PATH%;"C:\Program Files\Oracle\VirtualBox" | |
========================================================================================================== | |
Download VirtualBox Extension Pack | |
File > Preferences and select the Extensions tab. Click the add icon to install VirtualBox Extension Pack | |
========================================================================================================== | |
PS:for windows hosts | |
add the C:\Program Files\Oracle\VirtualBox directory to your PATH | |
# sharing folders bidirectional virtualbox | |
# host:windows guest:linux | |
Devices -> Shared Folders -> Shared Folders Settings -> Add (plus sign) -> Transient Folders -> Automount | |
# add user into vboxsf group | |
$ sudo usermod -a -G vboxsf sanchez | |
$ sudo grep vboxsf /etc/group | |
vboxsf:x:999:sanchez | |
"VBoxManage" command is different from "sudo VBoxManage" command | |
VBoxManage --version | |
sudo apt-get dist-upgrade -y -> Debian-based linux makes sure VirtualBox Guest Additions is installed | |
VBoxManage list runningvms -> Find running vm to box | |
vagrant package --base xxxxx_1522057296984_52705 --output ubuntu1604.box --> Package running vm as vagrant box | |
# Download an ISO image of VirtualBox Guest Additions http://download.virtualbox.org/virtualbox/ | |
wget -c http://download.virtualbox.org/virtualbox/5.2.12/VBoxGuestAdditions_5.2.12.iso -O VBoxGuestAdditions_5.2.12.iso | |
sudo mount -o loop VBoxGuestAdditions_5.2.12.iso /tmp/vbox | |
sudo sh /mnt/VBoxLinuxAdditions.run | |
lsmod | grep vboxguest -> verify vbox installation | |
modinfo vboxguest | |
#verify that Guest Additions are installed successfully | |
lsmod | grep vbox | |
========================================================================================================== | |
#troubleshooting windows 11 | |
The command VBoxManage list runningvms is used to list the VirtualBox virtual machines that are currently running on your system. It provides information about the name or UUID of the running virtual machines and their associated virtual machine groups. | |
To stop a running virtual machine, you can use the VBoxManage controlvm command with the poweroff option. Here's the syntax: | |
php | |
VBoxManage controlvm <VM_NAME_OR_UUID> poweroff | |
Replace <VM_NAME_OR_UUID> with either the name or the UUID of the virtual machine you want to stop. | |
For example, if you have a running virtual machine named "MyVM," you can stop it with the following command: | |
VBoxManage controlvm MyVM poweroff | |
Alternatively, if you know the UUID of the virtual machine, you can use it to stop the VM. First, list the running VMs to find the UUID: | |
VBoxManage list runningvms | |
Then, copy the UUID of the VM you want to stop and use it with the controlvm command: | |
php | |
VBoxManage controlvm <VM_UUID> poweroff | |
After executing the command, VirtualBox will initiate a clean shutdown of the virtual machine, giving it a chance to save its current state and close any open applications. If the virtual machine doesn't respond to the shutdown signal, VirtualBox will forcefully power off the VM. | |
Keep in mind that forcefully powering off a VM may lead to data loss or file system corruption if the guest operating system is not properly shut down. It's generally recommended to shut down the guest operating system from within the virtual machine whenever possible, as this allows it to perform the necessary cleanup tasks. | |
========================================================================================================== | |
https://www.virtualbox.org/manual/ | |
#troubleshooting | |
VBoxManage list vms | awk '{print $2;}' | |
VBoxManage list runningvms | awk '{print $2;}' | |
VBoxManage showvminfo vmid | |
VBoxManage showvminfo vmname | more | |
VBoxManage unregistervm --delete vmid | |
VBoxManage modifyvm vmid --name vmname | |
========================================================================================================== | |
#troubleshooting, windows 11 | |
Problem: | |
The UEFI Interactive Shell Opens Instead of Booting Windows 11 in Oracle Virtual Box | |
Fix: | |
Select the Windows 11 virtual machine and click the Settings icon | |
Go to the System settings found on the left-side panel and uncheck the box beside Enable EFI (special OSes only). Click OK. | |
========================================================================================================== | |
The UEFI Interactive Shell (also known as the UEFI Shell) is a command-line interface that provides low-level access and control over the Unified Extensible Firmware Interface (UEFI) firmware on a computer system. UEFI is the modern replacement for the traditional BIOS (Basic Input/Output System) and is responsible for initializing hardware components and launching the operating system. | |
When you see the UEFI Interactive Shell appear when booting a Windows 10 virtual machine in VirtualBox, it typically indicates an issue with the boot process. Here are a few possible reasons for this: | |
Incorrect boot order: The UEFI firmware tries to boot from different devices in a specific order specified in the BIOS settings. If the virtual machine's boot order is not properly configured, or if there is no valid bootable device available, the UEFI Shell may appear as a fallback option. | |
Missing or corrupted boot files: If the boot files required to start Windows 10 are missing or corrupted, the UEFI firmware may not be able to locate a valid bootloader. In such cases, it may drop into the UEFI Shell as a recovery measure. | |
VirtualBox configuration issues: Certain misconfigurations in VirtualBox can cause boot problems. For example, if the virtual hard disk file (VHD or VDI) is not properly attached or if the storage controller settings are incorrect, the UEFI Shell may be triggered. | |
To address the issue and boot into Windows 10 successfully, you can try the following steps: | |
Check the virtual machine's boot order settings in VirtualBox. Ensure that the virtual hard drive containing Windows 10 is set as the primary boot device. | |
Verify that the virtual hard disk file is properly attached to the virtual machine. In VirtualBox, go to the virtual machine's settings, navigate to the "Storage" section, and confirm that the correct disk image file is attached. | |
If you recently made changes to the virtual machine's configuration or upgraded VirtualBox, try reverting the changes or updating VirtualBox to the latest version. | |
If the issue persists, you may need to repair or reinstall the Windows 10 operating system within the virtual machine. You can try booting from a Windows 10 installation media (ISO file) within the virtual machine and perform the necessary repair steps. | |
If none of these steps resolve the issue, it may be helpful to provide more details about the specific error messages or behavior observed during the boot process in the UEFI Shell. | |
========================================================================================================== | |
#troubleshooting, windows 11 | |
Problem: | |
VERR_NEM_VM_CREATE_FAILED | |
Fix: | |
Control Panel-Programs-Programs and Features-Turn Windows features on or off-Windows Sandbox | |
========================================================================================================= | |
#https://www.virtualbox.org/manual/ch08.html#vboxmanage-storagectl | |
>VBoxManage storagectl vbox-chroot-79 --name disk1 --add sata | |
>VBoxManage storagectl vbox-chroot-79 --remove --name disk1 | |
>VBoxManage showvminfo vbox-chroot-79 --details | findstr Storage | |
VBoxManage storagectl vbox-chroot-79 --name disksata1 --add sata --hostiocache on | |
VBoxManage storagectl vbox-chroot-79 --name diskscsi1 --add scsi --hostiocache on | |
VBoxManage storagectl vbox-chroot-79 --name disksas1 --add sas --hostiocache on | |
VBoxManage storagectl vbox-chroot-79 --name controller-pcie1 --add pcie --hostiocache on | |
VBoxManage storagectl vbox-chroot-79 --name floppy1 --add floppy --hostiocache on | |
VBoxManage storagectl vbox-chroot-79 --name usb1 --add usb --hostiocache on | |
>VBoxManage closemedium disk nvme_disk1.vdi --delete | |
#For compatibility with earlier versions of Oracle VM VirtualBox, the createvdi and createhd commands are also supported and mapped internally to the createmedium command. | |
#https://www.virtualbox.org/manual/ch08.html | |
>VBoxManage createmedium #type for help | |
>VBoxManage createmedium --name vbox-chroot-79 --filename nvme_disk1 --variant Fixed --size 1024 | |
>vboxmanage --version | |
6.1.32r149290 | |
>VBoxManage createmedium --filename vdi_disk.vdi --format VDI --size 50000 | |
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | |
Medium created. UUID: 4c200422-b7d3-4287-b38d-a5b96dfef94c | |
>VBoxManage storageattach vbox-ubuntu-02 --storagectl SATA --type hdd --medium vdi_disk.vdi --port 0 --device 0 | |
>VBoxManage showmediuminfo disk 847f5e9c-e6e0-46d8-b826-868e7ea4fb4c | |
>VBoxManage list hdds | findstr nvme_disk1 | |
VBoxManage closemedium disk nvme_disk1.vdi --delete | |
VBoxManage storagectl vbox-chroot-79 --remove --name disk1 | |
>VBoxManage createmedium disk --filename nvme_controller_disk1 --format VDI --variant Fixed --size 1024 | |
>VBoxManage list hdds | findstr nvme_controller_disk1 | |
Location: C:\Users\veronica\nvme_disk1.vdi | |
>VBoxManage closemedium disk nvme_disk1.vdi --delete | |
>VBoxManage storagectl vbox-chroot-79 --name system-bus-pcie1 --add pcie --controller "NVMe" --portcount 1 --bootable off --hostiocache on | |
>VBoxManage storageattach vbox-chroot-79 --storagectl system-bus-pcie1 --type hdd --medium C:\Users\veronica\nvme_controller_disk1.vdi --port 0 | |
# command prompt format | |
VBoxManage createmedium --name vbox-chroot-79 --filename nvme_disk1 --variant Fixed --size 1024 | |
VBoxManage storagectl vbox-chroot-79 --name controllernvme1 --add pcie --controller "NVMe" --portcount 1 --bootable off --hostiocache on | |
VBoxManage storageattach vbox-chroot-79 --storagectl controllernvme1 --type hdd --medium nvme_disk1 --port 0 | |
# Vagrantfile format | |
vb.customize ["createmedium", "--filename", nvme_disk1, "--variant", "Fixed", "--size", "1024"] | |
vb.customize ["storagectl", :id, "--name", "controllernvme1", "--add", "pcie", "--controller", "NVMe", "--portcount", "2", "--bootable", "off", "--hostiocache", "on"] | |
vb.customize ["storageattach", :id, "--storagectl", "controllernvme1", "--type", "hdd", "--medium", nvme_disk1, "--port", "0"] | |
========================================================================================================== | |
#system buses/ controllers | |
VBoxManage closemedium disk nvme_disk1.vdi --delete | |
VBoxManage storagectl vbox-chroot-79 --remove --name disk1 | |
VBoxManage list hdds | findstr nvme_controller_disk1 | |
Location: C:\Users\veronica\nvme_disk1.vdi | |
VBoxManage closemedium disk nvme_disk1.vdi --delete | |
VBoxManage createmedium disk --filename nvme_controller_disk1 --format VDI --variant Fixed --size 4096 | |
VBoxManage storagectl vbox-controller-81 --name system-bus-pcie --add pcie --controller "NVMe" --portcount 2 --bootable off --hostiocache on | |
VBoxManage storageattach vbox-controller-81 --storagectl system-bus-pcie --type hdd --medium C:\Users\veronica\nvme_controller_disk1.vdi --port 0 | |
VBoxManage createmedium disk --filename LSILogicSAS_controller_disk1 --format VDI --variant Fixed --size 4096 | |
VBoxManage storagectl vbox-controller-81 --name system-bus-sas --add sas --controller "LSILogicSAS" --portcount 2 --bootable off --hostiocache on | |
VBoxManage storageattach vbox-controller-81 --storagectl system-bus-sas --type hdd --medium C:\Users\veronica\LSILogicSAS_controller_disk1.vdi --port 0 | |
VBoxManage createmedium disk --filename BusLogic_controller_disk1 --format VDI --variant Fixed --size 4096 | |
VBoxManage storagectl vbox-controller-81 --name system-bus-scsi --add scsi --controller "BusLogic" --portcount 16 --bootable off --hostiocache on | |
VBoxManage storageattach vbox-controller-81 --storagectl system-bus-scsi --type hdd --medium C:\Users\veronica\BusLogic_controller_disk1.vdi --port 1 | |
"existing system bus" | |
VBoxManage createmedium disk --filename LSILogic_controller_disk1 --format VDI --variant Fixed --size 4096 | |
VBoxManage storageattach vbox-controller-81 --storagectl system-bus-scsi --type hdd --medium C:\Users\veronica\LSILogic_controller_disk1.vdi --port 0 | |
"existing system bus" | |
VBoxManage createmedium disk --filename IntelAhci_controller_disk1 --format VDI --variant Fixed --size 4096 | |
VBoxManage storageattach vbox-controller-81 --storagectl ""SATA Controller" --type hdd --medium C:\Users\veronica\IntelAhci_controller_disk1.vdi --port 1 | |
"existing system bus" | |
VBoxManage createmedium disk --filename PIIX4_controller_disk1 --format VDI --variant Fixed --size 4096 | |
VBoxManage storageattach vbox-controller-81 --storagectl "IDE Controller" --type hdd --medium C:\Users\veronica\PIIX4_controller_disk1.vdi --port 0 --device 0 | |
--port 0,--device 0 primary master | |
VBoxManage createmedium disk --filename PIIX4_controller_disk1 --format VDI --variant Fixed --size 1024 | |
VBoxManage list hdds | findstr PIIX4_controller_disk1 | |
Location: C:\users\veronica\PIIX4_controller_disk1.vdi | |
VBoxManage storageattach vbox-chroot-79 --storagectl "IDE Controller" --type hdd --medium C:\users\veronica\PIIX4_controller_disk1.vdi --port 0 --device 0 | |
--port 0,--device 0 primary master | |
--port 1, --device 0 secondary master | |
--port 1,--device 1 secondary slave | |
--port 0,--device 1 secondary master | |
VBoxManage storagectl vbox-controller-81 --name "SATA Controller" --add sata --controller "IntelAhci" --portcount 1 --bootable off --hostiocache on | |
VBoxManage storagectl vbox-chroot-79 --name system-bus-scsi --add scsi --controller "LSILogic" --portcount 2 --bootable off --hostiocache on | |
VBoxManage createmedium disk --filename LSILogic_controller_disk1 --format VDI --variant Fixed --size 1024 | |
VBoxManage storageattach vbox-chroot-79 --storagectl system-bus-scsi --type hdd --medium C:\users\veronica\LSILogic_controller_disk1.vdi --port 0 | |
VBoxManage storagectl vbox-chroot-79 --name system-bus-sas --add sas --controller "LSILogicSAS" --portcount 2 --bootable off --hostiocache on | |
VBoxManage createmedium disk --filename LSILogicSAS_controller_disk1 --format VDI --variant Fixed --size 1024 | |
VBoxManage storageattach vbox-chroot-79 --storagectl system-bus-sas --type hdd --medium C:\users\veronica\LSILogicSAS_controller_disk1.vdi --port 0 | |
========================================================================================================== | |
VBoxManage: error: Cannot unregister the machine 'xx' while it is locked | |
sudo VBoxManage controlvm 'xx' poweroff | |
VBoxManage: error: The machine 'xx' is already locked for a session (or being unlocked) | |
sudo VBoxManage startvm 'xx' --type emergencystop | |
rm -fr ~/"VirtualBox VMs/NAMEOFVM" -> delete it manually | |
ps -ef | grep -i virtualbox | |
# Remove "VirtualBox Host-Only Ethernet Adapter" windows 10 | |
Device Manager -> Network Adapter -> right click -> uninstall device | |
# Remove "VirtualBox Host-Only Ethernet Adapter" windows 10, no GUI | |
VBoxManage list -l hostonlyifs | |
vboxmanage hostonlyif remove "VirtualBox Host-Only Ethernet Adapter #15" | |
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | |
# Create/Remove "VirtualBox Host-Only Ethernet Adapter" windows 10 | |
VBoxManage list hostonlyifs | |
VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.45.24 --netmask 255.255.255.0 | |
vboxmanage hostonlyif remove "VirtualBox Host-Only Ethernet Adapter" | |
VBoxManage list hostonlyifs | |
# Add/Remove an eighth NIC of hostonly networking to a existing VM | |
>VBoxManage list vms | |
"control-machine" {bbf0048b-57ad-4be6-9985-a8e06ffe7737} | |
>VBoxManage modifyvm "control-machine" --hostonlyadapter8 vboxnetX | |
>VBoxManage modifyvm "control-machine" --nic8 hostonly | |
>VBoxManage modifyvm "control-machine" --nic5 none | |
# Add/Remove an eighth NIC of hostonly networking to a existing VM, one-liner | |
VBoxManage modifyvm "control-machine" --nic8 hostonly --hostonlyadapter8 vboxnetX | |
VBoxManage modifyvm "control-machine" --nic9 none | |
------------------------------------------------------------------------------------------ | |
Windows Host | |
>vboxmanage --version | |
6.0.12r133076 | |
ISO download VirtualBox Guest Additions for Linux | |
http://download.virtualbox.org/virtualbox/ | |
Vbox Guest | |
$ wget http://download.virtualbox.org/virtualbox/6.0.12/VBoxGuestAdditions_6.0.12.iso | |
$ sudo mount -o loop,ro VBoxGuestAdditions_6.0.12.iso /mnt | |
$ sudo sh /mnt/VBoxLinuxAdditions.run --nox11 | |
reboot | |
$ lsmod | grep vboxguest | |
vboxguest 331776 1 | |
$ modinfo vboxguest | |
filename: /lib/modules/4.4.0-131-generic/misc/vboxguest.ko | |
version: 6.0.12 r133076 | |
license: GPL | |
description: Oracle VM VirtualBox Guest Additions for Linux Module | |
author: Oracle Corporation | |
srcversion: 72B364F5735D30373E34B7F | |
alias: pci:v000080EEd0000CAFEsv00000000sd00000000bc*sc*i* | |
depends: | |
retpoline: Y | |
vermagic: 4.4.0-131-generic SMP mod_unload modversions retpoline | |
$ lsmod | grep vbox | |
vboxguest 331776 1 | |
vboxvideo 40960 1 | |
ttm 98304 1 vboxvideo | |
drm_kms_helper 155648 1 vboxvideo | |
drm 364544 4 ttm,drm_kms_helper,vboxvideo | |
------------------------------------------------------------------------------------------ | |
create a closed network | |
VirtualBox > Preferences > Network tab > add a new network | |
------------------------------------------------------------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment