Skip to content

Setup Virtualbox with Apline Linux

Resources

Host Machine

  • Install alpine plugin - vagrant plugin install vagrant-alpine

Instructions

Download Alpine Linux distribution and install in VirtualBox

  • Alpine Linux Downloads - Download Virtual Distribution for x86_64.
  • VirtualBox Install
  • 1GB Ram, 8GB HD
  • Install Alpine Linux
  • Mount alpine-virt-3.6.1-x86_64.iso to start installation
  • Login with root
  • setup-alpine to install
  • poweroff to turn off the virtualbox
  • Remove virtual iso
  • Setup Alpine box
  • Uncomment extra repositories
    • vi /etc/apk/repositories
  • apk update - get latest package list
  • apk upgrade - Upgrade to latest versions
  • apk add bash - Install base
  • apk add sudo - Add sudo
  • adduser vagrant - vagrant user
  • vi /etc/sudoers
  • Use visudo
    • Add line: vagrant ALL=(ALL) NOPASSWD: ALL - add sudo without password
  • Edit */etc/ssh/sshd_config
    • set UseDNS no
  • Setup Virtualbox
  • VirtualBox guest additions
    • echo "http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
    • apk add virtualbox-additions-grsec
    • apk add virtualbox-guest-additions-5.1.22-r2
    • echo vboxpci >> /etc/modules
    • echo vboxdrv >> /etc/modules
    • echo vboxnetflt >> /etc/modules
  • reboot

Setup Vagrant

  • Create Vagrant base
    • vagrant package --base {virtualbox}
    • vagrant box add alpine-linux package.box
    • vagrant init alpine-linux
    • Install vagrant plugin for alpine - vagrant plugin install vagrant-alpine
    • Configure Vagrantfile maier/packer-templates
          Vagrant.configure(2) do |config|
          config.vm.define 'alpine' do |alpine|
              alpine.vm.box = 'maier/alpine-3.6-x86_64'
              # alpine.ssh.username = 'vagrant'
              # alpine.ssh.password = 'vagrant'
      
              # NOTE:
              #   there are *no* guest additions installed
              #   for alpine linux - the guest additions
              #   installer fails. once workarounds are
              #   identified the vbga will be added
              #   to the base box.
              #
              # since there are no vbga. if the vagrant-alpine plugin
              # is installed it can at least configure the system to
              # enable shared folders.
              #
              alpine.vm.synced_folder '.', '/vagrant', disabled: true
              #
              # after `vagrant plugin install vagrant-alpine`
              # comment the disabled synced_folder line above and
              # uncomment the following two lines
              #
              # alpine.vm.network 'private_network', ip: '192.168.100.10'
              # alpine.vm.synced_folder '.', '/vagrant', type: 'nfs'
      
              alpine.vm.provider 'virtualbox' do |vb|
                  # vb.gui = true
                  vb.name = 'Alpine'
                  vb.cpus = 1
                  vb.memory = 1024
                  vb.customize [
                      'modifyvm', :id,
                      '--natdnshostresolver1', 'on',
                      '--nic1', 'nat',
                      '--cableconnected1', 'on'
                  ]
              end
          end
      end
      
  • My Config
    Vagrant.configure("2") do |config|
      config.vm.box = "maier/alpine-3.6-x86_64"
      config.vm.box_check_update = false
      config.vbguest.auto_update = false
      config.vm.synced_folder "./vmshared", "/vagrant_data", disabled: true
      config.vm.network 'private_network', ip: "192.168.33.10"
      config.vm.synced_folder ".", "/vagrant_shared", type: "nfs"
      config.vm.provider "virtualbox" do |vb|
        vb.name = "Maier Alpine"
        vb.cpus = 1
        vb.memory = 1024
        vb.customize [
          'modifyvm', :id,
          '--natdnshostresolver1', 'on',
          '--nic1', 'nat',
          '--cableconnected1', 'on'
        ]
      end
    end
    
  • Added config.vbguest.auto_update = false to eliminate it trying to update
  • Added config.vbguest.auto_update = false to not check for updates
  • Using nfs to share volumes
  • vagrant up

Install packages

apk update && \
apk add nginx bash ca-certificates s6 curl ssmtp php7 php7-phar php7-curl \
php7-fpm php7-json php7-zlib php7-xml php7-dom php7-ctype php7-opcache php7-zip php7-iconv \
php7-pdo php7-pdo_mysql php7-pdo_sqlite php7-pdo_pgsql php7-mbstring php7-session \
php7-gd php7-mcrypt php7-openssl php7-sockets php7-posix php7-ldap php7-simplexml

Other Notes

Misc

  • Search for packages - apk search {name}

Shutdown

  • poweroff
  • halt

Accessing services on the guest box

  • Setup Port Forwarding
  • ssh - local port 2222 - guest host port - 22
  • Use ssh -p 2222 vagrant@127.0.0.1 - will give you access to the guest box

Last update: April 13, 2020 16:50:19