How to Setup Alpine on a Laptop

This post is going to go over how to install Alpine Linux on a laptop (should work for Desktop). Not only will I go over basic installation, I will explain how to get different necessities working to give a more out of the box feel. This will include the Sway window manager, wifi with wpa_supplicant, and sound via alsa.

Why Use Alpine Linux?

When writing this post I realized I just assumed you would already know why Alpine Linux is great. However, that is unrealistic. So the reason you might want to put up with this admittedly spartan experience ahead of you, is that Alpine Linux is really nice to use. Here are a few reasons why:

At least these are the reasons I am leaving behind Debian (which I will be eternally grateful to) for Alpine.

Basic Alpine Installation

The first thing we need to do is get Alpine Linux installed onto the laptop. The easiest way to do this is to use a USB pendrive. Installing Linux onto a pendrive is actually quite easy. Unfortunately, I had a hard time with Alpine. The reason is that I was using the standard ISO which worked great with QEMU. What works great is the extended version.

Make sure to download the latest extended version of the ISO here.

Prepare USB Pendrive

Before we copy the ISO to the pendrive we need to prepare the USB drive by clearing it of all its data. This step is quite necessary when you might already have a Linux ISO already installed on there. What can happen is that the files will get mixed up, and you wont know how bad it is when you are trying to boot. Cursing aloud about how it worked before but you did virtually the same thing and now it doesn't. Clear your pendrive's folks. One other thing, watch out for cheap USB pendrives, they will often times not work. Can be worth it to spend the bucks on a name brand device to ensure the success of these operations.

I'll be assuming you are on Linux but this should probably work on any posix system.

First you need to identify the path to the drive.

lsblk -p

You should see (assuming you only have one pendrive connected) two things your main hard drive, and the usb. Make sure in the next steps you aren't using the path to your hard drive!!! To ensure this, run lsblk -p before and after inserting the usb to tell what the difference is.

The path to the pen drive will most likely be at something like /dev/sdX, with X usually being 'b' or 'c'. I'll be using /dev/sdc for the example. Make sure your path doesn't have a number at the end like /dev/sdc1 as that is the partition. We don't want the partition, we want the whole disk.

There is a neat trick for this cleaning the drive assuming you are on Linux.

sudo dd if=/dev/zero of=/dev/sdc bs=1M status=progress

Here we set the input file to /dev/zero, the output file to the drive, the block size is set to 1 megabyte to help speed things up, and we want to visualize the progress. This might take a while depending on how big your drive is, so it is a good place to stop and take a nice, long break.

Once your pendrive is clean you can copy the iso over to it.

sudo dd if=alpine-extended-3.12.0-x86_64.iso of=/dev/sdc bs=1M status=progress

This will be over quickly since the iso is pretty small. Now unmount the drive. Then you will put the usb drive into the laptop you want to install Alpine on. Go about booting from it, (which is very laptop dependent). The other thing is that you will want to have an internet connection while going through the install process. Either plug in an ethernet cable or use a Linux compatible Wifi adapter.

Install Alpine Linux

Once you can boot from your pendrive you will login to the root user and run:

setup-alpine

This should be straightforward, as the defaults are fine. The only thing maybe worth noting is when it says to choose a disk make sure to choose your disk and not select the default which is none.

Reboot and voila! You have installed Alpine on your laptop. You can certainly stop here, but we are left with a pretty spartan device with no gui. So next I'll show how to install Sway, wifi, and sound.

Make It Usable

Install Wifi

If you are at this step and using wifi, you might notice that you don't have an internet connection. This is due to wpa_supplicant not running.

To fix this going forward and wpa_supplicant as a process to start at boot. Next time you reboot wpa_supplicant will start automatically.

rc-update add wpa_supplicant boot

To start wpa_supplicant:

rc-service wpa_supplicant start

Install Sway

This will mostly be a copy of my previous post, but focused on hardware instead of a VM and a some additional quality of life steps.

Install elogind

Sway seems to complain when you run it without a session, in order to appease it you need to be either running systemd, use elogind, or something similar.

Since alpine doesn't use systemd we don't want that. Instead we can use elogind.

greetd might also do the trick, and seems like a viable alternative to elogind, but I have not tried it yet.

In order to install elogind we need to enable the edge community repos. Uncomment it in the file at /etc/apk/repositories. Then update your repo indices and install elogind.

apk update
apk add elogind

I would suggest recommenting the line for edge community repos here because we don't need it anymore. Make sure to run apk update again.

As part of this whole session business we need to make a non-root user.

adduser *username*

Add them to video and input groups.

adduser *username* video
adduser *username* input

We don't need to login into the user account just yet, but we will need to before we start Sway.

More packages before Sway

We need to add some more packages before we install Sway.

apk add eudev
setup-udev

apk add xkeyboard-config libinput font-noto

Another important package is the graphics driver. This will depend on your laptop architecture. For me I just installed the intel package.

apk add mesa-dri-intel

Run apk search mesa-dri to see more packages to find the right driver for your laptop.

Install Sway

This is the fun part installing our window manager to start using a GUI!

apk add sway alacritty

Which will install sway and a cool terminal that is wayland compatible.

If you are a hacker type, and want to try out Wayland, I encourage you not to install xwayland that way you can see what works on Wayland natively and what doesn't. Overall, I've noticed Wayland apps to be much crisper than xwayland apps so there is a benefit at the end of the day.

If you just want things that work then install Xorg:

apk add xorg-server-xwayland dmenu

dmenu runs on X and is a useful widget. bemenu is an option too but at the time of writing this had a few bugs on Wayland, but should be usable in the future.

Now we want to start up Sway.

Starting Sway

Make sure to logout from root, then relogin as the nonroot user we made earlier. This will start the session we need to run Sway. Start sway like this:

XDG_RUNTIME_DIR=/tmp sway 2> sway.log

This will start sway and log any errors to sway.log, which is helpful in case you run into trouble.

Woohoo! We have a GUI. I recommend setting up your config now. An easy way to get started is to copy the default one.

mkdir -p ~/.config/sway
cp /etc/sway/config ~/.config/sway/
$EDITOR ~/.config/sway/config

Now config to your hearts content and maybe even show it off on r/unixporn.

Setting Up Sound

So you are going along and having a good time when, suddenly you realize your laptop has no sound. The way to fix this is to install alsa-utils. Make sure you are root when doing these steps.

apk add alsa-utils

Setup alsa to be started by OpenRC.

rc-service alsa start
rc-update add alsa

Now you can configure sound by running alsamixer.

alsamixer

Use F6 to select a sound card, you will know it works when you see volume controls. Select the master and turn the volume up, and press M to make sure it is not muted. Press Esc to exit the mixer. That should be all you need to get sound working now.

Conclusion

There you have it a somewhat detailed guide on how to insall Alpine Linux on a laptop. A few things I didn't go over were how to use Wifi without a Linux compatible adapter, or an ethernet connection.

My answer to that is support hardware vendors that are Linux compatible, or lookup how to copy the driver over and install it.

The other thing I think worth mentioning is most Linux user's are used to using sudo to get root access, but I would suggest looking at doas since it is an Alpine package as well.

If you run into any issues check out the Alpine wiki. Hope you enjoy the awesomeness that is Alpine Linux.

Content for this site is CC-BY-SA.

More Posts