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.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Networking with VirtualBox

    Tour the VirtualBox virtualization tool, a free and easy environment for virtual versions of Linux, Unix, and Windows.

  • Virtual Box

    Many popular virtualization tools are either too expensive or too complicated. If you’re looking for another option, try the no-cost and user-friendly VirtualBox.

  • phpVirtualBox

    Putting all virtualization tasks on a separate server saves significant resources on the client. phpVirtualBox makes it possible to create, configure, manage, and use remote VMs in a browser window.

  • Virtualization Tools

    Running server systems in virtual environments is a popular approach, but the technology offers benefits to desktop users. In this article, we investigate some virtual desktop alternatives.

  • QEMU and Qemu Manager

    Carry a virtual Linux machine with you wherever you go.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News