Windows.  Viruses.  Notebooks.  Internet.  office.  Utilities.  Drivers

Virtualization... virtualization...
Now 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 go for 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 this purpose. I'm sure most people use a GUI interface for setup. it is very clear and convenient. But how many have thought about the possibility of managing VirtualBox through the console.
The task was set: Install two operating systems (Ubuntu and Windows) on one server. At the same time there was a working server under running Ubuntu 9.04 Server Edition. Therefore, it was decided to put Windows XP as a guest system.
But there was a problem on Ubuntu NOT INSTALLED any graphic environment, i.e. there is only a bare console.

So what do 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 message. You may not have the necessary packages installed. In my case, I didn't have the package installed libxslt1.1 which was immediately corrected. sudo command apt-get install libxslt1.1 .
Adding yourself to a group vboxusers
sudo usermod -a -G vboxusers username

Create a virtual machine

To begin with, it should be noted that in order to control virtual machines through the console, one VBoxManage command is used (although it has a lot of parameters).
Let's start.
  1. First, let's create a car and immediately register it
    VBoxManage createvm -name VMName -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 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 specify:
    • Guest OS type. To get a list of supported OSes, run the VBoxManage list ostypes command
    • Allocated memory size
    • Name of the main disk
    • Ability to use VRDP (VirtualBox Remote Desktop Protocol)
    VBoxManage modifyvm VM_name --ostype OS_type --memory MB_memory_size --hda disk_name --vrdp on
  4. Connect the disk image from which we will install Windows XP
    • Let's register the DVD with the system distribution image
      VBoxManage openmedium path_to_image
    • Let's put our disk in 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 hostname

… Launch… Let’s go

To start the virtual machine, run
VBoxManage startvm hostname --type vrdp
Parameter --type vrdp needed to connect to the machine using VRDP
Everything, now it remains to connect to our machine using remote desktop. This can be done with standard utilities: for windows it's mstsc, for nix systems it's rdesktop. we only have a console, then 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 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, 3389 for the first machine, 3390 for the second, 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 it becomes necessary to run a virtual machine on a host without Xs. I will talk about 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 packages from dependencies (including some for the GUI interface). Therefore, it is better to download the deb package. Download, 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, which stores configs, but there are much fewer of them than in the first case). If the installation failed 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.

We 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 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 more clear here. you can also specify NAT as the network type (--nic1 nat). also enable rdp

We create hdd disk for 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 cling to IDE0 the previously created hdd

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

On IDE1 we cling 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

We start the car

In order to install the base system, we will use the 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 get to the virtual machine via ssh

Stopping the virtual machine

VBoxManage controlvm ubuntu acpipowerbutton
via acpi

Or more hard

VBoxManage controlvm ubuntu poweroff

We say loaded from hdd

VBoxManage modifyvm ubuntu --boot1 disk

You can also unhook the installation disk

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
view information about the virtual machine

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

1.Create a 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. its increase does not occur dynamically.
3. Create a virtual disk controller
VBoxManage storagectl windows_xp --name "IDE Controller" --add ide --controller PIIX4
This command creates an IDE controller named “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. We 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 system type VBoxManage modifyvm windows_xp --ostype WindowsX P
view all possible ostypes: VBoxManage list ostypes

8. Allow to connect 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 addons 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. Start the virtual machine
vboxheadless -s windows_xp or in the background:
VBoxManage startvm windows_xp --type headless
to run the guest OS on the base computer you are sshing to, 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

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 disk of the virtual machine needs to be cloned, then this is done using the VBoxManage utility:
VBoxManage clonehd /path/from/copy/image1.vdi /path/to/copy/image2.vdi
After that, 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


Author: Ken Hess
Publication date: January 18th, 2010
Translation: N.Romodanov
Transfer date: February 2010

Ordinary VirtualBox users may not be aware of the tremendous power that lies in the command line interface.

People usually ask: "Why work on the command line when you have a perfectly good graphical interface?" The answer is the vast possibilities of the command line. Since 1995 there has been a whole generation 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 era of computing was ushered in—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 stopped being afraid of Linux. But the command line is still alive and well in the Linux environment. It's still quite alive on Windows. And now that Macs are based on Unix, they also have a lot of stuff that doesn't require a GUI.

It may come as a surprise to you that underneath VirtuaBox's pretty GUI, with its bright graphics, clear Settings page, and plenty of drop-down lists, lurks the occult world of the command line. The true power of this dark world will be revealed only to those who dare to enter these musty catacombs. After you get to grips with the VirtualBox command line, you might decide that the GUI is little more than a pretty drape made for those who would otherwise just ignore the boring black rectangle of an actual running 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 advantage of the full power of automatic command execution. The only way automation that I know of on *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 with right time run the script. This command-line power that, thanks to its autorun capability, requires system administrators to also be able to write scripts, is their baggage of skill. For every job 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.

As far as virtualization is concerned, the command line will allow you to quickly create virtual disks, add a new network interface, start 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, with the help of hints, will help you create a virtual machine, run it, or install and modify it with very minimal intervention on your part. If you don't like to do everything manually, you will make a list of virtual machines that are used all the time, then set up scripts (templates) for each type of used virtual machines and, if necessary, create a virtual machine within a few seconds.

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

Installation and main components

From the VirtualBox Linux Downloads link, download the binary distribution 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 sources - /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), use one of the packages that you can download, or download the source code.

Creating and configuring a virtual machine

The hardest part about using the command line is knowing where to start. IN GUI you need to use the New button. The command line is a little more difficult to reveal its secrets. In order to create and set up a new virtual machine, you must open a terminal window, or use an ssh session to access the Linux system where 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 4 GB (4000 MB) virtual disk named Debian5.vdi; the size is fixed, i.e. its increase does not occur 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”, 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

We connect iso image toy 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

This command creates a bridge type NIC network interface (bridge): the cable is connected at startup Linux systems, adapter is eth0.

We 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 can see that creating and configuring a virtual machine on the command line frees you from endless mouse clicks and opens up a whole new world of virtual machine automation possibilities. And we haven't gone into much depth here, but I hope this will pique your curiosity and encourage you to master the tremendous power that the command line has.

If you liked this article, please share it with your friends:

Sometimes it becomes necessary to run a virtual machine on a host without Xs. I will talk about 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 packages from dependencies (including some for the GUI interface). Therefore, it is better to download the deb package. Download, 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 much fewer of them than in the first case). If the installation failed 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.

We 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 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 more clear here. you can also specify NAT as the network type (--nic1 nat). also enable rdp

Create an hdd disk for the 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 cling to IDE0 the previously created hdd

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

On IDE1 we cling 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

We start the car

In order to install the base system, we will use the 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 get to the virtual machine via ssh

Stopping the virtual machine

VBoxManage controlvm ubuntu acpipowerbutton
via acpi

Or more hard

VBoxManage controlvm ubuntu poweroff

We say loaded from hdd

VBoxManage modifyvm ubuntu --boot1 disk

You can also unhook the installation disk

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
view information about the virtual machine

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

If you notice an error, select a piece of text and press Ctrl + Enter
SHARE: