Installing virtual box


Installing and setting up virtual box was not without pain, but once I finally got it running i was very happy with its performance. Also I didn't experience any problems with sudden restarts etc. It could easily run 10 machines on my 8gb of ram. I have had problems with many other approaches to installing virtual box!

Do note that I have experienced Windows virtual machines becoming corrupt, perhaps due to my underlying filesystem (ext4) which I have found people advice against.

Here are some of my notes.




How to set up virtual box from scratch with auto-start.

Ensure you have the latest updates
$ sudo apt-get update

Install dkms to ensure upgrades in the future don't trouble us
$ sudo apt-get install dkms

(Optional) Make sure your system is up-to-date
$ apt-get upgrade

Download the package
Find the package by www-browser (remember it must match platform and version)
$ sudo www-browser www.virtualbox.org
put it on disk and call it virtualbox.deb

Ensure you get the right version for your platform.

Install build essentials
$ apt-get install build-essential

Perhaps you want to restart now

$ sudo apt-get install linux-headers-`uname -r`
$ sudo apt-get -f install
$ sudo dpkg -i virtualbox.deb


$ sudo /etc/init.d/vboxdrv setup

Create a user to run the virtual machines with
$ sudo useradd -m virtualbox
Set password for new account
$ sudo passwd virtualbox

To be able to run virtual box, add the user to vboxusers 
$ sudo usermod -a -G vboxusers virtualbox

Log in as virtualbox
$ su virtualbox

Create your first machine with:
$ VBoxManage createvm --name "testubt" --register

It will then print:
....

Virtual machine 'testubt' is created and registered.
UUID: 907a215e-9b05-4089-a1e9-53cb20d9feda
Settings file: '/home/virtualbox/.VirtualBox/Machines/testubt/testubt.xml'


Now modify it

$ VBoxManage modifyvm "testubt" --memory 1024 --acpi on --boot1 dvd --boot2 disk --nic1 nat --hwvirtex on
$ VBoxManage modifyvm testubt --ostype Ubuntu
$ VBoxManage storagectl testubt --name "IDE Primary master" --add ide
$ VBoxManage createvdi --filename "testubt_harddrive.vdi" -size 6000 -register
$ VBoxManage modifyvm "testubt" --hda "testubt_harddrive.vdi"


12. (Optional) Set your network adapter in bridged mode instead of NAT

$ VBoxManage modifyvm testubt --nic1 bridged
$ VBoxManage modifyvm testubt --bridgeadapter1 eth0

13.
Now start your new machine!

$ VBoxHeadless --startvm testubt --vrdpport 8888 --vrdp on &

And then connect to it via Remote Desktop, for example using a Windows machine on port 8888.


Automating the setup.

I recommend that you install vboxtool. But do note that I have had to manually change the script after upgrading virtual box to newer versions.


Login as sudo admin
$ su

Download the vboxtools from here: http://vboxtool.sourceforge.net/

Copy the scripts (vboxtool) with
$ sudo cp vboxtool /usr/local/bin/vboxtool

$ sudo chmod +x /usr/local/bin/vboxtool

$ sudo cp vboxtoolinit /etc/init.d/vboxtoolinit

$ sudo chmod +x /etc/init.d/vboxtoolinit

$ sudo update-rc.d vboxtoolinit defaults 99 10

*** Note. To remove vboxtoolinit from autostart: update-rc.d -f vboxtoolinit remove

$ sudo mkdir /etc/vboxtool

$ nano /etc/vboxtool/machines.conf

Enter into this file the server name and a port like:
svr1, 3391


Now logoff from your root user and try to login as virtualbox and run "vboxtool autostart"

Verify that you can connect through remote desktop

Verify that your setup works:

Restart the server. Test that it shuts down and that it restarts
$ sudo shutdown -r -t 10 now

It should disconnect immediately from remote desktop (and ssh)

After restart verify that it starts again...

Setup backup (didn't work in latest version when I tried):

create /home/virtualbox/vboxbackup

Modify /etc/vboxtool/vboxtool.conf
Add this line:
backup_folder=/home/virtualbox/vboxbackup

Comments

Popular posts from this blog

Switching from Docker Desktop to Rancher Desktop on WSL2: Solving the Missing docker-credential-desktop.exe Error

Running LXD/LXC on WSL2 with Ubuntu 20.04

Proxmox Remote administration via VNC