Managing VirtualBox Using the Console

    Virtualization ... virtualization ...
    Now everyone is trying to squeeze as much out of their hardware resources as possible. Having several separate computers with different operating systems is a little 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 are using Sun’s wonderful VirtualBox product for these purposes. I am sure that most of them use the GUI interface for configuration, as It is very clear and convenient. But how many have thought about the possibility of managing VirtualBox through the console.
    The task was set: To put two OS (Ubuntu and Windows) on one server. At the same time, there was a working server running Ubuntu 9.04 Server Edition. Therefore, it was decided to install Windows XP as a guest system.
    But there was a problem on Ubuntu NO GUI installed, i.e. there is only a bare console.

    So what we have:
    • Host system: Ubuntu 9.04 Server Edition
    • VirtualBox 2.2.2
    • Guest System: Windows XP

    Install VirtualBox


    Download the package for Ubuntu 9.04 from the official VirtualBox website. After downloading, we execute the command: VirtualBox should be installed. If you have problems installing the package, examine 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 command . Add yourself to the vboxusers group

    dpkg -i virtualbox-2.2_2.2.2-46594_Ubuntu_jaunty_i386.deb
    sudo apt-get install libxslt1.1

    sudo usermod -a -G vboxusers имя_пользователя

    Creating a virtual machine


    To begin with, it is worth noting that to manage virtual machines through the console, one VBoxManage command is used (although it has a lot of parameters).
    Let's get started.
    1. First, create a car and register it right away
      VBoxManage createvm -name имя_виртуальной_машины -register
    2. Next, you need to create a disk for the machine. It
      VBoxManage createhd --filename имя_диска --size размер_диска_в_мегабайтах
      is possible to select the type of disk VDI (VirtualBox), VMDK (VMWare), VHD (Microsoft Virtual PC). By default, of course, VDI :).
    3. We make additional settings for our virtual machine. We indicate:
      • Type of guest OS. To get a list of supported OSs, run the commandVBoxManage list ostypes
      • Allocated memory size
      • 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
      • Register DVD with system distribution image
        VBoxManage openmedium путь_до_образа
      • Insert our disk into the 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 имя_машины


    ... Launch ... Let's go


    To start the virtual machine it is necessary to perform
    VBoxManage startvm имя_машины --type vrdp
    parameter --type vrdp need to connect to the machine using VRDP
    all, now it is necessary to connect to the car, with the help of remote desktop. This can be done using standard utilities: for windows it is mstsc, for nix systems rdesktop. Since we only have a console, we need to use a computer that has a graphical desktop.
    To connect, you must specify the IP host 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, doVBoxManage --vrdpport порт. If you have several virtual machines installed, 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 easily connect to it using the VRDP protocol. I quietly installed Window XP while at my work computer.

    PS Windows XP was needed for only one reason. The project needed to use MS SQL Server.

    Useful links:


    VBoxManage UPD documentation

    : bsdemon suggested another way. Use libvirt

    Also popular now: