How to setup a virtual machine

How to setup a virtual machine ?

This post covers how to setup VirtualBox , VMware Workstation, VMware Player and Vagrant applications and how to setup guest operating system.

Here, I’ve selected Windows 10 Home as Host OS and Ubunbu 16.04 LTS Xenial as guest OS.

Let’s first understand some basic terminologies regarding Virtualization.

Virtualization :
Virtualization is the creation of a virtual (rather than actual) version of something, such as an operating system, a server, a storage device or network resources.

HostedVirtualizationSmall_20090325191230

Hypervisor :
A hypervisor or virtual machine monitor (VMM) is a piece of computer software, firmware or hardware that creates and runs virtual machines.

virtualization

A computer on which a hypervisor is running one or more virtual machines is defined as a host machine. Each virtual machine is called a guest machine. The hypervisor presents the guest operating systems with a virtual operating platform and manages the execution of the guest operating systems. Multiple instances of a variety of operating systems may share the virtualized hardware resources.

Type-1, native or bare-metal hypervisors
These hypervisors run directly on the host’s hardware to control the hardware and to manage guest operating systems. For this reason, they are sometimes called bare metal hypervisors.

Type-2 or hosted hypervisors
These hypervisors run on a conventional operating system just as other computer programs do.
A guest operating system runs as a process on the host. Type-2 hypervisors abstract guest operating systems
from the host operating system. VMware Workstation, VMware Player, VirtualBox and QEMU are examples of type-2 hypervisors.

400px-Hyperviseur

VirtualBox :

VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. It is freely available as Open Source Software under the terms of the GNU General Public License (GPL) version 2.

Presently, VirtualBox runs on Windows, Linux, Macintosh, and Solaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, Windows 7, Windows 8, Windows 10), DOS/Windows 3.x, Linux (2.4, 2.6, 3.x and 4.x), Solaris and OpenSolaris, OS/2, and OpenBSD.

You can download it from here VirtualBox

There are two options to setup guest OS,
1) You need Ubuntu ISO image to set it up new guest OS machine. It can be downloaded from here ubuntu-16.04-desktop-amd64.iso.
2) You can directly download ready box from osboxs.

I’ve chosen to setup new machine using ISO image.

Installation setups are given on their website which are pretty simple. Installation steps has chosen default setting while allocation size/space to guest OS.
You need to make sure that your guest machine has sufficient space both for application and data which you will keeping on it.

Follow these steps to setup virtual machine,

Virtualbox Setting Up a New Virtual Machine

You can also share folder between Host and guest machine using VirtualBox/SharedFolders and
HOWTO: Use Shared Folders.

If you want to have it mount automatically upon each boot, put the mount command in /etc/rc.local (Debian based distro’s), or whatever script is run at the end of the boot process. The Shared Folders service should mount them automatically, but that doesn’t always happen.
Using /etc/fstab has little effect, because that file is processed before the SF module is loaded and will fail to mount the share. Sometimes, the share does get mounted because the GA check for it when they are loaded upon boot, but it’s very flaky, meaning it doesn’t work most of the time. You’re better of with the first option.
When you put the mount command in /etc/rc.local, so it’s mounted at startup, you can’t use the short notation for your home folder. During startup, everything is done through the root user, so using ~ for home, means it’s the home folder of Root (/root).

Guest Additions setup can be found here, Guest Additions.

Following are important steps for setting up shared folder,

sudo apt-get install build-essential
sudo apt-get install linux-headers-`uname -r`

sharename="shared_folder"
sudo mkdir /mnt/$sharename
sudo chmod 777 /mnt/$sharename
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename
ln -s /mnt/$sharename $HOME/Desktop/$sharename

For me, it got mounted on /media/sf_share path for some reason.

If google chrome in guest OS (Ubuntu) is not working properly then Disable 3D-acceleration in guest OS setting on virtual box.

Resize Virtualbox Image :

1) Backup VDI image:

Take a backup of you image by coping ‘.vdi’ file to somewhere else. You may need it to restore your system in case of any data lose.

path_to_folder\VirtualBox VMs\Xenial64\Xenial64.vdi

2) Extent VDI image size:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "path_to_folder\VirtualBox VMs\Xenial64\Xenial64.vdi" --resize 30000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Above command will extent VDI size of you image but you will still need to allocate that space to guest OS partition manually.

3) Allocate space to partition:

You can resize your existing guest OS parting using gparted.

Download gparted from this link, (Choose correct 32bit/64bit)
gparted

Boot your virtual machine using above gparted ISO.

NOTE: If gparted gui not working or you it is getting hanged in between.
Go to VM Setting->Systems and checked the “Enable EFI (special OSes only)” extended feature.

Now you should see gparted GUI.

You can see /dev/sda1, /dev/sda2 (linux-swap) partitions on screen. You can easily resize /dev/sda2 (linux-swap) partition by selecting it, choosing “Resize/Move” and applying using “Apply” button.

But, If you wish to extent /dev/sda1 partition then you will need to delete linux-swap and /dev/sda2 partition. Now It will allow you to resize /dev/sda1 partiontion. Set it whatever size you want. Also keep

some 3-4GB free for linux-swap.

Now, re-add your Linux Swap Space. Press on the unallocated space and right-click to “Created new Partition” -> choosing “Create as: Extended partition” .

Press “+Add” and right-click the new “unallocated” to Create a new partition. Choose as “Create as: Logical Partition” and underneath “File System: linux-swap”.

Now press “+Add” and then “Apply” in the main window. Hopefully all changes are successfully applied.

You can now safely shut down this Live CD Virtual Machine.

You can now check disk space again.

#df -h

VMware Workstation / VMware Player :

VMware virtualizes computing, from the data center to the cloud to mobile devices, to help our customers be more agile, responsive, and profitable.

VMware Workstation and VMware Player transforms the way technical professionals develop, test, demonstrate and deploy software by running multiple x86-based operating systems simultaneously on the same PC.

You can download it from here Vmware

Most of installation steps are identical to for both of them. There are few differences which can be found here on compare page.

Follow these steps to setup virtual machine,

VMware Workstation Setting Up a New Virtual Machine

Here also you will need some shared folder to sync data between Host and Guest machine.

Install vmware-tools as follows,

sudo apt-get install build-essential
sudo apt-get install linux-headers-`uname -r`
cp /cdrom/VM*.gz /tmp/
cd /tmp
tar xvzf VM*.gz
cd vmware-tools*
sudo ./vmware-install.pl

NOTE : if you got,
The package that need to be removed,
open-vm-tools

sudo apt-get remove open-vm-tools;

and try running above command again.

Hit enter for all defaults.

Details are given here, Installing VMware tools on an Ubuntu guest

Once it is done, follow steps given as below to setup shared folder,

Create a New Shared Virtual Machine

Now, your shared folder should be ready on following path,

ls /mnt/hgfs/

Vagrant :

Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.

To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine.

You can get it here, Vagrant

To set it up on ubuntu follow this Setup vagrant on ubuntu

You can find ready boxes here, hashicorp.

Now we can just start your virtual machine as follows,

C:\HashiCorp\Vagrant\bin>vagrant init boxcutter/ubuntu1604
C:\HashiCorp\Vagrant\bin>vagrant up --provider virtualbox

If you are using Window as Host OS and Ubuntu Server as guest OS then While setup you will get following details,

Username : ubuntu
PrivateKey : Drive:\HashiCorp\Vagrant\bin\.vagrant\machines\default\virtualbox\private_key

As Window doesn’t has ssh client by default. You will need ssh client like ‘putty’ to ssh to guest OS Ubuntu server.

Putty can be downloaded from here, putty.

Also download PuTTYgen.

- PuTTY – Client to for managing SSH sessions
- PuTTYgen – Tool for managing and creating SSH key pairs

Load Vagrant private key in PuTTYgen, set key passphrase (remember it. Will need later) and click on ‘Save private key’ button to Generate Putty(.ppk) ‘Private’.
Use Putty private key (.ppk) to set it under SSH-Auth section in Putty. You can also set default auth username under Putty Connection-Data section.

Now you should be able to ssh to guest Ubuntu server OS.

You can also setup shared folder on Vagrant. Steps are given here , Shared folder.

Now you can setup as many as guest OS using above applications.

Thanks.

This entry was posted in Uncategorized, Virtualization and tagged , , . Bookmark the permalink.

Leave a Reply