VirtualBox (Oracle): Difference between revisions
| (One intermediate revision by the same user not shown) | |||
| Line 20: | Line 20: | ||
Now you can start your VM with double click on the new link. If your VM has a weird name, put it into quotes. |
Now you can start your VM with double click on the new link. If your VM has a weird name, put it into quotes. |
||
A possible parameter is |
|||
--type headless |
|||
=== shutdown a virtual machine === |
=== shutdown a virtual machine === |
||
| Line 170: | Line 173: | ||
It somehow does not work (for me) for Windows. |
It somehow does not work (for me) for Windows. |
||
I can start Windows headless if I do it explicitly but not via default and this change. |
I can start Windows headless if I do it explicitly but not via default and this change. |
||
If you use commands to start the VM, you can do |
|||
VBoxManage startvm "VM Name" --type headless |
|||
=== Guest Addition, Debian === |
=== Guest Addition, Debian === |
||
Latest revision as of 21:40, 10 January 2026
command line
https://www.oracle.com/technical-resources/articles/it-infrastructure/admin-manage-vbox-cli.html
setup
Find "VBoxManage.exe" and either put it into the PATH variable or make sure your calls see the .exe. If you just plan to create some scripts, you should not need to modify the PATH variable, but if you really want to work with the command line with VirtualBox, then you really should put it into your path.
start a virtual machine without starting the GUI "VirtualBox Manager"
- list your VMs
VBoxManage list vms
- right click on your desktop: New shortcut...
- browse to VBoxManage.exe (location of the item)
- Next
- Name: "Start v-dev" or whatever makes sense for the VM you will be starting
- Finish
- Right click the new link / Properties
- in the "Target" line behind the .exe insert a space and give as parameters "startvm <name from 'list vms'>"
D:\tools\system\VirtualBox\VBoxManage.exe startvm v-dev
- OK
Now you can start your VM with double click on the new link. If your VM has a weird name, put it into quotes.
A possible parameter is
--type headless
shutdown a virtual machine
- Do the same as for when you start a virtual machine.
- Do not append startvm but instead add
controlvm <name from "list vms"> acpipowerbutton
Misc
ssh (port forwarding)
If you do not want to have the machine attackable in the normal network you will set the network as NAT. If you now want to connect to services of the machine, you'd have to know the current IP. You can circumvent this problem.
machine/Settings/Network/Advanced/Port Forwarding
| Name | Protocol | Host IP | Host Port | Guest IP | Guest Port |
|---|---|---|---|---|---|
| ssh | TCP | 127.0.0.1 | 40022 | (empty) | 22 |
Now you can ssh to localhost at port 40022.
In this context, should you have problems with X11 programs, consider to install the X-Server VcXsrv and check DISPLAY of VM via ssh.
http example for Redmine (port forwarding)
machine/Settings/Network/Advanced/Port Forwarding
| Name | Protocol | Host IP | Host Port | Guest IP | Guest Port |
|---|---|---|---|---|---|
| http | TCP | 40082 | 80 |
Now open c:\Windows\System32\drivers\etc\hosts as admin so you can edit it and find the line
127.0.0.1 localhost
You add something like v-redmine.local.net so you'll have now:
127.0.0.1 localhost v-redmine.local.net
It is IMPORTANT that you use the correct domain and subdomain here. You will perhaps NOT have "local.net" but something else which you decided when you installed your virtual server. In doubt, check the 'hosts' file of the virtual machine.
I am not sure if you need to boot but you will probably have to restart your browser.
Then you can access
http://v-redmine.local.net:40082/my/page
and work with redmine as usual.
You'll probably want shortcuts with
C:\Tools\System\VirtualBox\VBoxManage.exe startvm v-redmine
and
C:\Tools\System\VirtualBox\VBoxManage.exe controlvm v-redmine acpipowerbutton
Windows Remote Desktop Connection RDP (port forwarding)
If you do not want to have the machine attackable in the normal network you will set the network as NAT. If you now want to connect to services of the machine, you'd have to know the current IP. You can circumvent this problem.
machine/Settings/Network/Advanced/Port Forwarding
| Name | Protocol | Host IP | Host Port | Guest IP | Guest Port |
|---|---|---|---|---|---|
| RDP (TCP) | TCP | (empty) | 43389 | (empty) | 3389 |
| RDP (UDP) | UDP | (empty) | 43389 | (empty) | 3389 |
- Now allow RDP connections to the guest machine via "Remote Desktop Settings"
- Now you open a RDP connection from the host to the guest via localhost:43389
Headless start
When you don't want to use the machine via the view opened by VirtualBox but instead with RDP or ssh, then you don't want an extra window to be opened when you start a VM. Headless start (selectable with the combo of the "play" button) can be set as the default, so you don't have to select "headless" in the list each time you start a VM.
- Close all virtual machines
- close VirtualBox GUI
- BOOT (Not joking here, BOOT!)
- You set a directory for your VMs.
- There you will find a .vbox for each VM.
- do the following changes:
In the .vbox search for (can be there multiple times, find the right one or do them all)
<Clipboard/> <GuestProperties>
Add <Frontend> like in the following sample:
<Clipboard/> <Frontend> <Default type="headless"/> </Frontend> <GuestProperties>
The exact spot is not important. What is important is that the entry has this level.
It somehow does not work (for me) for Windows. I can start Windows headless if I do it explicitly but not via default and this change.
If you use commands to start the VM, you can do
VBoxManage startvm "VM Name" --type headless
Guest Addition, Debian
- In Settings/Storage/Controller:IDE
- Choose Virtual Optical Disk File from the folder where you installed VirtualBox
- C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso
- In der Console in Debian
sudo apt-get install gcc make perl sudo apt-get install 'linux-headers-'`uname -r`
- cd /media/cdrom
- sudo sh VBoxLinuxAdditions.run
- Debian booten (System/Shutdown.../Restart)
If the simple mount of the VirtualBox\VBoxGuestAdditions.iso does not work:
- look at the system
lsblk -f
- mount manually (depending on the output of the previous command, /dev would not be shown for sr0 for example
cd /media mount /dev/sr0 cdrom
Linked clone versus full clone
- You can later change the linked clone to a full clone
- the linked clone only saves the difference
- When a linked clone is created, a snapshot is created in the base image
- Without the base image the linked clone can't operate
- example:
- debian console installation: 3 GB
- linked clone directly after cloning: 2 MB (yes, that is no error, MB!)
After cloning a Debian machine, what to change
- /etc/hostname
- /etc/hosts (normally two changes in this file)
- Ports you forward
No internet for the guest machine
Add a 2nd network adapter in "host-only" mode. Then you can enable or disable the original adapter as needed without having to remember the details.
Automatic DHCP
Under File/Tools/Network is the area where you setup the ip range of automatically given IPs. Make sure to match this somewhat with your real network or you will have problems to connect with certain tools. Ssh will not work from 192.168.150.* to 192.168.50.* but MS Remote Desktop Connection will work.