Review of Alpine Linux
Table of Contents
Introduction
Busybox[1] is a very small implementation of the
most common UNIX utilities in a single executable. The project is
modular so you have the opportunity to include only what you need at
compile time. If you are curious about how it works a simple ls -l
of
tar
and ps
, for example, will show they are all symlink to the
busybox executable. The program will check argv[0]
to see how it was
invoked and will behave accordingly. It is very useful where resources
are limited like in Embedded Systems, initramfs[2],
Docker containers and lightweight distributions.
Musl[3] is an implementation of the C standard library, POSIX[4] and some extra extensions as well. It has been developed as an attempt to meet the requirements of the market of both its concurrents glibc[5] (typically used in Desktops and Servers) and uClibc[6] (tiny embedded systems).
Alpine Linux[7] is a lightweight distribution following the three S principles: Simple, Small and Secure:
- Standard C Library: Musl
- Init System: Busybox + OpenRC[8]
- Unix Utilities: Busybox
- Package MAnager: Apk (Alpine Package Keeper)
- Official Website: https://alpinelinux.org/
- User Handbook: https://docs.alpinelinux.org
- Official Wiki: https://wiki.alpinelinux.org
Requirements
In case you are in a situation where you have a Windows PC or laptop and you cannot install a dual-boot system to run Linux, you can install a Hypervisor of type 2 and install Linux in a Virtual Machine. In the past I liked using QEMU on a Linux host, but under Windows the hardware acceleration was not working properly and I had very slow VMs. So I have the choice between Hyper-V, VirtualBox and VMWare.
Hyper-V[10] is the native solution on Windows, but it is the most recent hypervisor of the three and I never used it before. I am also not sure how well it is supporting Linux guests. VMWare[12] looks like the most professional solution, but VirtualBox[11] is the product I am more familiar with, so I decided to start my tests with it.
I have installed the latest Debian with XFCE, Proton VPN Client[9] and Firefox. The official application of ProtonVPN supports only the main distro (Debian, Ubuntu, Fedora) however there is a guide to configure it with OpenVPN and WireGuard. So the Installation of the system and apps was very straight forward. I then installed the VirtualBox Guest Additions but I feel the performance is unstable: it is usable, but nothing special. The amount of disk space is rather high: around 4 GB.
I then tried my favorite distribution: Slackware. It works well, but the disk usage is too much: even without KDE, Tex and kernel sources it uses around 8 GB. I can fine-tune my installation for sure but I don’t want to spend too much time on it.
In the future I also would like to try a Kubernetes[13] cluster: in this context having a small VM will help me to avoid running out of resources when I will allocate multiple VMs for my cluster.
With all this in mind, let’s move on and see if Alpine Linux is suitable for my needs.
Installation of the base system
On the Download page you see multiple flavors so I had to start reading the section Image Type of the Handbook and found standard or virtual are the two choices I can opt for. The only difference between the two is the kernel. I started with virtual, but later I had to install the standard kernel because the audio card was not working.
Then the installation procedure in the Handbook lets you
choose if you want to proceed with an Automatic or a
Semi-Automatic installation. I usually go with the most manual
one because I like to tune my system, but this time I wanted to test
Alpine quickly so I proceeded with the Automatic Quick Mode. Ok, it
was too much basic and it didn’t install anything on the disk. So I
rerun setup-alpine
without the option -q
and this time the script
asked me a couple of questions. When asked about the disk the Handbook
doesn’t give much guidance, but looking at the installation guide in
the Wiki you can familiarize yourself with the different ways to install
Alpine and sys (System Disk Mode) is what we are looking for.
It is interesting to note the Diskless Mode. I haven’t tried it yet, but since I am generally happy with Alpine after the experiment reported in this article, I will test it as well and improve my article list on Linux Live distros running entirely from RAM.
The installation was quick and easy to perform and the basic system occupies less than 200 MB of storage. It is pretty basic and, because of Busybox, you might miss some of the flags in the UNIX utilities, however you can easily install the fully-fledged version of the various commands[14] (I was glad to see a very interesting article covering it in the Wiki).
The Handbook proceeds with the basic information required to use the
package manager and OpenRC. It was the first time I was looking
into it and if you are familiar with other package managers and init
systems you will pick up very quickly the new stuff. I was able to
install Firefox with all its dependencies just with a single apk add firefox
. I haven’t installed Xorg yet, so it is rather useless
Firefox at the moment, however the test was to see if I had to
struggle with extra steps that sometimes are required in other
lightweight distributions.
Let’s see how to set up the graphical environment in the next section.
X Window System and Windows Manager
Some distro have a concept of groups of packages or meta-packages
to install Xorg, a Window Manager and/or a full Desktop Environment
(like KDE, Gnome, XFCE, LXDE, etc). So I looked if I found anything on
the wiki. There are a lot of DEs and WMs supported on Alpine and they
are documented here[15]. Everything can be installed
with the command setup-desktop
and I was curious to know if I could
install just a basic Xorg server so I tried the autocompletion in the
shell hitting double tab after having typed setup-
and I saw
setup-xorg-base
.
Since performace issues usually come out looking at the bootstrap time and during graphical sessions, I looked up on the wiki also for any guidance on the installation in VirtualBox. Since I was also interested in having the best performances even in text-based VMs, I wanted to install the VirtualBox Guest Additions. It came out a page[16] where two packages are documented to get the best performances:
- virtualbox-guest-additions
- virtualbox-guest-additions-x11
(both installable with the standard package manager
apk
)
I installed BSPWM (with SXHK) [17] and the terminals xfce4-terminal, xterm and urxvt[18].
All of my systems in general boot in text mode and then I start the
X session manually using startx
. To achieve this goal I need to
create a file called .xinitrc in the user home folder and in that
script I need to call the executable bspwm. In some distros you find
examples of the xinitrc in /etc/X11/xinit, however I wasn’t lucky
this time. I also used to find an example of bspwmrc and
sxhkdrc in /usr/share/doc/bspwm/examples*. For the latter
issue I had to install the package bspwm-doc, while for .xinitrc
I tried to call directly bspwm -c $HOME/.bswpwmrc
. I created
$HOME/.bswpwmrc using almost the same content as the example:
#! /bin/sh
sxhkd -c $HOME/.sxhkdrc &
bspc monitor -d I II III IV V VI VII VIII IX X
bspc config border_width 2
bspc config window_gap 5
bspc config split_ratio 0.52
bspc config borderless_monocle true
bspc config gapless_monocle true
#bspc rule -a Gimp desktop='^8' state=floating follow=on
#bspc rule -a Chromium desktop='^2'
#bspc rule -a mplayer2 state=floating
#bspc rule -a Kupfer.py focus=on
#bspc rule -a Screenkey manage=off
I simply commented out the last part of the example because they are
not relevant to me and I have added -c $HOME/.sxhkdrc
to be sure
the daemon sxhkd will use my configuration. I copied the example in
$HOME/.sxhkdrc and I have added a couple of shortcuts in the
section terminal emulator:
# terminal emulator
super + Return
urxvt
super + q
xfce4-terminal
super + a
xterm
Let’s type startx
and see what’s happening. Bspwm starts properly
and both xterm and urxvt work properly, but when I tried
xfce4-terminal I saw squares instead of characters and the UI was
completely broken. Also Firefox looked almost working, except for some
weird squares. I thought it was a problem with the fonts so I
installed the package font-dejavu and restarted Xorg. After that
everything was fine.
I proceeded with my tests installing Alsa[19] and playing
a video from the browser. The video performances were
good and fluid, but there was no audio. I thought about a dependency
between Firefox and Pulseaudio that was not installed, but aplay -l
showed no audio cards available. The VirtualBox configurations seemed
ok, so it had to be an issue with the driver of the virtual audio
card. I was wondering if I had to perform another installation from
scratch using the standard ISO installer, but I tried to simply
install the package linux-lts. Luckily it installed a second kernel
and updated the Extlinux[20] configuration (the Boot
Loader) and, after reboot, I had aplay -l
showing the card and Firefox
playing my video with audio.
Everything is good so far. Compared to Debian I feel Alpine runs smoother but the quality of the audio is a little bit worse. I haven’t done any proper banchmark so it might be just an impression.
How much storage space is it used now with Xorg and Firefox? It is 600 MB. Very impressive.
Remote X Window
Since the X Window System follows a client-server architecture, it is possible to install a server implementation on Windows and run an X client like Firefox from the VM without installing Xorg.
I was curious to try this option and see how it performs. A rapid search on the web pointed me to the options:
- Cygewin/X (https://x.cygwin.com/)
- MobaXterm (https://mobaxterm.mobatek.net/)
- Xming (http://www.straightrunning.com/XmingNotes/ and https://sourceforge.net/projects/xming/files/)
- VcXsrv (https://github.com/marchaesen/vcxsrv/releases)
Cygewin and MobaXterm are not only a pure X server implementation, so I preferred to try the other two options. VcXsrv is currently actively developed and looks like the best option, however Windows Defender seems to complain about a Trojan:
https://github.com/marchaesen/vcxsrv/issues/29
This looks like a false positive, but I am paranoid in terms of security, so I preferred to not try my chances.
Xming was almost abandoned and if you want to download the latest release you need to pay. However an old implementation can be downloaded from SourceForge. This is what I did.
After the installation:
- run Xming
- SSH in the VM and execute
firefox
In theory it is only required to run ssh -X user@ip
or ssh -Y user@ip
and the setup of the remote X session should work out of the
box. However when I tried with both commands it failed. At first the
issue is that sshd does not allow remote X sessions. So I had to
change a couple of parameters in /etc/ssh/sshd_config:
X11Forwarding yes
AllowTcpForwarding yes
PermitTunnel yes
Even with this configuration it doesn’t seem to work. The
purpose of -X
or -Y
is just to create a remote tunnel and expose
TCP port 6000 (where Xmind is listening) to the VM. I checked
with netstat -alnp
and the problem is that there is no socket
listening on port 6000 in the VM so the fix is to explicitly
configure the tunnel and I was able to run my
graphic applications remotely with this:
# ssh into the VM and create the remote tunnel
ssh -R 6000:127.0.0.1:6000 user@ip
# export the DISPLAY variable
export DISPLAY=:0.0
# run Firefox
firefox
Firefox opened its window using Xming, but the performances were so poor I couldn’t really do anything.
There is actually another option I can try: VNC. I will probably test it in the future.
Docker and Kubernetes
Given the small footprint of the OS looks like the perfect candidate to try to use as a base for Docker and at least one of the lightweight Kubernetes distributions. I was wondering also to try a regular K8s installation with multiple VMs and I was surprised to find a page on their amazing wiki to do it:
- How to install Kubernetes - https://wiki.alpinelinux.org/wiki/K8s
- How to install Docker - https://wiki.alpinelinux.org/wiki/Docker
Conclusions
Alpine Linux is great!
Main features I loved:
- small footprint
- large number of packages available in their repositories
- easy to install a full Desktop Environment
- very well documented in their Wiki
- systemd-free
- simple to configure and use
The amazing Wiki and the focus on simplicity made me remember with nostalgia the early years of Arch Linux (before the adoption of systemd).
Looks like Alpine Linux is a good candidate to become my next favorite distribution.
References
[1] https://www.busybox.net/about.html
[2] https://www.kernel.org/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html
[3] https://musl.libc.org/about.html
[4] https://pubs.opengroup.org/onlinepubs/9699919799/
[5] https://sourceware.org/glibc/
[7] https://wiki.alpinelinux.org/wiki/Alpine_Linux:Overview
[8] https://github.com/OpenRC/openrc
[9] https://protonvpn.com/support/linux-vpn-setup/
[11] https://www.virtualbox.org/
[14] https://wiki.alpinelinux.org/wiki/How_to_get_regular_stuff_working
[15] https://wiki.alpinelinux.org/wiki/Desktop_environments_and_Window_managers
[16] https://wiki.alpinelinux.org/wiki/VirtualBox_guest_additions
[17] https://github.com/baskerville/bspwm
[18] https://software.schmorp.de/pkg/rxvt-unicode.html
[19] https://wiki.alpinelinux.org/wiki/ALSA
[20] https://wiki.syslinux.org/wiki/index.php?title=EXTLINUX