Virtualbox setting up a Windows guest from a Linux console. Managing VirtualBox using the console Virtualbox console

1.Create virtual machine named windows_xp
VBoxManage createvm --name windows_xp --regist er
The created virtual machine is XML file, which 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 controller virtual disks
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 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 size random access memory for virtual machine 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 protocol
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 switch:

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

We 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 network interface Bridge type NIC
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


Posted by Ken Hess
Date of publication: January 18th, 2010
Translation: N. Romodanov
Translation date: February 2010

Regular VirtualBox users may not be aware of the enormous power that lies within the command line interface.

People usually ask: "Why use the command line when you have a perfectly good GUI?" The answer is the enormous power of the command line. Since 1995, there has been a whole generation of computer users who believe that a computer is a collection of windows and graphics, but in reality this is very far from the truth. Why, 1995, you ask? WITH the advent of Windows 95 in 1995, a new computer era was opened - the era of graphical interfaces. Shortly after that fateful August, FVWM95 was released, which was Linux's answer to the Windows 95 Explorer interface. It seems to me that in those good old days command line disappeared forever. Nobody wanted to use DOS anymore and they stopped being afraid of Linux. But the command line is still alive and well in the Linux environment. It's still quite alive in Windows. And now that Macs are Unix-based, they also have a lot of things that don't require a GUI.

It may come as a surprise to you that underneath VirtuaBox's pretty GUI, with its colorful graphics, clear Settings page, and big amount drop-down lists, the occult world of the command line lurks. The true power of this dark world will only be revealed to those who dare to enter these musty catacombs. After you deal with the command line VirtualBox, you might decide that the GUI is little more than just a pretty drapery designed for those who would otherwise simply ignore the boring black rectangle of an actual working application.

The Power of the Command Line

The black rectangle I was talking about is the terminal window. The command line allows you to take full advantage of the power of automatic command execution. The only way automation, which is known to me in *nix systems, is the use of scripts written in Perl, shell scripts or scripts in some other language. And the system scheduler daemon (cron) will help you right time run the script. This is the power of the command line, which, thanks to the ability to run automatically, which also requires system administrators to be able to write scripts, is their skill set. In every vacancy that requires System Administrator, it will be indicated that the applicant must be able to write scripts in at least one of the interpreted languages ​​listed in the vacancy.

When it comes to virtualization, the command line allows you to quickly create virtual disks, add a new network interface, launch virtual machines, and create new virtual machines, all without using a GUI. Automatic execution using scripts will also allow you to schedule the start and stop of virtual machines without your direct intervention. And, if you're a really great scripter, you can write a script that will guide you, with minimal intervention on your part, to create a virtual machine, run it, or install and change it. If you don't like doing everything manually, you'll make a list of the virtual machines you use all the time, then set up scripts (templates) for each type of virtual machine you use and, if necessary, create a virtual machine within seconds.

Let's look at simple and elegant functionality command line in VirtualBox.

Installation and main components

Use the VirtualBox Linux Downloads link to download the binary distribution designed for your system. If you want, you can download source. For the option I chose (for RHEL5/CentOS5 in rpm format), the following directories were created:

  • For binary modules - /usr/lib/virtualbox with links from /usr/bin
  • For libraries - /usr/lib/virtualbox
  • For source codes - /usr/share/virtualbox
  • For guest components (ISO) - /usr/share/virtualbox

If your distribution does not have latest version VirtualBox (version 3.1.2 at the time of this writing), then use one of the packages that can be downloaded, or download the source code.

Creating and configuring a virtual machine

The hardest thing about using the command line is knowing where to start. IN graphical interface you need to use the New button. The command line reveals its secrets a little more complexly. In order to create and configure a new virtual machine, you must open a terminal window, or use an ssh session to access the Linux system on which VirtualBox is installed, and run the following command:

$ /usr/bin/VBoxManage createvm --name Debian5 –register

This command creates a new virtual machine named Debian5 and registers it with VirtualBox. The created virtual machine is an XML file that is located in the home directory ~/.VirtualBox/Machines/Debian5/Debian5.xml.

Create a virtual disk for your virtual machine:

$ /usr/bin/VBoxManage createhd --filename Debian5.vdi --size 4000 --variant Fixed

You have created a virtual disk named Debian5.vdi with a size of 4 GB (4000 MB); the size is fixed, i.e. it does not increase dynamically.

The virtual disk is created as a file ~/.VirtualBox/HardDisks/Debian.vdi

Create a disk device controller to which you will attach the virtual disk and virtual CD/DVD device

$ /usr/bin/VBoxManage storagectl Debian5 --name "IDE Controller" --add ide --controller PIIX4

This command creates an IDE controller named “IDE Controller”, the controller type is PIIX4.

Now let's connect the virtual disk to your virtual machine:

$ /usr/bin/VBoxManage storageattach Debian5 --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium Debian5.vdi

Connecting ISO image that operating system you want to install:

$ /usr/bin/VBoxManage storageattach Debian5 --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /ISO/debian-40r3-i386-netinst.iso

Setting up the network:

$ /usr/bin/VBoxManage modifyvm Debian5 --nic1 bridged --cableconnected1 on --bridgeadapter1 eth0

Using this command, a bridge NIC network interface is created: the cable is connected at startup Linux systems, adapter - eth0.

Let's start the virtual machine:

$ /usr/bin/VBoxManage startvm Debian5

If everything goes as planned, you will see the following message, and then you will see the virtual machine window ready for installation:

Waiting for the remote session to open... Remote session has been successfully opened.

You see, creating and configuring a virtual machine from the command line frees you from endless mouse clicks and opens up a whole new world of virtual machine automation possibilities. We haven't gone too deep here, but I hope this will pique your curiosity and encourage you to explore the enormous power that the command line has.

If you liked the article, share it with your friends:

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 working server under Ubuntu management 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 control virtual machines One VBoxManage command is used through the console (though it has a lot of parameters).
Let's begin.
  1. First, let's create a car and register it immediately
    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. Let's do additional settings 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 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. full list all types can be found using 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

We create 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 minimal installed system you can raise several virtual ones for various purposes and experiments

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