My current use for this VM is to run ansible. I use SSH to access the VM (both for running commands and transferring files), so don't bother running a GUI on it, or shared folders.

This document was tested with VirtualBox v5.0.20 r106931, running under Windows 7, and installing AlpineLinux v3.3.3 x64. It is assumed that VirtualBox is already installed.

Obtain installer ISO

Go to the downloads section of https://alpinelinux.org/ and download the 64-bit "Standard ISO" - I got alpine-3.3.3-x86_64.iso - save it somewhere you can find it again.

Setup VM

  • Start VirtualBox, and click [New] to create a new VM.
  • Set the name as suits you, set Type="Linux", Version="Linux 2.6 / 3.x / 4.x (64bit)", click [Next].
  • Set Memory size to 256MB, click [Next].
  • Select "Create a new virtual hard disk" and click [Create].
  • Select "VDI" and click [Next].
  • Select "Dynamically allocated" and click [Next].
  • Set size to 2GB and click [Create].

The blank machine should now be created, and will be listed in the VirtualBox window, on the left. Right-click on the machine and choose "Settings". Configure as follows:

  • System > Motherboard
    • Base Memory = 256MB
    • Boot Order = Optical, Hard Disk (untick Floppy)
    • Pointing Device = PS/2 Mouse
    • Hardware clock in UTC Time
  • Display > Screen
    • Video Memory = 1MB
      • NOTE: VirtualBox will complain about this, but I'm planning to connect via ssh, so will not be using any appreciable amount of video ram.
  • Storage
    • in the Storage Tree, select the CD just under "Controller IDE"
    • in the Attributes section, click on the CD icon at the far right.
    • Choose Virtual Optical Disk File and select your ISO (alpine-3.3.3-x86_64.iso)
  • Audio
    • disable
  • Network > Adapter 1
    • Adapter1 attached to: NAT
    • Click the blue triangle to expand "Advanced" settings, then click [Port Forwarding]
    • In the top-right corner, click the green symbol with the "+" on it
      • Name = "SSH"
      • Protocol = "TCP"
      • Host Port = "22022" (or whatever suits you)
      • Guest Port = "22"
      • click [OK]
  • Serial Ports > Port 1
    • disable
  • USB
    • disable

Basic Alpine Linux Install

  • Start the VM.
  • Login as root (no password required).

Run "setup-alpine", and configure as follows:

  • keyboard layout = "us"
  • keyboard variant = "us"
  • system hostname = whatever suits you
  • initialise interface: "eth0"
  • "dhcp"
  • no manual setup
  • enter root password, as desired.
  • timezone: "Pacific/Auckland" (or whatever suits you)
  • HTTP/FTP proxy URL: [none]
  • Detect and add fastest mirror (f)
  • SSH server: "openssh"
  • NTP client: "chrony"
  • install to disk: "sda"
  • install type: "sys"
  • erase & continue? Y

Wait for it to install...

Now run "poweroff" to shutdown the VM - this is necessary in order to reboot into the installed system, so we can install things there.

Remove CD

In the main VirtualBox window, right-click on the machine and choose "Settings". Reconfigure as follows:

  • Storage
    • in the Storage Tree, select the CD just under "Controller IDE".
    • in the Attributes section, click on the CD icon at the far right.
    • Choose "Remove disk from virtual drive", and click OK.

Update Packages

Start the VM. When it has finished booting, the login prompt should show the hostname you selected (instead of "localhost"). Login as "root", using the password you setup.

Use vi to edit the repositories - uncomment all the URL lines to enable them all.

vi /etc/apk/repositories

It should look something like this (but probably different URLs, depending on which ones were detected as being fastest for you):

#/media/cdrom/apks
http://dl-6.alpinelinux.org/alpine/v3.3/main
http://dl-6.alpinelinux.org/alpine/v3.3/community
http://dl-6.alpinelinux.org/alpine/edge/main
http://dl-6.alpinelinux.org/alpine/edge/community
http://dl-6.alpinelinux.org/alpine/edge/testing

Update the package list and upgrade what has already been installed:

apk update
apk upgrade

The base install at this stage will have used about 25MB of the boot partition (nominally about 100MB, but 92.8MB reported), 512MB as swap, and 270MB of the root partition - if the base disk was 2GB, about 1GB is free on the root drive.

Setup User and Sudo

Create the sudo group, create a non-root user (use whatever username you like, instead of "otheruser"), and add the new user to the sudo group:

addgroup sudo
adduser otheruser
adduser otheruser sudo

Install sudo

apk add sudo

Run "visudo" and remove the "#" comment character from the 2nd line in this group so it looks like:

## Uncomment to allow members of group sudo to execute any command
%sudo ALL=(ALL) ALL

Setup VirtualBox Drivers

The VirtualBox drivers improve performance of a VM running under VirtualBox.

apk add virtualbox-guest-modules-grsec virtualbox-additions-grsec

Reboot the VM by typing "reboot".

Test

You should now be able to login as the non-root user you created (using the non-root password you provided).

Once logged in, you should be able to execute commands as root by using sudo (and the non-root user password), eg. "sudo apk update" - if sudo is not working correctly, it will give an error, eg. if you weren't using sudo at all:

testvm:~$ apk update
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

If sudo is working correctly, the command will execute, eg.:

testvm:~$ sudo apk update
fetch http://dl-6.alpinelinux.org/alpine/v3.3/main/x86_64/APKINDEX.tar.gz
fetch http://dl-6.alpinelinux.org/alpine/v3.3/community/x86_64/APKINDEX.tar.gz
fetch http://dl-6.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-6.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-6.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
v3.3.3-46-ge9c0256 [http://dl-6.alpinelinux.org/alpine/v3.3/main]
v3.3.3-47-g150c9b2 [http://dl-6.alpinelinux.org/alpine/v3.3/community]
v160223-1826-g4681e7d [http://dl-6.alpinelinux.org/alpine/edge/main]
v160223-1826-g4681e7d [http://dl-6.alpinelinux.org/alpine/edge/community]
v160223-1826-g4681e7d [http://dl-6.alpinelinux.org/alpine/edge/testing]
OK: 15131 distinct packages available

SSH

It should also be possible to SSH from the host machine to the VM at address "localhost" (or "127.0.0.1"), and port "22022"

References