Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ravibhure
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravibhure/2dfcccc0401f1667dfef to your computer and use it in GitHub Desktop.
Save ravibhure/2dfcccc0401f1667dfef to your computer and use it in GitHub Desktop.
Vagrant on CentOS and Ubuntu
Setup Vagrant and a small quick start
Setup Vagrant and a small quick-start I had troubles with an regular VM so i installed vagrant :), this is what i have done. And installed Vagrant like described here.
================================================
For Ubuntu --
URL: http://vagrantup.com/docs/getting-started/setup/ubuntu.html
Or follow the instructions here:
Install Ruby
$ sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby wget
$ sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby
$ sudo ln -s /usr/bin/ri1.8 /usr/bin/ri
$ sudo ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc
$ sudo ln -s /usr/bin/irb1.8 /usr/bin/irb
Install RubyGems
$ cd ~/
$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
$ tar xvzf rubygems-1.3.7.tgz
$ cd rubygems-1.3.7
$ sudo ruby setup.rb
$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
================================================
================================================
For CentOS --
$ yum -y install gcc make ruby-devel rubygems ruby
$ wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
$ rpm --import oracle_vbox.asc
$ rm -f oracle_vbox.asc
$ wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo -O /etc/yum.repos.d/virtualbox.repo
$ yum -y install VirtualBox-4.1
================================================
$ update RubyGems
$ sudo gem update --system
Now Ruby is installed and updated RubyGems. VirtualBox OSE if it is not already installed check if its at least the 4.1 or higher.
Install vagrant, its actually very easy to do, go back to terminal and type:
$ gem install vagrant
Then install a vagrant box by typing:
$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
You can a specify name for the vagrant box you just download, with this command.
$ vagrant box add <your-name> <http://your.vagrant.box/url>
Its also possible to download different vagrant boxes like ubuntu or lucid64 bit here are some urls:
ubuntu 11.04 server i386 http://dl.dropbox.com/u/7490647/talifun-ubuntu-11.04-server-i386.box
ubuntu 11.04 server amd64 http://dl.dropbox.com/u/7490647/talifun-ubuntu-11.04-server-amd64.box
scientific linux 6 64 http://download.frameos.org/sl6-64-nochef.box
centos 5.6 32 http://yum.mnxsolutions.com/vagrant/centos_56_32.box
puppet debian lenny 32 https://s3-eu-west-1.amazonaws.com/glassesdirect-boxen/debian/debian_lenny_32_puppet_backport.box
debian lenny 32 https://s3-eu-west-1.amazonaws.com/glassesdirect-boxen/debian/debian_lenny_32.box
puppet debian lenny 64 ttp://puppetlabs.s3.amazonaws.com/pub/debian_lenny_64.box
debian squeeze 64 rvm https://s3-eu-west-1.amazonaws.com/rosstimson-vagrant-boxes/debian-squeeze-64-rvm.box
puppet solaris 10 64 http://puppetlabs.s3.amazonaws.com/pub/solaris10_64.box
puppet squeeze 64 http://puppetlabs.s3.amazonaws.com/pub/squeeze64.box
devstructure maverick 64 http://static.devstructure.com/devstructure64.box
devstructure maverick 32 http://static.devstructure.com/devstructure32.box
puppet rhel 6 64 http://puppetlabs.s3.amazonaws.com/pub/rhel60_64.box
puppet centos 4 64 http://puppetlabs.s3.amazonaws.com/pub/centos4_64.box
puppet sles 11sp1 64 http://puppetlabs.s3.amazonaws.com/pub/sles11sp1_64.box
puppet centos 5.5 64 http://puppetlabs.s3.amazonaws.com/pub/centos5_64.box
gentoo 64 http://dl.dropbox.com/u/4270274/gentoo64-0.7.box
opscode ubuntu 10.04 http://opscode-vagrant-boxes.s3.amazonaws.com/ubuntu10.04-gems.box
opscode centos 5 http://opscode-vagrant-boxes.s3.amazonaws.com/centos5-gems.box
ubuntu maverick 64 http://mathie-vagrant-boxes.s3.amazonaws.com/maverick64.box
Now init a new vagrant box with the command
$ vagrant init <your vagrant box name>
This creates a file called Vagrantfile, and now its time to rock! Type vagrant up.
$ vagrant up
Your out put souled be something like this:
[default] Importing base box 'base'...
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- ssh: 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Running any VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant
Thats it!
Remove a vagrant box:
$ vagrant box remove my_box
Some vagrant commands
$ vagrant box list
$ vagrant box remove <my_box>
$ vagrant init
$ vagrant ssh
$ vagrant up
$ vagrant halt
$ vagrant destroy
$ vagrant restart
$ vagrant resume
$ vagrant suspend
$ vagrant box repackage foo
# Misc
# To increase Vagrants cpu and mem edit Vagrantfile with following appropriate settings and reload vagrant to use 'vagrant reload'
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "lucid32"
config.vm.provider :virtualbox do |vb, override|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "4"]
end
How to update VirtualBox Guest Additions with vagrant
# Start the old vagrant
$ vagrant init centos-6.3
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on
# this machine, please update the guest additions and repackage the
# box.
#
# Guest Additions Version: 4.1.18
# VirtualBox Version: 4.2.8
$ vagrant ssh
vagrantup:~$ sudo yum -y update
vagrantup:~$ cd /opt
vagrantup:~$ sudo wget -c http://download.virtualbox.org/virtualbox/4.2.8/VBoxGuestAdditions_4.2.8.iso \
-O VBoxGuestAdditions_4.2.8.iso
vagrantup:~$ sudo mount VBoxGuestAdditions_4.2.8.iso -o loop /mnt
vagrantup:~$ cd /mnt
vagrantup:~$ sudo sh VBoxLinuxAdditions.run --nox11
vagrantup:~$ cd /opt
vagrantup:~$ sudo rm *.iso
vagrantup:~$ sudo /etc/init.d/vboxadd setup
vagrantup:~$ sudo chkconfig --add vboxadd
vagrantup:~$ sudo chkconfig vboxadd on
vagrantup:~$ exit
# Now check that the Guest Additions work
$ vagrant halt
$ vagrant up
# Package the new VM
$ vagrant halt
$ vagrant package
$ mv package.box centos-6.3.box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment