Recipes and instructions on how to build an Alpine Linux VM with Golang compiler support.
In order to install a new Alpine Linux VM, you need to:
- go to the Alpine Linux download site and download the latest Alpine Linux ISO image; under the "VIRTUAL" label there is one that is specifically optimised to be run as a guest VM (for example, see here)
- run Oracle VirtualBox, create a new VM and make sure that is has:
- some RAM (not very mus: actually a bare VM only seems to take as much as 64 MB)
- a 8 GB dynamically-allocated hard disk
- the Alpine Linux ISO image mounted into the CD-ROM
- NAT networking with port-forwarding to grant both:
- access to the internet from the guest, which is necessary to download additional software packages once the VM is up and running, and
- access to the SSH server from the host: the single port forwarding rule to add via the GUI, which can be named "SSH", must allow TCP connections from "empty" host's (literally leave the field empty in the GUI) port 2222 to "empty" guest on port 22;
this will make sure that when you run
ssh -p 2222 root@localhost
on the host you'll end up logging into the guest
- fire the VM and, once the live distribution has started up, log in as
root
(no password) and at the prompt runsetup-alpine
, then follow the instructions; the only things worth being noted are:- for Italy, choose
it
, then againit
as keyboard layout and sub-layout; then chooseCET
for the timezone - choose
sda
as the drive to install to, andsys
(meaning persistent, full system) as the install type.
- for Italy, choose
During the install process you will be requested to change root
's password; any password (including password
) will do, but in order for the machine to be a valid Vagrant Base Box, root
's password must be vagrant
.
Once the machine is up and running, go the VirtualBox GUI and remove the ISO image from the CD-ROM, then on VirtualBox's GUI, menu Machine
, send an ACPI Shutdown
to halt it, or at the command prompt type
$> poweroff
Take a snapshot before you start installing stuff, just in case...
reboot
restarts the machine; poweroff
shuts it down by sending an ACPI signal, halt
stops the CPU (without powering down).
In order to enable SSH access to the root
user:
- edit the
/etc/ssh/sshd_config
file asroot
- add a line in the
Authentication
section of the file that saysPermitRootLogin yes
- restart the sshd service:
$> /etc/init.d/sshd restart
and then check its status with
$> rc-status
Then on the host you can connect to the guest by running
$> ssh -p 2222 root@localhost
This step is required to create a Hashicorp Vagrant base image; for details, see here.
In order to setup VirtualBox Guest Additions, you must edit the Alpine Linux's package manager's configuration file, /etc/apk/repositories
, to include the community
packages. To do so, simply edit the file and make sure that the community
is uncommented:
#/media/cdrom/apks
http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/v3.9/main
- #http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/v3.9/community
+ http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/v3.9/community
#http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/edge/main
#http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/edge/community
#http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/edge/testing
then update the packages and proceed to installation:
$> apk update
$> apk add virtualbox-guest-additions virtualbox-guest-modules-virt
then reboot the system:
$> reboot
an when it starts up again, install the module:
$> modprobe -a vboxsf
Now you can open the Devices > Shared Folders > Shared olders Settings
menu on the VirtualBox GUI and define one or more shared folders; suppose you want to mount your host's /path/to/my/data
folder as the guest's /mnt/outside
, you select the host's path (/path/to/my/data
), give a symbolic name to the shared folder (e.g. Data
), and specify that you want it mounted as permanent
, auto-mount
ed at boot in read/write
mode, then provide the /mnt/outside
path as the mountpoint.
Then at the guest's CLI you type:
$> mount -t vboxsf <Shared Folder Name> <Guest Mountpoint>
e.g.
$> mount -t vboxsf Data /mnt/outside
and the host's Data
folder, which is path/to/my/data
, will be available in read/write mode under the guest's mnt/outside
.
That's it!
In order for the machine to be a valid Vagrant Base Box (see here for details), it needs to:
- install package
sudo
and enable thewheel
group (the sudoers)
$> apk install sudo
$> sed -e 's/# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/g' -i /etc/sudoers
- have a valid
vagrant
user, withvagrant
password
$> adduser -S vagrant -s /bin/ash -G wheel
$> passwd vagrant
Type password: *******
Re-type password: *******
- have a set of insecure pre-defined keys for automatic logon of the
vagrant
user, which can be downloaded from here; the public key should be downloaded to the Alpine machine and copied intovagrant
's home directory:
$> mkdir -p /home/vagrant/.ssh/
$> cat /mn/outside/vagrant.pub >> /home/vagrant/.ssh/authorized_keys
$> chmod 700 /home/vagrant/.ssh
$> chmod 600 /home/vagrant/.ssh/authorized_keys
In order to package the VM as a Vagrant Base Box, run
$> vagrant package --base <my-virtual-machine>
where <my-virtual-machine>
is the name of the VirtualBox image.
... or you can simply refer to a pre-packaged Alpine Linux Base Image on Hashicorp's cloud:
Vagrant.configure("2") do |config|
config.vm.box = "roboxes/alpine39"
end
or
Vagrant.configure("2") do |config|
config.vm.box = "generic/alpine39"
end
For more information see also the Robox Github page
TODO