📜 ⬆️ ⬇️

Running a virtual machine in VirtualBox without GUI

VirtualBox Sometimes there is a need to start a virtual machine on a host without X. 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 package (Dynamic Kernel Module Support Framework):
')
sudo apt-get install dkms

On the VirtualBox site, there are 2 options: set the source of the packages ( deb download.virtualbox.org/virtualbox/debian karmic non-free 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 pulled a bunch of dependency packages (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

maybe there will also need dependencies (some libraries for parsing xml in which configs are stored, but they are much smaller than in the first case). If the installation is not completed due to dependencies, you can simply do

sudo apt-get -f install

at the same time dependencies and VirtualBox are installed

OK. VirtualBox set. Let's start creating guest-machines.

create the car itself:

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

customize

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

here with more everything is clear. as a network type, you can also specify NAT ( --nic1 nat ). also include rdp

create hdd disk for virtual machine:

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

add IDE controller to our machine

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

we hook on IDE0 created earlier hdd

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

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

We tell the machine to boot from disk

VBoxManage modifyvm ubuntu --boot1 dvd

we start the car

nohup VBoxHeadless --startvm ubuntu &

in order to supply the base system, we will use the rdp client (I have KDE, KRDC comes as standard). We connect to the host machine on the port that was specified in the settings ( --vrdpport 3390 ), set the system, do sudo apt-get install openssh-server . now you can access the virtual machine via ssh

stop the virtual machine

VBoxManage controlvm ubuntu acpipowerbutton
via acpi

or more tightly

VBoxManage controlvm ubuntu poweroff

we speak is loaded with 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 run again

nohup VBoxHeadless --startvm ubuntu &

More useful commands are:

VBoxManage list runningvms
view all running machines

VBoxManage showvminfo ubuntu
view virtual machine information

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

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


All Articles