Creating a vagrant base box for ubuntu 12.04 32bit server

Craig Perry edited this page Nov 21, 2013 · 12 revisions

Creating a base box in Vagrant

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 or hostname --fqdn commands)
  • Root Password: vagrant
  • Main account login: vagrant
  • Main account password: vagrant

Setup the Virtual Machine

  1. Download ubuntu server 32bit version

  2. 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.
  3. Run the machine and do a minimal installation of the machine

Prepare the Virtual Machine

Now with the machine loaded

  1. 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
    
  2. Change hostname

     sudo hostname vagrant
    
  3. Create admin group

     sudo groupadd admin
    
  4. assign the vagrant user to the admin group

     sudo usermod -G admin vagrant
    
  5. 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
    
  6. 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
    
  7. Install puppet

     sudo apt-get -y install puppet puppetmaster
    
  8. install openssh-server packages

     sudo apt-get -y install openssh-server
    
  9. 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
    
  10. Install virtual box guest additions

    1. 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
      
    2. 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
      
  11. Empty the cache

     sudo apt-get clean
    

Make the box

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

References

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.