Skip to content

Instantly share code, notes, and snippets.

@jakebrinkmann
Last active March 22, 2021 14:37
Show Gist options
  • Save jakebrinkmann/4ae0a59bf6f3b0b4929499d2ab832fbd to your computer and use it in GitHub Desktop.
Save jakebrinkmann/4ae0a59bf6f3b0b4929499d2ab832fbd to your computer and use it in GitHub Desktop.
Guide to get a CentOS.7 "box" up and running inside Windows10 using vagrant

Install Vagrant

Guide to get a CentOS.7 "box" up and running inside Windows10

Dependencies

  • Windows 10

Setup

Vagrant manages Virtual Machines (VMs) through various providers (VirtualBox, VMWare, Hyper-V, AWS, etc.). Let's use VirtualBox.

Vagrant may also need tools, such as rsync to function. To get everything working smoothly, install Minimalist GNU for Windows (MinGW) using mingw-get-setup.exe binary.

You must add C:\MinGW\bin; to your user PATH environment variable manually. You can permanently add C:\MinGW\bin; to your PATH by following the instructions in the "Environment Settings" section on the MinGW Getting Started page.

Then, install rsync inside the MinGW Installation Manager through All packages > MSYS > msys-rsync bin. Add the tools to system path using cmd:

set PATH=C:\mingw\bin;%PATH%
set PATH=C:\MinGW\msys\1.0\bin;%PATH%

or powershell:

$env:Path += ";C:\MinGW\msys\1.0\bin" 

Try it out:

rsync --version

note: I already had these tools available thorugh Cygwin, but explored using MinGW for "fun"...

To use vagrant, we will need to install it. Find the windows vagrant_1.8.7.msi binary.

Setup a box

> mkdir F:\VM\centos
> cd F:\VM\centos
> vagrant init centos/7

A Vagrantfile has been placed in this directory. You are now ready to vagrant up your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on vagrantup.com for more information on using Vagrant.

Notice, I am using my F:\ drive, and using a "box" with "centos/7" as the name.

Provision the VM

vagrant up

Interestingly, a "box" already existed with this name, and will be downloaded and added to %userprofile%\.vagrant.d\boxes

From here:

Official Vagrant images for CentOS Linux 6.8 and CentOS Linux 7.2.1511 for x86_64 are now available for download

And, the download is only ~400MB, where even the "Minimal" CentOS .iso file is nearly 700MB... awesome 😄

Print out the setup

vagrant ssh-config

Connect to the machine

Or, hop onto the machine:

vagrant ssh

Save your state

You can also create snapshots:

vagrant snapshot save pre-db
...
vagrant snapshot restore pre-db

Exit gracefully

When stopping the machine,

vagrant halt

And, if you're really gone for good:

vagrant global-status
vagrant destroy --force $psxxxxx

VirtualBox Guest Additions

Following instructions:

So, if want to be using a shared folder in the VagrantFile like so:

config.vm.synced_folder "../data", "/vagrant_data"

You'll have to download : http://download.virtualbox.org/virtualbox/4.2.16/VBoxGuestAdditions_4.2.16.iso (replace 4.2.16 by your VirtualBox version).

To figure out what version of VirtualBox is installed on the host machine (windows powershell):

> & "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" --version
5.1.6r110634

Begin the GuestAdditions installation:

vagrant up 
vagrant ssh

# First, install required dependencies. (I am not positive this is necessary...)
sudo yum install gcc -y
sudo yum install kernel-devel -y
exit # exit from vagrant

# Reload the machine and fire Vagrant
vagrant reload 
vagrant ssh

# Mount the disk 
cd /opt
sudo wget http://download.virtualbox.org/virtualbox/5.1.6/VBoxGuestAdditions_5.1.6.iso
sudo mount VBoxGuestAdditions_5.1.6.iso -o loop /mnt
cd /mnt
sudo sh VBoxLinuxAdditions.run --nox11
cd /opt
sudo rm *.iso
# systemctl enable vboxadd.service # This turned out to not be necessary...

exit
# ADD THE SHARED FOLDER TO YOUR **VagrantFile**
vagrant reload
vagrant ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment