Minggu, 05 April 2015

VM without GUI

VirtualBox Headless, install and manage VM without GUI


VirtualBoxI’m aware that Xen or KVM are much more used and recommended to create and mange virtual machines on a server, but for some reasons I needed to use Virtualbox. Here is a short note on how to install virtualbox on ubuntu, and how-to use it without GUI (graphical interface) to create and manage your VM’s (Virtual Machines).

Installatiion:
The installation method proposed here applies to ubuntu 12.04 (precise pangolin), for other versions or distributions see this page.
Add virtualbox repository to your /etc/apt/sources.list (as root):
   deb http://download.virtualbox.org/virtualbox/debian precise contrib
add virtualbox repository key to apt:
    wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
then run apt-get update and install virtualbox package:
   sudo apt-get update && sudo apt-get install virtualbox
you can also install dkms, this avoids to rebuild virtualbox modules each time there is a kernel update:
   sudo apt-gt install dkms
Create a VM:
    VBoxManage createvm --name "MyUbuntuServer" --ostype Ubuntu --register
The above command create a VM called MyUbuntuServer, the ostype param selects some default values like RAM size, type of the network device.
To modify your VM settings run something like this:
    VBoxManage modifyvm "MyubuntuServer" --memory 512 --acpi on --boot1 dvd --nic1 nat
Add a disk controller (IDE controller) to your VM:
   VBoxManage storagectl MyUbuntuServer" --name "IDE Controller" --add ide --controller PIIX4
Then create a virtual disk (6GB in our case):
   VBoxManage createhd --filename "MyUbuntuServer.vdi" --size 6000
Attach this virtual disk to your VM by adding it to the IDE controller:
   VBoxManage storageattach "MyUbuntuServer" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "MyUbuntuServer.vdi"
Start your VM and install an OS:
Donwload an Ubuntu Server ISO at http://ubuntu.com
Attach the downloaded ISO to your VM, so it will boot from it :
   VBoxManage storageattach "MyUbuntuServer" --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /wherever/you/saved/ubuntu-12.04-server.iso
Start your VM using vboxheadless:
   VBoxHeadless --startvm "MyUbuntuServer"
If everything is ok, yuo should see a copyright notice, if not it returns to the command line.
Manage your VM:
For example, if you have an ssh server on your VM you may want to start your VM without virtualbox remote desktop protocol (VRDP is always started even if not specified in the VM settings):
   VBoxHeadless --startvm  --vrde off
more on vboxmanage command and its options in virtualbox manual.

Tidak ada komentar:

Posting Komentar