Vagrant Boxes / VMWare Fusion / CentOS 7

Use one found here: http://www.vagrantbox.es you can use one of those to build upon or you can create one.

These steps are if you want to to create a fresh box.
Grab the latest CentOS image here:
http://www.centos.org/download/

I use the minimal image http://ftp.usf.edu/pub/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-Minimal.iso

First you need to create a VM using Fusion.

  1. Select “Install from disc or image” >> Continue
  2. “Use another disc or disc image” >> Find your iso >> Continue
  3. Uncheck “Use Easy Install” make sure “Make your home folder accessible to the virtual machine is unchecked. >> Continue
  4. Click “Customize Settings” >> Rename your vm and place it somewhere safe.

Settings for new VM:

Sharing
Make sure sharing is disabled.

Processor & Memory

Screen Shot 2014-12-16 at 1.17.56 PM
Select 1 Processor and 512 MB Memory, this is minimal because not everyone has a system with 16 cores and 64gb of memory.

Display
Make sure everything here is unchecked, Accelerated 3d and Retina Display not needed.

Network Adapter
Make sure “Share with my Mac” is selected.
Screen Shot 2014-12-16 at 1.18.31 PM

Hard Disk
Uncheck “Split into multiple files”
Screen Shot 2014-12-16 at 1.18.49 PM
ClickApply

Sound Card
Click “Remove Sound Card”

USB & Bluetooth
Click “Advance USB options” >> Click “Remove USB Controller”

Printer
Click “Remove Printer Port”

Compatibility
Click “Advanced options” >> I use hardware version7, but you can use whatever you feel is necessary. It is the compatibility you are looking for, if you and everyone you are suppling the box is using Fusion 7 leave it alone. If by chance you don’t know who is going to use your box you’ll want to be as compatible as you can.
Screen Shot 2014-12-16 at 1.20.17 PM

Isolation
Uncheck “Enable Drag and Drop” and “Enable Copy and Paste”
Screen Shot 2014-12-16 at 1.20.28 PM

Installing CentOS:

Select Language.

Installation Destination. Click “Done” >> Begin Installation

Root Password >> Set it to vagrant >> Click “Done” twice.

Click “Reboot”

Install complete.

Configure CentOS:

Login as root password is vagrant.

My ethernet didn’t work so I had to regenerate a MAC address in network settings under the “Network Adapter” pane in Fusion.
Screen Shot 2014-12-16 at 3.31.50 PM

# update yum
yum update
yum groupinstall "Development Tools"
yum install kernel-devel

# vmware tools for guest
# http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2075048

curl -O http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-DSA-KEY.pub
curl -O http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-RSA-KEY.pub

rpm --import VMWARE-PACKAGING-GPG-DSA-KEY.pub
rpm --import VMWARE-PACKAGING-GPG-RSA-KEY.pub

vi /etc/yum.repos.d/vmware-tools.repo

# insert this into file
[vmware-tools]
name = VMware Tools
baseurl = http://packages.vmware.com/packages/rhel7/x86_64/
enabled = 1
gpgcheck = 1

# install
yum install open-vm-tools-deploypkg

# if having problems click install VMWare Tools
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cp /mnt/cdrom/VMwareTools-9.9.0-2304977.tar.gz /tmp
cd /tmp
tar -C /tmp -zxvf VMwareTools-9.9.0-2304977.tar.gz
cd vmware-tools-distrib
./vmware-install.pl

# pay close attention to install process.

# restart
systemctl restart vmtoolsd

# check ssh service should be active
service sshd status

# check firewall service
service firewalld status

# Set SELinux to permissive mode
# Permissive: In Permissive mode, SELinux is enabled but will not enforce the security policy, only warn and log actions. Permissive mode is useful for troubleshooting SELinux issues
sed -i -e 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config

# add vagrant user
useradd vagrant

# switch to vagrant user
su - vagrant

# make ssh directory
mkdir -m 0700 -p /home/vagrant/.ssh

# grab vagrant authorized_keys
curl https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub >> /home/vagrant/.ssh/authorized_keys

# make sure permissions are correct for file
chmod 600 /home/vagrant/.ssh/authorized_keys

# switch back to root
exit

# important step modifying sudoers comment out requiretty
# allows ssh to run sudo commands
sed -i 's/^\(Defaults.*requiretty\)/#\1/' /etc/sudoers

# allows vagrant to use sudo without password entry
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

# clean up
yum clean all
rm -rf /tmp/* /var/log/wtmp /var/log/btmp
history -c

shutdown -h now

Post Configure:

Remove CD/DVD Drive
Screen Shot 2014-12-16 at 6.07.54 PM
Click on “Remove CD/DVD Drive”

Creating a Vagrant Box

cd to where your vmware vm is stored usually its ~/Documents/Virtual\ Machines/

My example

cd /Volumes/VMs/Vagrant\ CentOS 64-bit\ Minimal.vmwarevm

Defrag & Shrink virtual disk.

/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -d Virtual\ Disk.vmdk

/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k Virtual\ Disk.vmdk
# add metadata file
vi metadata.json

# add this
{
    "provider": "vmware_fusion"
}

# remove log files
rm -f vmware*.log

# finally time to create the box file
tar cvzf centos-7.0-x86_64-minimal.vmware.box ./*

# once done remove metadata.json file
rm -f metadata.json

Adding Vagrant Box

vagrant box add centos-7.0-x86_64-minimal /Volumes/VMs/Vagrant\ CentOS 64-bit\ Minimal.vmwarevm/centos-7.0-x86_64-minimal.vmware.box

A lof of this is from Thornelabs.

 

Leave a Reply

Your email address will not be published. Required fields are marked *