Saturday, July 22, 2017

Oracle Linux - changing the amount of memory of your Vagrant box

Vagrant is an open-source software product build by HashiCorp for building and maintaining portable virtual development environments. The core idea behind its creation lies in the fact that the environment maintenance becomes increasingly difficult in a large project with multiple technical stacks. Vagrant manages all the necessary configurations for the developers in order to avoid the unnecessary maintenance and setup time, and increases development productivity. Vagrant is written in the Ruby language, but its ecosystem supports development in almost all major languages.

I use Vagrant a lot, really a lot, and especially in combination with Oracle LinuxOracle ships a number of default vagrant boxes from within oracle.com which speeds up the development, test and experimental way of working a lot. Without having the need to manually maintain local clones of Oracle virtualbox images you can now use vagrant to extremely fast run Oracle Linux instances.  A short guide on how to get started with vagrant can be found in this specific blogpost on my blog.

When you run a box for a short time you might not be that interested in memory tuning as long as it works. However , if you need to run multiple boxes for a longer periode of time as part of a wider development ecosystem you do want to ensure that all the boxes fit in your development system and you still have some free memory left to do actual things.

A default box is taking a relative large part of the memory of your host. Tuning this memory to what it actually should be is relatively easy. In our example the Oracle Linux 6.9 box starts by default using 2048MB of memory. We wanted to trim this down to 1024. To state the exact amount of memory you need to configure some parts in your Vagrantfile config file.

The below example we added to the Vagrantfile defined the amount of memory that could be given to the box:

config.vm.provider "virtualbox" do |vb|
  vb.memory = "1024"
end

This would make that the box will be given only 1024. Additional you can pass other configuration for example if want to provide only 1 cpu you could also add the below line right after the vb.memory line to do so.

v.cpus = 2

Understanding and using the Vagrantfile configuration options will help you in building and tuning your boxes in the most ideal way to have the best development environment you can imagine on your local machine.

No comments: