Open
Close

Virtualbox console. Managing VirtualBox using the console. Installation and main components

1.Create a virtual machine named windows_xp
VBoxManage createvm --name windows_xp --regist er
The created virtual machine is an XML file that is located in the home directory /root/VirtualBox\ VMs/windows_xp/windows_xp.vbox
2. Next you need to create a virtual machine disk
VBoxManage createhd --filename /date/VirtualBox/windows_xp.vdi --size 15000 --variant Fixe d
By default, the disk is created in the user's home folder, we created the windows_xp.vdi disk in the /date/VirtualBox/ directory with a size of 15 gigabytes; the size is fixed, i.e. it does not increase dynamically.
3.Create a virtual disk controller
VBoxManage storagectl windows_xp --name "IDE Controller" --add ide --controller PIIX4
Using this command, an IDE controller is created with the name “IDE Controller”, the controller type is PIIX4.
4. Connect the virtual disk to the virtual machine:
VBoxManage storageattach windows_xp --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /date/VirtualBox/windows_xp.vdi

5.Connect the virtual image of the OS we want to install
VBoxManage storageattach windows_xp --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /date/public/winxp_pro_eng_sp3.iso

6. Set the RAM size for the virtual machine to 512MB
vboxmanage modifyvm windows_xp --memory 512

7. Set the system type VBoxManage modifyvm windows_xp --ostype WindowsX P
see all possible ostypes: VBoxManage list ostypes

8. Allow connecting to the console via RDP
vboxmanage modifyvm windows_xp --vrde on
To make it more convenient to manage virtual machines, you need a set of add-ons that includes USB 2.0 and a built-in RDP server. Download add-ons and install: wget http://dlc.sun.com.edgesuite.net/virtualbox/4.2.12/Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack

VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack

9. Launch the virtual machine
vboxheadless -s windows_xp or in the background:
VBoxManage startvm windows_xp --type headless
to run a guest OS on the host computer you are working with via ssh, you need to use the –type=headless key:

10. Connect via RDP ip_servera and install win_xp as usual

11.You can turn off the machine like this: VBoxManage controlvm windows_xp poweroff

12.Mount the VboxGuestAdditions disk
VBoxManage storageattach windows_xp --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso

Start the machine and install VboxGuestAdditions
13. Detailed information about a specific virtual OS can be obtained with the VBoxManage showvminfo windows_xp command

14. This command creates a bridged NIC network interface
VBoxManage modifyvm windows_xp --nic1 bridged --bridgeadapter1 eth0

15. If the virtual machine disk needs to be cloned, this is done using the VBoxManage utility:
VBoxManage clonehd /path/from/copying/image1.vdi /path/where/copying/image2.vdi
After this, everything connects wonderfully to the new virtual machine.

16.Create a shared folder with the server
vboxmanage sharedfolder add "windows_xp" --name share-name --hostpath /mnt
Connect shared folder from windows_xp execute
\\vboxsvr\share-name

Sometimes there is a need to run a virtual machine on a host without X. I will tell you how to do this, having access to the host system only via ssh + rdp (Remote Desktop Protocol). I will describe the process for OC Ubuntu 9.10 as a host.

Let's start by installing VirtualBox.

You must first install the dkms (Dynamic Kernel Module Support Framework) package:

Sudo apt-get install dkms

The site offers 2 options: register the package source (deb download.virtualbox.org/virtualbox/debian karmic non-free) in /etc/apt/sources.list or download and install the deb package. When I registered the source and did sudo apt-get install virtualbox-3.1, I got a bunch of dependency packages (including some for the GUI interface). Therefore, it is better to download the deb package. Download and install:

Sudo dpkg -i virtualbox-3.1_3.1.0-55467_Ubuntu_karmic_i386.deb

Perhaps dependencies will also be required here (some libraries for parsing xml, in which configs are stored, but there are significantly fewer of them than in the first case). If the installation did not complete due to dependencies, you can simply do

Sudo apt-get -f install

This will install dependencies and VirtualBox

OK. Installed VirtualBox. Let's start creating guest machines.

Let's create the car itself:

VBoxManage createvm --name ubuntu --ostype Ubuntu --register
(name - machine name, ostype - system type. A complete list of all types can be found with the VBoxManage list ostypes command)

Setting it up

VBoxManage modifyvm ubuntu --memory 512 --floppy disabled --audio none --nic1 bridged --bridgeadapter1 eth0 --vram 4 --accelerate3d off --boot1 disk --acpi on --cableconnected1 on --usb off --vrdp on --vrdpport 3390

Everything is clear here. You can also specify NAT as the network type (--nic1 nat). also enable rdp

Create a hdd disk for a virtual machine:

VBoxManage createhd --filename /home/user/vbox/ubuntu.vdi --size 20000 --register

Adding an IDE controller to our machine

VBoxManage storagectl ubuntu --name "IDE Controller" --add ide

We attach the previously created hdd to IDE0

VBoxManage storageattach ubuntu --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /home/user/vbox/ubuntu.vdi

On IDE1 we attach the installation image

VBoxManage storageattach ubuntu --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/user/vbox/iso/ubuntu-9.10-alternate-i386.iso

Telling the machine to boot from disk

VBoxManage modifyvm ubuntu --boot1 dvd

Let's start the car

In order to install the base system, we will use an rdp client (I have KDE, KRDC is included in the standard package). connect to the host machine on the port specified in the settings (--vrdpport 3390), install the system, do sudo apt-get install openssh-server . Now you can access the virtual machine via ssh

Stopping the virtual machine

VBoxManage controlvm ubuntu acpipowerbutton
via acpi

Or more harshly

VBoxManage controlvm ubuntu poweroff

We say it boots from the hdd

VBoxManage modifyvm ubuntu --boot1 disk

You can also unclip the installation disc

VBoxManage storageattach ubuntu --storagectl "IDE Controller" --port 1 --device 0 --medium none

And we start again

Nohup VBoxHeadless --startvm ubuntu &

More useful commands:

VBoxManage list runningvms
view all running machines

VBoxManage showvminfo ubuntu
viewing information about a virtual machine

Thus, on one machine with a minimally installed system, you can raise several virtual ones for various purposes and experiments

Virtualization...virtualization...
Nowadays everyone is trying to squeeze as much as possible out of their hardware resources. Having several separate computers with different operating systems is a little expensive and not all organizations will do it. But there is a way out, you can use virtual machines. And it is possible that many people use the wonderful product from Sun “VirtualBox” for these purposes. I'm sure that most people use the GUI interface for configuration, because... it is very clear and convenient. But how many people have thought about the possibility of managing VirtualBox via the console?
The task was set: to install two operating systems (Ubuntu and Windows) on one server. At the same time, there was a running server running Ubuntu 9.04 Server Edition. Therefore, it was decided to install Windows XP as a guest system.
But a problem arose on Ubuntu: no graphical environment was 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

Installing VirtualBox

Download the package for Ubuntu 9.04 from the official VirtualBox website
After downloading, run 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, check the error messages. You may not have the necessary packages installed. In my case I didn't have the package installed libxslt1.1, which was immediately fixed by the command sudo apt-get install libxslt1.1.
Add yourself to the group vboxusers
sudo usermod -a -G vboxusers username

Creating a virtual machine

To begin with, it is worth noting that to manage virtual machines through the console, one VBoxManage command is used (though it has a lot of parameters).
Let's begin.
  1. First, let's create a car and immediately register it
    VBoxManage createvm -name virtual_machine_name -register
  2. Next you need to create a disk for the machine
    VBoxManage createhd --filename disk_name --size disk_size in_megabytes
    It is possible to select the disk type VDI (VirtualBox), VMDK (VMWare), VHD (Microsoft Virtual PC). By default, of course, VDI :).
  3. We make additional settings for our virtual machine. Let us indicate:
    • Guest OS type. To get a list of supported operating systems, run the VBoxManage list ostypes command
    • Memory allocation size
    • Main disk name
    • Ability to use VRDP (VirtualBox Remote Desktop Protocol)
    VBoxManage modifyvm virtual_machine_name --ostype OS_type --memory memory_size in megabytes --hda disk_name --vrdp on
  4. Let's connect the disk image from which we will install Windows XP
    • Let's register a DVD with the system distribution image
      VBoxManage openmedium path_to_image
    • Let's insert our disk into the virtual drive
      VBoxManage modifyvm WindowsXP --dvd path_to_image
  5. Let's look at the settings of our machine. We make sure that everything suits us and...
    VBoxManage showvminfo machine_name

...Launch... Let's go

To start a virtual machine you need to run
VBoxManage startvm machine_name --type vrdp
Parameter --type vrdp needed to connect to the machine using VRDP
That's it, now all that remains is to connect to our machine using a remote desktop. This can be done using standard utilities: for windows it is mstsc, for x-based systems it is rdesktop. Since we only have a console, we need to use a computer that has a graphical desktop.
To connect, you need to specify the IP host of the machine and the port for this virtual machine. In my case, I didn't change anything and used the default port (3389). To change the port, run VBoxManage --vrdpport port. 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 easily connect to it using the VRDP protocol. I quietly installed Window XP while at my work computer.

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

Sometimes there is a need to run a virtual machine on a host without X. I will tell you how to do this, having access to the host system only via ssh + rdp (Remote Desktop Protocol). I will describe the process for OC Ubuntu 9.10 as a host.

Let's start by installing VirtualBox.

You must first install the dkms (Dynamic Kernel Module Support Framework) package:

Sudo apt-get install dkms

The site offers 2 options: register the package source (deb download.virtualbox.org/virtualbox/debian karmic non-free) in /etc/apt/sources.list or download and install the deb package. When I registered the source and did sudo apt-get install virtualbox-3.1, I got a bunch of dependency packages (including some for the GUI interface). Therefore, it is better to download the deb package. Download and install:

Sudo dpkg -i virtualbox-3.1_3.1.0-55467_Ubuntu_karmic_i386.deb

Perhaps dependencies will also be required here (some libraries for parsing xml, in which configs are stored, but there are significantly fewer of them than in the first case). If the installation did not complete due to dependencies, you can simply do

Sudo apt-get -f install

This will install dependencies and VirtualBox

OK. Installed VirtualBox. Let's start creating guest machines.

Let's create the car itself:

VBoxManage createvm --name ubuntu --ostype Ubuntu --register
(name - machine name, ostype - system type. A complete list of all types can be found with the VBoxManage list ostypes command)

Setting it up

VBoxManage modifyvm ubuntu --memory 512 --floppy disabled --audio none --nic1 bridged --bridgeadapter1 eth0 --vram 4 --accelerate3d off --boot1 disk --acpi on --cableconnected1 on --usb off --vrdp on --vrdpport 3390

Everything is clear here. You can also specify NAT as the network type (--nic1 nat). also enable rdp

Create a hdd disk for a virtual machine:

VBoxManage createhd --filename /home/user/vbox/ubuntu.vdi --size 20000 --register

Adding an IDE controller to our machine

VBoxManage storagectl ubuntu --name "IDE Controller" --add ide

We attach the previously created hdd to IDE0

VBoxManage storageattach ubuntu --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /home/user/vbox/ubuntu.vdi

On IDE1 we attach the installation image

VBoxManage storageattach ubuntu --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/user/vbox/iso/ubuntu-9.10-alternate-i386.iso

Telling the machine to boot from disk

VBoxManage modifyvm ubuntu --boot1 dvd

Let's start the car

In order to install the base system, we will use an rdp client (I have KDE, KRDC is included in the standard package). connect to the host machine on the port specified in the settings (--vrdpport 3390), install the system, do sudo apt-get install openssh-server . Now you can access the virtual machine via ssh

Stopping the virtual machine

VBoxManage controlvm ubuntu acpipowerbutton
via acpi

Or more harshly

VBoxManage controlvm ubuntu poweroff

We say it boots from the hdd

VBoxManage modifyvm ubuntu --boot1 disk

You can also unclip the installation disc

VBoxManage storageattach ubuntu --storagectl "IDE Controller" --port 1 --device 0 --medium none

And we start again

Nohup VBoxHeadless --startvm ubuntu &

More useful commands:

VBoxManage list runningvms
view all running machines

VBoxManage showvminfo ubuntu
viewing information about a virtual machine

Thus, on one machine with a minimally installed system, you can raise several virtual ones for various purposes and experiments