-
Notifications
You must be signed in to change notification settings - Fork 17
Creating a vagrant base box for ubuntu 12.04 32bit server
This tutorial is for creating a vagrant box for ubuntu 12.04 (LTS)
Along the tutorial you must follow this conventions
- Hostname: vagrant-[os-name], e.g. vagrant-debian-lenny
- Domain: vagrantup.com (causes delays in resolving own FQDN, as in
dnsdomainname
orhostname --fqdn
commands) - Root Password: vagrant
- Main account login: vagrant
- Main account password: vagrant
-
Download ubuntu server 32bit version
-
Create a virtual box called vagrant-precise32
- Make sure you allocate enough disk space in a dynamically resizing drive. Typically, we use a 40 GB drive, which is big enough for almost everything.
- Make sure the default memory allocation is not too high. Most people don’t want to download a box to find it using 1 GB of RAM. We typically set it at 360 MB to start, since that is the size of most small slices. The RAM is configurable by the user at run-time using their Vagrantfile.
- Disable audio, usb, etc. controllers unless they’re needed. Most applications don’t need to play music! So save resources by disabling these features.
-
Run the machine and do a minimal installation of the machine
Now with the machine loaded
-
Install basic packages
sudo apt-get -y install vim git-core
and then, make vim your default editor (personal preference)
sudo update-alternatives --config editor
-
Change hostname
sudo hostname vagrant
-
Create
admin
groupsudo groupadd admin
-
assign the vagrant user to the admin group
sudo usermod -G admin vagrant
-
Edit the sudoers file
and add this three lines to the file
Defaults env_keep="SSH_AUTH_SOCK" %admin ALL=NOPASSWD: ALL
After that, it should look like this:
# This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" Defaults env_keep="SSH_AUTH_SOCK" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges #%admin ALL=(ALL) ALL %admin ALL=NOPASSWD: ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL
-
Execute this bootstrap script using sudo:
#!/usr/bin/env bash apt-get -y update apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev cd /tmp wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz tar -xvzf ruby-1.9.3-p125.tar.gz cd ruby-1.9.3-p125/ ./configure --prefix=/usr/local make make install gem install chef ruby-shadow --no-ri --no-rdoc
-
Install puppet
sudo apt-get -y install puppet puppetmaster
-
install openssh-server packages
sudo apt-get -y install openssh-server
-
Install vagrant's public keys
mkdir ~/.ssh/ chmod 0755 ~/.ssh cd ~/.ssh wget http://github.com/mitchellh/vagrant/raw/master/keys/vagrant wget http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub mv vagrant.pub authorized_keys chmod 0644 authorized_keys
-
Install virtual box guest additions
-
first, install dkms and reboot
sudo apt-get -y install linux-headers-$(uname -r) build-essential dkms sudo reboot It is important to reboot before installing the guest additions, otherwise, they will not survive a kernel upgrade
-
then install the guest additions
Click on your VirtualBox window and select “Devices” and “Install Guest Additions”. The option is in the VM window, and not in the VirtualBox control panel. This will attach a virtual CD to your device, which you can mount and install the software from. sudo apt-get -y install linux-headers-$(uname -r) build-essential mkdir /media/cdrom mount /dev/cdrom /media/cdrom sudo sh /media/cdrom/VBoxLinuxAdditions.run
-
-
Empty the cache
sudo apt-get clean
go to the virtual box directory (ex: ~/VirtualBox VM/vagrant-precise32)
then execute
vagrant package --base vagrant-precise32
and you'll have the package.box
ready to use with vagrant :)
To add it to your box lists and init
vagrant box add vagrant-precise32 package.box
vagrant init vagrant-precise32
vagrant up