Giter Site home page Giter Site logo

alpine-golang-vm's Introduction

How to create an Alpine Linux VM with a Golang compiler

Recipes and instructions on how to build an Alpine Linux VM with Golang compiler support.

Set up the virtual machine

In order to install a new Alpine Linux VM, you need to:

  1. 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)
  2. run Oracle VirtualBox, create a new VM and make sure that is has:
    1. some RAM (not very mus: actually a bare VM only seems to take as much as 64 MB)
    2. a 8 GB dynamically-allocated hard disk
    3. the Alpine Linux ISO image mounted into the CD-ROM
    4. NAT networking with port-forwarding to grant both:
      1. access to the internet from the guest, which is necessary to download additional software packages once the VM is up and running, and
      2. 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
  3. fire the VM and, once the live distribution has started up, log in as root (no password) and at the prompt run setup-alpine, then follow the instructions; the only things worth being noted are:
    1. for Italy, choose it, then again it as keyboard layout and sub-layout; then choose CET for the timezone
    2. choose sda as the drive to install to, and sys (meaning persistent, full system) as the install type.

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).

Enable root access via SSH

In order to enable SSH access to the root user:

  1. edit the /etc/ssh/sshd_config file as root
  2. add a line in the Authentication section of the file that says PermitRootLogin yes
  3. 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

Install VirtualBox guest additions

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-mounted 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!

Fulfill the other Vagrant Base Box requirements

In order for the machine to be a valid Vagrant Base Box (see here for details), it needs to:

  1. install package sudo and enable the wheel group (the sudoers)
$> apk install sudo
$> sed -e 's/# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/g' -i /etc/sudoers
  1. have a valid vagrant user, with vagrant password
$> adduser -S vagrant -s /bin/ash -G wheel
$> passwd vagrant
Type password: *******
Re-type password: *******
  1. 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 into vagrant'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

Package the Alpine Linux Base Box

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...

... 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

Install the golang toolchain

TODO

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.