Tag: Virtualbox

VirtualBox allows you to add new Hard Disks from the UI, you can just goto Virtual machine settings and add new hard disks, but its a bit tricky if you want to use as one of your hard disk partitions as the new hard disk, specially if your host is Windows OS. We are going to use VBoxManage utility which was installed with VirtualBox.

To be able to use any selected hard disk partition on your VirtualBox VM follow the steps below, I am going to give all the details and explanations but my assumption is you at least have an understanding of virtual machines, command line and environment variables.

What is VBoxManage?

VBoxManage utility allows you to configure and control almost all the aspects of VirtualBox which includes creating virtual hard disks, network interfaces configuring your virtual machines and much more.

For the purpose of this howto we are going to use VBoxManage to list the partitions, and then create a virtual disk file which will be pointing to one of the hard drive partitions.

Set up Environment Variable

First we need to set up the “PATH” environment variable, when ever you run a command on command line all the folders specified in “PATH” environment variable are search to find the respective executable.

In the “Disk Management” window note the Disk number from the left side of the disk.

Create Virtual Drive using VBoxManage

Now we are going to create a virtual disk which we will map to one of the partitions of our physical drive. As we have already noted the physical disk number which is “1” so our Physical Drive construct would look something like: “\\.\PhysicalDrive1”

Although late to party, but finally I joined. Until now I had been manually managing my VMs in Virtualbox without Vagrant, but that process was very tedious and slow. Find the image, download it, import it, boot the machine, configure networking, assign the IP addresses, setup the machine. But with Vagrant its as easy as:

Note: Dont’ worry about what it means, I will explain in later chapters.

vagrant init <url to box>
vagrant up
vagrant ssh

vagrant init <url to box>
vagrant up
vagrant ssh

As you can see how easy it is to get your new sandbox environment up and running within few minutes. Its not just the basic setup, but Vagrant allows you to completely setup your new VM with everything you need in your dev environment.

The great part is you don’t have to leave your local machine to write code. Confused? Vagrant actually mounts your local folder (where you ran vagrant init) in your VM, so what ever changes you make on your local machine will be available in your vagrant box.

Let’s Dive into Vagrant

Enough of the praising, let’s dive in and experience the power of vagrant. First you need to find Vagrant boxes (VM images), so you can use them for your development. The following instructions assumes that your are using some flavor of linux (the concept is same for other OS, you just have to convert the commands as per your OS).

The best place to find the Vagrant boxes are Vagrant Cloud. Once you find the suitable box for your development. Create your development directory and do the vagrant init (remember git or hg init?) with the the name of the box from Vagrant Cloud. See the commands below:

mkdir web-app-dev
cd web-app-dev
vagrant init hashicorp/precise32

mkdir web-app-dev
cd web-app-dev
vagrant init hashicorp/precise32

This will create the Vagrantfile and add the box name to the Vagrantfile. You are ready to launch your first vagrant controlled sandboxed dev environment. Just run the vagrant up to get the VM up and running. See the example below (run the command in same folder where you ran vagrant init):

vagrant up

vagrant up

This will download the box (VM image) from the Vagrant cloud, after downloading it will boot the box, do the provisioning and then it will mount your development folder on VM at /vagrant. After few minutes your new VM will be up and running.

Once the VM is up, you can login to the VM by just doing a vagrant ssh. Yes it is this simple, see the example below:

vagrant ssh

vagrant ssh

Now that you are logged into the VM, you can configure it for your development manually (for now). Later on I will write about how can you automate the setup part too, based on your development needs.

Checkout the folder share, by creating files in /vagrant folder on your new VM and then go back to your local folder and see them appear there. Similarly you can create files on local and they will immediately appear in your VM.

Where is the Version Control?

You can add Vagrantfile to your version control so you can replicate your Vagrant setup to other devs or on other locations too. Don’t add other Vagrant files to version control, for now it is just Vagrantfile. Simply just run the following commands (from same folder where you ran vagrant init):

git initgit add Vagrantfile
git commit-m"Add Vagrantfile"

git init
git add Vagrantfile
git commit -m "Add Vagrantfile"

What’s next?

I tried my best to make this getting started guide as simple as I could, and not be confusing for the new developers who are still trying to figure out how linux works. Later on I will write about provisioning and advanced networking setup in Vagrant.

If you have any questions, confusions feel free to ask them in comments and I will try to help you as much as I can.