How to run a virtualbox on a headless server.
I tried to get qemu-kvm running on my slackware boxes but no matter what I tried I couldnt get the network to work. After many days of trying and reading and failing I gave up. I then decided to try virtualbox from the command line. And that worked really great and network worked out of the box without any fuss.
First step is to download virtualbox (For slackware64 I choose All distributions AMD64)
Run as root
sh Virtualbox-<version.Architecture>.run # This will install Virtualbox usermod -a -G vboxusers username # This will add your user to the group that is allowed to run virtualbox
Extension packs has been introduced starting with Virtualbox 4. Some of the functionality like remote desktop(VRDE) has been removed and turned into an extension. Because we need remote desktop functionality to be able to install and control our virtual machine we need to download the extension pack. (Choose Virtualbox <Version> Oracle VM Virtualbox Extension pack and press All platforms and download.
Run as root:
vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-.vbox-extpack # This will install the extension pack.
Now we are ready to create our first virtual pc. (First download the iso of the distro you choose and put it into ~/iso folder in your homedirectory.
I’ve made a collection of scripts to automate the progress of creating, starting, stopping and unregister your VM.
You can find them here (Download them and remove the .txt)
Manually process:
Creating a VM: I will now create slackware server vm with 512 MB ram and 20GB hardrive, installing from a slackware iso image(which is stored in ~/iso in my homefolder)VBoxManage createvm --name "slackware" --register VBoxManage modifyvm "slackware" --memory 256 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter eth0 VBoxmanage createhd --filename /slackware.vdi --size 20000 VBoxManage storagectl "slackware" --name "IDE Controller" --add ide VBoxManage storageattach "slackware" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium path to your vdi>/slackware.vdi VBoxManage storageattach "slackware" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium ~/iso/slackware.isoThat's all it is to create a VM. Now lets start your vm.
Starting your VM for installationVBoxHeadless --startvm "slackware" & # This starts your vm and a remote desktop server.Next step is to connect to the vm using a remote desktop client (windows=mstsc and linux=rdesktop)
rdesktop <ip adress of the host>,NOT the guest mstsc and type in adress of the host,NOT the guestGo through the installation and shutoff the VM:
Shutting of your VMVBoxManage controlvm "slackware" poweroffOne last step and the VM is ready for use. We have to remove the installation media, so its booting the OS and not the installation media.
Removing the installation mediaVBoxManage modifyvm "slackware" --dvd noneStarting your VM
VBoxHeadless --startvm "slackware" --vrde off & # Starts your VM without remote desktop support. You dont need this after its approriate configured right?![]()
Unregister your vm
If you mess up something and you want to delete the vm and redo it you have to unregister the vm before you can create it again with the same name. If not you will get errors.VBoxManage unregistervm slackware --deleteSource: Howtoforge
Automate the process (using the scriptsI provied earlier. its easy to create, start, stop and unregister the VM.)
sh create-vm.sh # Type in name, how much ram you want, and how much harddrive space and the scripts does the rest. sh start-vm.sh # Type in name of the vm you want to start, removes the dvddrive, ask you if you want VRDE(remote desktop server) support or not and starts the vm. sh stop-vm.sh # Type in name of the vm you want to stop. sh unregistervm.sh # Type in name of the vm you want to unregister.