This quick tutorial is going to illustrate how to set name, number of CPUs, memory and GUI mode for Vagrant virtual machines.
1. Set Name for Virtual Machines
We can set name for virtual machines that appear in the VirtualBox GUI by changing the value of the name property. Let’s see an example:
1 2 3 4 5 6 7 8 |
Vagrant.configure(2) do |config| config.vm.box = "ubuntu/xenial64" config.vm.provider "virtualbox" do |v| v.name = "my-hadoop-single" end end |
Let’s see how the name of virtual machine appears in VirtualBox before and after we set the name for virtual machine.
Before:
After:
The displayed name is the one configured in the Vagrantfile file.
2. Set Number of CPUs for Virtual Machines
If we work on a multiprocessor machine, we can set number of CPUs for virtual machines using theĀ cpus property. Let’s see an below example which we set 2 CPUs for the above virtual machine:
1 2 3 4 5 6 |
Vagrant.configure(2) do |config| config.vm.box = "ubuntu/xenial64" config.vm.provider "virtualbox" do |v| v.cpus = 2 end end |
Let’s verify the number of CPUs of the virtual machine in VirtualBox:
We can see that there was two CPUs set for the virtual machine.
3. Set Amount of Memory for Virtual Machines
We can set amount of memory for virtual machines using the memory property. Let’s see an example which we set 2048 MB memory for a virtual machine:
1 2 3 4 5 6 |
Vagrant.configure(2) do |config| config.vm.box = "ubuntu/xenial64" config.vm.provider "virtualbox" do |v| v.memory = 2048 end end |
Now let’s verify the amount of memory set for the VM in the VirtualBox:
We can see that there was 2048 MB of memory was set for the virtual machine.
4. Set GUI Mode for Virtual Machines
By default, VirtualBox starts the machines in headless mode, which means that there is no UI to access
the guest OS. And in this case, the only one way we can access the virtual machines is using SSH. If we want to have a UI, we can set the GUI mode for virtual machines using the gui property. Let’ see an example which we set the GUI mode for the above virtual machine:
1 2 3 4 5 6 |
Vagrant.configure(2) do |config| config.vm.box = "ubuntu/xenial64" config.vm.provider "virtualbox" do |v| v.gui = true end end |
5. Conclusion
The tutorial has illustrated how to set name, number of CPUs, memory and GUI mode for Vagrant virtual machines. We can see that those properties are very essential when we work with virtual machines and we often have to modify those properties to fit with our desired environment. And with Vagrant, it’s easy for us to achieve that by just defining in the Vagrant configuration file.
Here are other related tutorials for your references:
Uninstall Vagrant on Ubuntu 16.04
How to Add a Vagrant Box from Local or Remote