Useful and lesser-known features of VirtualBox
New Warehouses
VBoxManage lets you quickly create empty media in the current directory (Listing 2). The disc
option creates a disk image; alternatively, dvd
creates an empty DVD, or floppy
creates an empty floppy disk image. --size
is the size of the data carrier in megabytes.
Listing 2
Creating Empty Media
For hard disk images, the additional --format
parameter lets you explicitly specify the format: VDI
, VMDK
, or VHD
. The media is automatically registered by VBoxManage, so you will find it immediately in the VirtualBox Manager under File | Virtual Media Manager. If necessary, click on Update.
VBoxManage also lets you convert a hard disk image created with dd
to VDI, VHD, or VMDK format. The commands from Listing 3 load the contents of the disk /dev/sdc
into the disc.raw
image and convert it into the image.vdi
image.
Listing 3
Loading the Disk Contents
VirtualBox can also pass a real hard disk or partition directly into the virtual machine. To do this, you first need to create an image file of your physical data carrier. The command from Listing 4 creates a new image named file.vmdk
in the /home/tim/
folder. If you mount the image on a virtual machine, it directly accesses the /dev/sdc
drive. However, the whole procedure requires VirtualBox to have read and write access to the /dev/sdc
drive.
Listing 4
Creating a New Image
Intervention
If the Guest Additions are installed on the guest system, you can start programs directly on the guest with VBoxManage. The command from Listing 5 logs into the virtual machine with Fedora 29 as the user tim and a password of 123456; when it gets there, it launches the gedit text editor.
Listing 5
Launching an App on the Guest
--exe
is followed by the full path to the program you wish to execute. In the case of a Windows virtual machine, you need to enter the backslashes in the path twice, such as --exe "C:\\Windows\\System32\\calc.exe"
. For a graphical X11 application to launch on a Linux guest, you need to set the DISPLAY
environment variable using the --putenv
parameter. You can also add further parameters to the program (Listing 6).
Listing 6
Adding Parameters
The parameters are always at the end following the two minus signs. In the example, gedit/arg0
indicates that the parameters for the gedit
program follow next. In the example, this is just the complete path to the text file that you want gedit to open.
The guestcontrol
command gives an insight into the state of the guest system if required (Listing 7, first line). Among other things, guestcontrol
also lists the current processes. If a process is hanging, you can kill it with closeprocess
(second line). --session-id
is the ID of the session in which the process is running. The number at the end represents the process ID of the troublemaker.
Listing 7
guestcontrol
Conclusions and Outlook
Additional commands for VBoxManage, including numerous examples, are available in the comprehensive user manual for VirtualBox [1]. If you work regularly with VirtualBox, you should at least browse the table of contents of the user manual: It provides many hints for interesting functions that are often overlooked or forgotten in everyday life.
Infos
- VirtualBox user manual: https://www.virtualbox.org/manual/UserManual.html
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)