Wednesday, January 4, 2017

Making a vagrant box for RHEL

One of the assignments at work is getting me into creating a vagrant box for RHEL, as I would want to create and destroy RHEL VMs multiple times in a day. 
This blog summarizes the steps to create a vagrant box for RHEL. The software I have are 

1) Oracle VM Virtual Box
2) An ISO file with RHEL 7 setup rhel-server-7.0-x86_64-dvd.iso

Let's begin by creating a baseline VM 

1) New Machine -> Give a Name, Type is Linux, Version is Red Hat 64 bit
2) Memory is fine at 1024 MB
3) Create a Virtual Hard Disk. I chose VDI as my hard disk type, Dynamically allocated size is better for me, and the size for HDD is set to 100 GB. 
4) Go ahead and mount the iso file to the VM. This can be done by selecting the machine settings -> Storage -> and mount the iso on the optical drive. 
5) Start the machine and select to install the RHEL O/S. Walkthrough the wizard and install the RHEL on the VM.  While installing the OS I also chose to create an additional user 'abhishek' on it.
6) Register with the subscription manager by using subscription-manager register
7) sudo visudo and comment the line "Defaults .requiretty"
8) Create a user called vagrant and set the password as vagrant. Commands to use are useradd vagrant. And passwd vagrant. 

Once done let's package this VM as a vagrant box 
1) vagrant package --base BaseRHEL 
2) vagrant box add test package.box 

and now you have a vagrant box for the machine. Enjoy creating as many VMs as you want :).