Setup of Alpine linux on bare metal systems.
Of interest, this guide was written using a VM as a test case for deployment on a Thin Client. The VM matched the Thin Client's resources (2 cores, 2GB RAM, 4GB Storage, One Gb Ethernet, 1 Wireless Adapter (actual USB Wireless dongle - testing drivers)). At the end of this guide, the system still has 1.5GB of storage space remaining (with the 1GB of swap never being used)! RAM usage has sat around 148MB/2GB. Impressive.
Some of this guide uses extracts from other online guides. Please see the credits section at the bottom for credits.
TBA
- Load Alpine to USB
-
Set Boot Partition to 500MB.
export BOOT_SIZE=500
-
Set system Swap sizing.
export SWAP_SIZE=2048
-
Set system Bootloader type.
export BOOTLOADER=grub
-
Identify the system's internal drive alias in preperation for system setup.
df -h
NOTE: On most systems it is likely to be /dev/sda1. However on some systems (like thin clients) it may be different due to them using different storage technologies. For example, Thin client might me /dev/mmcblk0.
-
Run Alpine system setup script (Installation).
setup-alpine
This script will run through and setup Alpine's configuration. The parameters to be setup are:
-
Keyboard and Variant.
-
Hostname.
-
Network options:
3a. Select the eth0 adapter, this is the onboard ethernet port
3b. You can either specify DHCP or setup static networking.
3c. DNS Options. It is recommended to use 8.8.8.8 and none for the domain
-
Time zone options: Just use the suggested defaults.
-
Proxy Options: Use noneif you are connecting directly to the Internet.
-
SSH Options. Select OpenSSH.
-
NTP Options. Chrony is a good choice.
-
Boot Mode:
8a. Select sys to install the system on disk.
8b. TBA.
- Disk Options. Select the system disk based on drive identified in Step 4. Most systems will use sda, however some (Thin Clients) might use mmcblk0*.
This setup will create the following disk structure.
- /dev/sda1 as BOOT (500MB) in /boot
- /dev/sda2 as SWAP (2GB (if 2048 specified), or 1GB (if 1024 specified))
- /dev/sda3 as ROOT (rest of available disk space).
-
After these have run through the system will be fully initialised and Alpine will be installed to the internal system disk. Reboot to apply.
reboot
This section is a WIP, but is used to highlight functions of Alpine and how they contrast to Debian (to make conversion to this OS easier).
- apk = Alpine Package Keeper. The debian alternative to this would be apt. This is used to manage packages in the Alpine OS, such as upgrade or install packages.
- add = Install a Package, or upgrade an existing one.
- del = Delete an installed package.
-
Update the system package list.
apk update
-
Install pending system updates.
apk upgrade
-
Install a package.
apk add <package name>
su
su -
This section is optional but used to install other applications such as docker or Wireless drivers.
Before installing any services, its bet to run the commands below as a root user. To enter the root terminal, run;
su
On initial install, Alpine is configured to use the MAIN package repository to fetch its packages. This is fine, but some packages, such as Docker, are only available on the COMMUNITY package repository. By default, the COMMUNITY repository is disabled, meaning if you try to install a package (in this case Docker), which is only available on the COMMUNITY repository, then you will get an error;
ERROR: unable to select packages:
docker (no such package):
required by: world[docker]
To fix this, you will have to enable the COMMUNITY repository.
-
Check the installed repository lists.
tail -f /etc/apk/repositories
You should see both the /main and /community are listed, but the /community is commented out with a #.
-
Run Vim editor to enable the community repository.
vi /etc/apk/repositories
-
Remove the # in front of the /community link.
-
To save the file, press the escape key. Then key the following;
:wq
-
Update the package list with the new repository.
apk update
You should see the /community version be printed. Now you can go ahead and install packages.
To search for available packages and their names, use the links below.
NOTE: This package index features ALL linux distros, to search for Alpine specifically, you have to use the filters.
** Before starting, don't forget to become the root user.**
su
apk add nano
Installing Docker is a several step process.
-
Download and install the package.
apk add docker
-
Connect to Docker by adding yourself to the docker group
addgroup ${USER} docker
-
Set Docker to start at system boot, and run now.
rc-update add docker default service docker start
-
Now that Docker is installed and setup, Docker Compose needs to be installed.
apk add docker-cli-compose
docker run --name docker-nginx -p 80:80 nginx
Go to the systems IP address, on port 80 and you should see the Nginx landing page!.
apk add htop
This section is specifically for setting up the Realtek WiFi dongle on my system.
Run commands as root user
su
-
Update the system package repository.
apk update
-
Install WPA Supplicant.
apk add wpa_supplicant
-
Install the Realtek Wi-Fi driver.
apk add --upgrade linux-firmware-rtlwifi
Package info and supported devices
-
List network adapters. Look for the wlan0 specifially to make sure it is listed.
ip a
-
Add your wireless credentials to the WPA Supplicant configuration file.
wpa_passphrase 'ExampleWifiSSID' 'ExampleWifiPassword' > /etc/wpa_supplicant/wpa_supplicant.conf
-
Start WPA Supplicant in the foreground to confirm it works.
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
-
If Step 6 worked, run it in the background.
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
-
Check the adapter has come up (it won't have an IP yet).
ip a
-
Configure the interface with an IP address.
udhcpc -i wlan0
-
Check the interface has successfully leased an IP from the DHCP Server.
ip addr show wlan0
-
Set the Wi-Fi adapter and DHCP to start automatically on boot.
nano /etc/network/interfaces
-
Add wlan0 definition to the file
auto wlan0 iface wlan0 inet dhcp
-
Test to make sure everything is configured correctly and the interface will come up as expected. First bring the interface down.
ip link set wlan0 down
-
Now manually restart the networking service.
rc-service networking --quiet restart &
-
Now that everything is setup and works, set WPA supplicant to start automatically on boot.
rc-update add wpa_supplicant boot
-
Ensure networking is set to start automatically on boot.
rc-update add networking boot
With the above configuration, udhcpc will only run once at boot. If the Wifi isn't available then, or the network changes after booting, udhcpc needs to be notified. You can automatically notify udhcpc of network changes by using a wpa_cli action file, such as the one installed by default at /etc/wpa_supplicant/wpa_cli.sh
.
-
MANUALLY
wpa_cli -a /etc/wpa_supplicant/wpa_cli.sh
-
AUTOMATICALLY
-
Open the WPA CLI file.
nano /etc/conf.d/wpa_cli
-
Copy the update command into the file.
WPACLI_OPTS="-a /etc/wpa_supplicant/wpa_cli.sh"
-
Set the WPA CLI to start on system boot.
rc-update add wpa_cli boot