📜 ⬆️ ⬇️

Manage VirtualBox using the console

Virtualization ... virtualization ...
Now everyone is trying to squeeze out as much as possible from their hardware resources. Having several separate computers with different operating systems is a bit expensive and not all organizations will go for it. But there is a solution, you can use virtual machines. And it is possible that many use for this purpose a wonderful product from Sun "VirtualBox". I am sure that most of the settings use the GUI interface, since it is very visual and convenient. But how many people thought about the possibility of managing VirtualBox through the console.
The task was set: To install two OSes on one server (Ubuntu and Windows). At the same time there was a working server running Ubuntu 9.04 Server Edition. Therefore, it was decided to put Windows XP as a guest.
But there was a problem on Ubuntu. No graphical environment was installed, i.e. there is only a bare console.

So, what we have is:

Install VirtualBox


Download from the official site of VirtualBox package for Ubuntu 9.04
Once downloaded, execute the command:
dpkg -i virtualbox-2.2_2.2.2-46594_Ubuntu_jaunty_i386.deb
VirtualBox should install. If you have problems installing the package, review the error message. You may not have the necessary packages installed. In my case, I did not have the libxslt1.1 package installed, which was instantly fixed by the sudo apt-get install libxslt1.1 command sudo apt-get install libxslt1.1 .
Add yourself to the vboxusers group
sudo usermod -a -G vboxusers _

Create a virtual machine


To begin with, it is worth noting that one command VBoxManage is used to manage virtual machines via the console (although it has a lot of parameters).
Let's start.
  1. To start, create a car and immediately register it.
    VBoxManage createvm -name __ -register
  2. Next, you need to create a disk for the machine.
    VBoxManage createhd --filename _ --size ___
    It is possible to choose the type of VDI (VirtualBox), VMDK (VMWare), VHD (Microsoft Virtual PC) disk. By default, of course, VDI :).
  3. We make additional settings for our virtual machine. We indicate:
    • Type of guest OS. For a list of supported OS, run the command VBoxManage list ostypes
    • Size of memory allocated
    • The name of the main disk
    • Ability to use VRDP (VirtualBox Remote Desktop Protocol)
    VBoxManage modifyvm __ --ostype _ --memory ___ --hda _ --vrdp on
  4. Connect the disk image from which we will install Windows XP
    • Let's register a DVD with the image of the system distribution kit.
      VBoxManage openmedium __
    • Insert our disk in a virtual drive
      VBoxManage modifyvm WindowsXP --dvd __

  5. Let's look at the settings of our car. We are convinced that everything suits us and ...
    VBoxManage showvminfo _


... Running ... Let's go


To start the virtual machine you need to run
VBoxManage startvm _ --type vrdp
The --type vrdp parameter is needed to connect to the machine using VRDP
Everything is now left to connect to our machine, via remote desktop. This can be done using standard utilities: for windows, this is mstsc, for nix systems, rdesktop.TK. we only have a console, we need to use a computer that has a graphical desktop.
To connect, you need to specify the host IP of the machine and the port for this virtual machine. In my case, I did not change anything and used the default port (3389). To change the port, run the VBoxManage --vrdpport . If you have several virtual machines installed, then in order to connect to each of them, you need to specify different ports in the settings, for example, for the first machine 3389, for the second 3390, etc.


Instead of an epilogue


Now we have a virtual machine running and we can safely connect to it using the VRDP protocol. I calmly installed Window XP, being at my desktop computer.
')
PS Windows XP was needed for one reason only. The project had to use MS SQL Server.

Useful links:


VBoxManage documentation

UPD: bsdemon suggested another way. Use libvirt

Source: https://habr.com/ru/post/60325/


All Articles