Console commands VirtualBox

VirtualBox is one of the most popular virtualization systems open source for Windows and Linux. Because of the free distribution program has gained immense popularity, and the developers have added many useful features. Standard users and myself included, are accustomed to use the VirtualBox GUI.

It is simple and convenient. However, if you install VirtualBox on the server, there is no graphical interface. But you can do the same and more with console commands VirtualBox. These teams very much. In this article we consider the most useful console commands VirtualBox. The end of the article you will have a fully configured and working virtual machine.

Basic commands VirtualBox

Management of virtual machines in the terminal by using the command VBoxManage. It has a fairly simple syntax:

$ VBoxManage Abdiel team optiimal

I am not going to consider all options and commands VirtualBox, consider them in the process. By default, all virtual machines are in the directory .config/VirtualBox/Machines. However, you can change this path by using the setproperty command. For example, /home/virtualbox/:

VBoxManage setproperty machinefolder /home/virtualbox/

1. Create a virtual machine

The first step is to create a new virtual machine with which we will work. Each virtual machine is nothing like the XML settings file. Create a virtual machine running VirtualBox with the command VBoxManage createvm. Here are the main options:

  • –name – the name of the machine;
  • –ostype – type of operating system;
  • –register – registers the virtual machine, otherwise it will be just created XML settings file.

The list of available types of operating systems can be viewed with the command:

VBoxManage list ostypes

Let’s create a virtual machine for Ubuntu and will register it in the system:

VBoxManage createvm --name "Ubuntu1804" --ostype "Ubuntu_64" --default --register

The virtual machine is successfully created and added.

2. Adding an existing machine

If you migrated a virtual machine from another system, you may want to add it. This is analogous to the open item in the GUI menu. Use the command VBoxManage registervm, which is the argument you need to pass the path to the file virtual machine:

VBoxManage registervm /home/sergiy/VirtualBox VMs/Ubuntu1804/Ubuntu1804.vbox

3. The list of virtual machines

To make sure that everything works you may want to look at the list of virtual machines. This can be done with the command:

VBoxManage list vms

Or you can see the list of running VMS:

VBoxManage list runningvms

To see more detailed information about virtual machines, use the option –long:

VBoxManage list vms --long

4. Configure storage machine

By default it creates only virtual machine configuration. It has no repository that will host the operating system. Now we add it. You first need to create a hard disk in a folder next to the file of the virtual machine:

VBoxManage createhd --filename "/home/sergiy/VirtualBox VMs/Ubuntu1804/Ubuntu1804.vdi" --size 10000 --format VDI

Here you need to pass the file path for the future of disk and its size in megabytes. I create the disk to 10 gigabytes. This should be enough to run the test system. Then, using commands storagectl and storageattach add a SATA controller and connect the drive:

VBoxManage storagectl "Ubuntu1804" --name "SATA Controller" --add sata --controller IntelAhci

VBoxManage storageattach "Ubuntu1804" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "/home/sergiy/VirtualBox VMs/Ubuntu1804/Ubuntu1804.vdi"

Parameter –medium necessary to convey the file path of the drive you are going to connect. If you want to get the machine to boot from an ISO image, you still need the IDE controller:

VBoxManage storagectl "Ubuntu1804" --name "IDE Controller" --add ide --controller PIIX4

You can then connect your way:

VBoxManage storageattach "Ubuntu1804" --storagectl "IDE Controller" --port 1 --device 0 --type DVD drive --medium ~/ubuntu.iso

5. Remote access

Since the virtual machine on the server, access to graphical interface no, but we need to access the machine. For this we can use the RDP Protocol. To enable remote access, use the command:

VBoxManage modifyvm "Ubuntu1804" --vrde on

You can also change the RDP port on the one you want, for example, 33891:

VBoxManage modifyvm "Ubuntu1804" --vrdeport 33891

Now we can get access to this machine, but let’s set up password authentication so no one else could access it if the server is accessible from the Internet. First set the authentication type to external:

VBoxManage modifyvm --Ubuntu1804 vrdeauthtype external

We note that it is necessary to use the authorization module VBoxAuthSimple:

VBoxManage setproperty vrdeauthlibrary VBoxAuthSimple

It remains to choose a username and password. Let it be losst_user and losst_password. Create a hash for our password:

VBoxManage internalcommands passwordhash losst_password

It remains to associate this hash with username losst_user for our machine:

VBoxManage setextradata "Ubuntu1804" "VBoxAuthSimple/users/losst_user" 4a26e3cde3647806539e746d4b7fa27401af9198ac0da1a5122e8851648566d2

Configuring rdp, virtualbox is now completed and the machine will be accessible over the network. You will connect with the utility Reminna. You only have to run it.

6. Install VirtualBox Extpack

If you want to use remote access VirtualBox, you need to install the VirtualBox extensions for your version of the program. First look have you installed these extensions:

VBoxManage list extpacks

The system reports that I have installed one set of extensions. We would be interested in stitching VRDE Module. Its value must be RDP, not VNC and not anything else.

To install the extension first see your version of VirtualBox:

VBoxManage --version

For my version 5.2 expansion sets can be found on this page. You’ll find the right extpack using search. Then upload it to your server and install with the command:

VBoxManage extpack install ~/filepath.extpack

After installation it will appear in the list.

7. Hardware setup

As I said, the default machine are given the most minimal resources, with so many resources can run low on modern systems. So let’s give the virtual machine more RAM:

VBoxManage modifyvm "Ubuntu1804" --memory 2048

To increase the amount of video memory in virtualbox, execute:

VBoxManage modifyvm "Ubuntu1804" --vram 128

The amount of memory required in megabytes. So the changes worked, the machine must be switched off. Next, give the machine two processor core:

VBoxManage modifyvm "Ubuntu1804" --cpus 2

Now, with such parameters we can work with.

8. Control state machine

To start the virtual machine, use the command startvm. So how do we run it without graphics, use the option –type headless:

VBoxManage startvm "Ubuntu1804" --type headless

After the vehicle has been started, you can open it with a reminna:

Further, to control the running machine, use the command controlvm. It allows you to put the machine on pause or stop it. To put the machine on pause use the pause command:

VBoxManage controlvm "Ubuntu1804" pause

For the withdrawal of the machine from the pause state:

VBoxManage controlvm "Ubuntu1804" resume

To completely power off the machine:

VBoxManage controlvm "Ubuntu1804" poweroff

If you don’t want to turn off the machine, you can save it as:

VBoxManage controlvm "Ubuntu1804" savestate

Or you can send a signal of pressing the button:

VBoxManage controlvm "Ubuntu1804" acpipowerbutton

If your car beat interrupted by restarting the computer or turning off lights can be a situation that it will remain locked and you will not be able to start it. To resolve this problem, use the command:

VBoxManage startvm "Ubuntu1804" --type emergencystop

Our paper is nearing completion, but it’s not all console commands VirtualBox.

9. View information about the machine

View information about the current state of the machine, and the equipment using the showvminfo command:

VBoxManage showvminfo "Ubuntu1804"

If you are only interested in the status of the machine, you can filter the output of the virtualbox cli utility grep:

VBoxManage showvminfo "Ubuntu1804" | grep State

Insights

In this article we have considered useful commands VirtualBox CLI, which will allow you to fully manage virtual machines on the server. I did not give details about the setting of the disk size, you can all be read in the article how to increase disk size of VirtualBox. Of course, there are many other interesting commands that do not fit in this article, such as configuring automatic installation system, network setup, changing equipment on the fly, and much more.

Source: losst.ru

(Visited 10 times, 2 visits today)