Created
September 12, 2013 17:31
-
-
Save dillera/6541129 to your computer and use it in GitHub Desktop.
Create VMware fusion Vagrant clones for Centos6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Vagrant VMWare Fusion Centos6 | |
# HOWTO by Andrew Diller, dillera@gmail.com | |
# July 2013 v.1 | |
# | |
# | |
# Vagrant version 1.2.4 | |
# vmrun version 1.12.1 build-1040386 | |
# Fusion - Professional Version 5.0.3 (1040386) | |
# | |
# | |
# - Build vmware Fusion VM using Centos6.4 minimal install | |
# - ENABLE Sharing | |
# - Set 2 CPUs, 2048G Ram | |
# - remove USB | |
# - remove Sound Card | |
# - remove Printer Port | |
# - Set Compatibility to Hardware Version 8 (to use with ESXi 5) | |
# | |
# - start install via GUI | |
# | |
# - it will stop and ask about gcc, Click Ignore all | |
# | |
# - when the vm reboots it won't come all the way up, but ssh is available | |
# | |
# - GUI: Click on "install vmware tools..." | |
# | |
# - Find out the DHCP address of your vm using nmap (hint: install brew to get nmap) | |
# | |
# | |
# $ ifconfig -a |grep netmask | |
# inet 127.0.0.1 netmask 0xff000000 | |
# inet 192.168.251.215 netmask 0xffffff00 broadcast 192.168.251.255 | |
# inet 192.168.41.1 netmask 0xffffff00 broadcast 192.168.41.255 | |
# inet 172.16.135.1 netmask 0xffffff00 broadcast 172.16.135.255 | |
# | |
# | |
# $ nmap -sP 172.16.135.* | |
# | |
# Starting Nmap 6.25 ( http://nmap.org ) at 2013-07-23 20:15 EDT | |
# Nmap scan report for 172.16.135.1 | |
# Host is up (0.00069s latency). | |
# Nmap scan report for 172.16.135.134 | |
# Host is up (0.00079s latency). | |
# Nmap done: 256 IP addresses (2 hosts up) scanned in 2.65 seconds | |
# | |
# $ ssh root@172.16.135.134 | |
# root@172.16.135.134's password: | |
# [root@localhost ~]# | |
# | |
# [root pw is the user's pw you created on Easy install] | |
--------------------------------- | |
on HOST as ROOT | |
yum -y install perl gcc kernel-headers | |
mkdir /mnt/cdrom | |
mount /dev/sr0 /mnt/cdrom | |
cd /tmp | |
tar zxvf /mnt/cdrom/VMwareTools-9.2.2-893683.tar.gz | |
cd vmware-tools-distrib && ./vmware-install.pl -d | |
cd / | |
rm -rf /tmp/vmware-tools-distrib | |
adduser vagrant | |
groupadd admin | |
usermod -G admin vagrant | |
echo "vagrant:vagrant"|chpasswd | |
echo "root:vagrant"|chpasswd | |
# we want runlevel 3 | |
sed -i -e s/id:5:/id:3:/g /etc/inittab | |
# we don't want SELEENUX | |
sed -i -e s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config | |
# de-couple the MAC ADDRESS and UID for eth0 | |
sed -i -e '/HWADDR/ s/^/# /' /etc/sysconfig/network-scripts/ifcfg-eth0 | |
sed -i -e '/UUID/ s/^/# /' /etc/sysconfig/network-scripts/ifcfg-eth0 | |
# clean up suders file to just contain lines and no comments | |
# add the the required changes for vagrant | |
egrep -v '^[[:blank:]]*#|^$' /etc/sudoers > /tmp/sudoers | |
sed -i -e s/LS_COLORS"/SSH_AUTH_SOCK LS_COLORS"/ /tmp/sudoers | |
sed -i -e '/requiretty/ s/^/# /' /tmp/sudoers | |
echo '%admin ALL=NOPASSWD: ALL' >> /tmp/sudoers | |
cat /tmp/sudoers | |
cp /etc/sudoers /etc/sudoers_bk | |
# ensure you use real cp command, not an alias | |
\cp -f /tmp/sudoers /etc/ | |
# download and install the ssh keys for vagrant user | |
sudo su - vagrant | |
mkdir .ssh | |
curl -k https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub > .ssh/authorized_keys | |
chmod 0700 .ssh | |
chmod 0600 .ssh/authorized_keys | |
exit | |
# this is the critical udev fix that lets vagrant work | |
# this is found at: http://blog.hacka.net/#post64 | |
# i've not modified his script | |
cat << _EOF_ > /lib/udev/write_net_rules | |
#!/bin/bash | |
# Replacement for the default /lib/udev/write_net_rules script provided by Red Hat. | |
# Generate udev rules to order interfaces in the same order as their bus addresses. | |
# Credits: Skaperen @ http://www.linuxquestions.org/questions/linux-networking-3/overriding-etc-udev-rules-d-70-persistent-net-rules-903234/ | |
if ! test -d /sys/devices ; then | |
echo "${0}: ERROR: /sys appears to not be mounted" 1>&2 | |
exit 1 | |
fi | |
scansys() { | |
find /sys/devices -type d -wholename '/sys/devices/pci*/net' -print | |
} | |
extract() { | |
awk -F/ '{printf "%s eth%u\n",$(NF-1),NR-1;}' | |
} | |
generate() { | |
echo '# these rules are for persistence based on bus device address' | |
# No linebreaks below! | |
awk '{printf "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNELS==\"%s\", KERNEL==\"eth*\", NAME=\"%s\"\n",$1,$2;}' | |
} | |
scansys | extract | sort | generate >/etc/udev/rules.d/70-persistent-net.rules | |
_EOF_ | |
rm -f /etc/udev/rules.d/70-persistent-net.rules | |
udevadm trigger --action=change | |
udevadm control --reload-rules | |
# this creates a simple first-boot type | |
# do this just one time | |
mv /etc/rc.d/rc.local /etc/rc.d/rc.local.bak | |
echo "/lib/udev/write_net_rules" >>/etc/rc.d/rc.local | |
echo "udevadm trigger --action=change" >>/etc/rc.d/rc.local | |
echo "mv /etc/rc.d/rc.local.bak /etc/rc.d/rc.local" >>/etc/rc.d/rc.local | |
sudo yum clean all | |
init 6 | |
# When it comes back up, ensure vagrant keys are setup, and sudo is allowed: | |
$ ssh -i ~/.vagrant.d/insecure_private_key vagrant@172.16.135.134 | |
[vagrant@localhost ~]$ | |
[vagrant@localhost ~]$ sudo su - | |
[root@localhost ~]# | |
shutdown -h now | |
======================================================================================================= | |
Make the box | |
# my script is here: https://gist.github.com/dillera/6046134 | |
$ ./make_fusion_box.sh ~/VirtualMachines/vagrant-centos6_x64-fusion-3.vmwarevm ~/work/VagrantCustomBoxes vagrant-centos_x64-fusion-final1 | |
======================================================================================================= | |
Setup 2 vagrant hosts | |
# import in the box | |
vagrant box add centos6-final1 ~/work/VagrantCustomBoxes/vagrant-centos_x64-fusion-final1.box | |
# paste this into your shell to quickly setup 2 vagrant hosts to test the networking | |
--------------------------START PASTE-------------------------- | |
for i in final1 final2 | |
do | |
mkdir $i | |
cd $i | |
vagrant init | |
MYVAG=$i MYBOX=centos6-final2 cat << _EOF_ > Vagrantfile | |
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure("2") do |config| | |
config.vm.define :$MYVAG do |v| | |
v.vm.box = "$MYBOX" | |
v.vm.hostname = "$MYVAG" | |
v.vm.provider :vmware_fusion do |v| | |
v.vmx["numvcpus"] = "2" | |
v.vmx["coresPerSocket"] = "2" | |
v.vmx["memsize"] = "2048" | |
# v.vmx["ethernet0.addresstype"] = "static" | |
# v.vmx["ethernet0.address"] = "00:0C:29:49:50:DD" | |
# v.vmx["ethernet1.addresstype"] = "static" | |
# v.vmx["ethernet1.address"] = "00:0C:29:49:50:D3" | |
end | |
end | |
end | |
_EOF_ | |
cd .. | |
done | |
--------------------------END PASTE-------------------------- | |
# now go into each one and vagrant up... | |
[22:19][dillera@massivebook:~/work/vagrant/final2]$ vagrant up | |
Bringing machine 'final2' up with 'vmware_fusion' provider... | |
[final2] Cloning VMware VM: 'centos6-final2'. This can take some time... | |
[final2] Verifying vmnet devices are healthy... | |
[final2] Preparing network adapters... | |
[final2] Fixed port collision for 22 => 2222. Now on port 2200. | |
[final2] Starting the VMware VM... | |
[final2] Waiting for the VM to finish booting... | |
[final2] The machine is booted and ready! | |
[final2] Forwarding ports... | |
[final2] -- 22 => 2200 | |
[final2] Setting hostname... | |
[final2] Configuring network adapters within the VM... | |
[final2] Enabling and configuring shared folders... | |
*** Shared folders are still broken, but the host is up! | |
* Open a new terminal window, cd into that directory and: | |
vagrant ssh | |
========================================================================= | |
Both boxes up! Differnet IPs, different MACs! | |
[22:24]$ vagrant ssh | |
Last login: Tue Jul 23 18:46:47 2013 from 172.16.135.1 | |
[vagrant@final1 ~]$ | |
[vagrant@final1 ~]$ ifconfig -a | |
eth0 Link encap:Ethernet HWaddr 00:0C:29:5A:F3:7F | |
inet addr:172.16.135.134 Bcast:172.16.135.255 Mask:255.255.255.0 | |
inet6 addr: fe80::20c:29ff:fe5a:f37f/64 Scope:Link | |
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 | |
RX packets:383 errors:370 dropped:0 overruns:0 frame:0 | |
TX packets:256 errors:0 dropped:0 overruns:0 carrier:0 | |
collisions:0 txqueuelen:1000 | |
RX bytes:42036 (41.0 KiB) TX bytes:31274 (30.5 KiB) | |
Interrupt:18 Base address:0x2024 | |
lo Link encap:Local Loopback | |
inet addr:127.0.0.1 Mask:255.0.0.0 | |
inet6 addr: ::1/128 Scope:Host | |
UP LOOPBACK RUNNING MTU:16436 Metric:1 | |
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 | |
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 | |
collisions:0 txqueuelen:0 | |
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) | |
[vagrant@final1 ~]$ | |
[22:24]$ vagrant ssh | |
Last login: Tue Jul 23 18:46:47 2013 from 172.16.135.1 | |
[vagrant@final2 ~]$ ifconfig -a | |
eth0 Link encap:Ethernet HWaddr 00:0C:29:12:6B:DC | |
inet addr:172.16.135.136 Bcast:172.16.135.255 Mask:255.255.255.0 | |
inet6 addr: fe80::20c:29ff:fe12:6bdc/64 Scope:Link | |
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 | |
RX packets:365 errors:356 dropped:0 overruns:0 frame:0 | |
TX packets:253 errors:0 dropped:0 overruns:0 carrier:0 | |
collisions:0 txqueuelen:1000 | |
RX bytes:40100 (39.1 KiB) TX bytes:30984 (30.2 KiB) | |
Interrupt:18 Base address:0x2024 | |
lo Link encap:Local Loopback | |
inet addr:127.0.0.1 Mask:255.0.0.0 | |
inet6 addr: ::1/128 Scope:Host | |
UP LOOPBACK RUNNING MTU:16436 Metric:1 | |
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 | |
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 | |
collisions:0 txqueuelen:0 | |
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) | |
[vagrant@final2 ~]$ | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
have you looked into packer.io it will take a vmx and allow you to run provisioners etc ..