Skip to content

Instantly share code, notes, and snippets.

@alexandrinos
Last active December 27, 2015 21:25
Show Gist options
  • Save alexandrinos/6c62b19ce1c841f0adb4 to your computer and use it in GitHub Desktop.
Save alexandrinos/6c62b19ce1c841f0adb4 to your computer and use it in GitHub Desktop.
Vagrant - create a vagrant base box from another
#fire up a new box
vagrant init hashicorp/precise64
vagrant up
#optional customization in the vm
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install vim
sudo apt-get install apache2
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
sudo mysql_install_db
sudo /usr/bin/mysql_secure_installation
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
sudo apt-get install php5-cgi php5-cli php5-curl php5-common php5-gd php5-mysql
sudo service apache2 restart
#option : cleaning the vm
sudo apt-get clean
#UBUNTU Beginn
sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY
#UBUNTU End
#bash&history cleaning
cat /dev/null > ~/.bash_history && history -c && exit
#repackage the vm into a new box
vagrant package --output mynew.box
#add the box in the vagrant
vagrant box add mynewbox mynew.box
#remove the old box
vagrant destroy
rm Vagrantfile
#initialize
vagrant init mynewbox
#now we can customize it with the box with the new name in Vagrantfile,if we want
cat /dev/null > Vagrantfile
echo '
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "mynewbox"
config.vm.network "private_network", ip: "192.33.33.33"
config.vm.hostname = "mynewbox"
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
' > Vagrantfile
echo 'Done'
#copy a public key to the remote VM using the private key from the Vagrant box
#and appendinf to the authorized_keys ; for permissions see ssh public key
cat ~/.ssh/id_rsa.pub | ssh -i ubuntu64_trusty/.vagrant/machines/default/virtualbox/private_key root@ulisse 'cat >> ~/.ssh/authorized_keys'
#ssh into the box with the private with, not with the vagrant ssh
ssh vagrant@192.168.33.10 -i .vagrant/machines/default/virtualbox/vagrant_private_key
#to login as a root(not very clever) modify sshd_config
PermitRootLogin yes #after that you need to create a passwd for root with $ passwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment