Friday, August 2, 2013

Vagrant, Virtualbox and OpenBSD 5.3

  1. Create instance in VirtualBox
    1. Download 5.3 ISO.
    2. Open it as the CD when Virtualbox starts.
    3. Configure VM: network adapter = NAT, no audio.
    4. Install OpenBSD.
  2. Setup OS for vagrant:
    1. Set hostname to vagrant
      # cat vagrant > /etc/myname
      # hostname vagrant
      
    2. Use DHCP
      # echo dhcp > /etc/hostname.em0
      # rm -f /etc/resolv.conf
      
    3. Install bash, as vagrant assumes this is the shell.
      # pkg_add bash
      
    4. Install python for provisioning with ansible.
      # pkg_add python
      Ambiguous: choose package for python
       a       0: <None>
               1: python-2.5.4p18
               2: python-2.7.3p1
               3: python-3.2.3.p0
      Your choice: 2
      ...
      
    5. Add vagrant user and put in wheel group.
      # adduser vagrant  
      shell = bash
      group = vagrant
      password = vagrant
      ...
      # usermod -G wheel vagrant
      
    6. Let users in wheel group sudo without a password.
      # visudo
      [uncomment the line:]
      %wheel ALL=(ALL) NOPASSWD: SETENV: ALL
      
    7. Get vagrant SSH keys
      # export h=http://github.com/mitchellh/vagrant/raw/master
      # ftp $h/keys/vagrant -o vagrant
      # ftp $h/keys/vagrant.pub -o vagrant.pub
      # cp vagrant ~vagrant/.ssh
      # cp vagrant.put ~vagrant/.ssh/authorized_keys
      # chmod 0700 ~vagrant/.ssh
      # chmod 0640 ~vagrant/.ssh/authorized_keys
      # chmod 0640 ~vagrant/.ssh/vagrant
      
    8. Vagrant uses port 2222.
      # sudo vi /etc/ssh/sshd_config
      [uncomment Port 22 line and add Port 2222 line after that.]
      
  3. Package up the virtual box.
    1. Use a standard name for the box.
      - Open VirtualBox.
      - Settings --> General --> Basic
      - Set name to vagrant_openbsd_5.3
      
    2. Export box.
      $ cd ~/VirtualBox\ VMs/vagrant_openbsd_5.3
      $ rm -f package.box
      $ vagrant package --base vagrant_openbsd_5.3
      [vagrant_openbsd_5.3] Clearing any previously set forwarded ports...
      [vagrant_openbsd_5.3] Creating temporary directory for export...
      [vagrant_openbsd_5.3] Exporting VM...
      [vagrant_openbsd_5.3] Compressing package to: /Users/mark/VirtualBox VMs/vagrant_openbsd_5.3/package.box
      $
      
  4. Install the box into vagrant.
    $ vagrant box remove vagrant_openbsd_5.3 virtualbox
    $ vagrant box add vagrant_openbsd_5.3 package.box
    Downloading or copying the box...
    Extracting box...te: 439M/s, Estimated time remaining: --:--:--)
    Successfully added box 'vagrant_openbsd_5.3' with provider 'virtualbox'!
    $ vagrant box list
    openbsd             (virtualbox)
    vagrant_openbsd_5.3 (virtualbox)
    $
    
  5. Install vagrant-guests-openbsd. It's actively developed: Vagrant 1.2.7 was released on July 27, 2013 and the vagrant-guests-openbsd plugin was updated on August 3, 2013.
    $vagrant plugin install vagrant-guests-openbsd
    
  6. Setup Vagrantfile. Using , as it provides better than what comes with Vagrant.
    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    
    VAGRANTFILE_API_VERSION = "2"
    
    Vagrant.require_plugin "vagrant-guests-openbsd"
    
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    
      # Every Vagrant virtual environment requires a box to build off of.
      config.vm.box = "vagrant_openbsd_5.3"
    
      # 
      config.vm.guest = :openbsd_v2
      
      config.vm.synced_folder "../", "/vagrant", :disabled => true
      #config.vm.synced_folder "../", "/vagrant", :nfs => true
    
      config.vm.network :private_network, ip: "192.168.67.10", netmask: "255.255.255.0"
    
      # Uncomment to debug.
      #config.vm.provider "virtualbox" do |v|
      #  v.gui = true
      #end
    
    end
    
  7. Use it.
    $ time vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    [default] Setting the name of the VM...
    [default] Clearing any previously set forwarded ports...
    [default] Creating shared folders metadata...
    [default] Clearing any previously set network interfaces...
    [default] Preparing network interfaces based on configuration...
    [default] Forwarding ports...
    [default] -- 22 => 2222 (adapter 1)
    [default] Booting VM...
    [default] Waiting for VM to boot. This can take a few minutes.
    [default] VM booted and ready for use!
    [default] No guest additions were detected on the base box for this VM! Guest
    additions are required for forwarded ports, shared folders, host only
    networking, and more. If SSH fails on this machine, please install
    the guest additions and repackage the box to continue.
    
    This is not an error message; everything may continue to work properly,
    in which case you may ignore this message.
    [default] Mounting shared folders...
    
    real  0m51.05s
    user  0m1.46s
    sys 0m0.55s
    
    
    $ vagrant ssh
    Last login: Fri Aug  2 15:39:10 2013 from 10.0.2.2
    OpenBSD 5.3 (GENERIC) #50: Tue Mar 12 18:35:23 MDT 2013
    
    Welcome to OpenBSD: The proactively secure Unix-like operating system.
    
    Please use the sendbug(1) utility to report bugs in the system.
    Before reporting a bug, please try to reproduce it with the latest
    version of the code.  With bug reports, please try to ensure that
    enough information to reproduce the problem is enclosed, and if a
    known fix for it exists, include that as well.
    
    $ whoami
    vagrant
    $ hostname
    vagrant
    $ exit
    Connection to 127.0.0.1 closed.
    
    
    $ time vagrant halt
    [default] Attempting graceful shutdown of VM...
    
    real  0m14.15s
    user  0m1.23s
    sys 0m0.50s
    $
    

No comments:

Post a Comment