Install Alpine

Format the microSD

Make partitions

parted /dev/sda
(parted) mklabel msdos
(parted) mkpart primary fat32 0% 3Gib
(parted) mkpart primary ext4 3Gib 100%
parte /dev/sda print
Model: Generic- SD/MMC (scsi)
Disk /dev/sda: 31,9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  3221MB  3220MB  primary  fat32        lba
 2      3221MB  31,9GB  28,7GB  primary  ext4

Make filesystems

mkfs.fat -F32 /dev/sda1
mkfs.ext4 /dev/sda2

Install Alpine

Download it from here. For my RaspberryPi 3 Model B+ I used aarch64. Then mount the boot partition (sda1) and copy all the files in there.

mount /dev/sda1 /mnt/sdcard
tar zxvf ~/Downloads/alpine-rpi-3.12.0-aarch64.tar.gz -C /mnt/sdcard
sync
umount /mnt/sdcard

Now extract the card and power up the device. Once it booted, login with root without password.

Setup Keymap

setup-keymap
Select keyboard layout [none]: es
Select variant []: es

Setup Network

localhost:~# setup-interfaces
Available interfaces are: eth0 wlan0.
Enter ´?´ for help on the bridges, bonding and vlans.
Which one do you want to initialize? (or ´?´ or ´done´) [eth0] <enter>
Ip address for eth0? (or ´dhcp´, ´none´, ´?´) [dhcp] <enter>
Available interfaces are: wlan0.
Enter ´?´ for help on the bridges, bonding and vlans.
Which one do you want to initialize? (or ´?´ or ´done´) [wlan0] done<enter>
Do you want to do any manual network configuration? [no] <enter>
localhost:~# rc-service networking start
...

Setup SSHd

localhost:~# setup-sshd
Which SSH server? (´openssh´, ´dropbear´ or ´none´) [openssh] <enter>

Use vi to edit /etc/ssh/sshd_config and allow to connect with root and password by adding PermitRootLogin yes. Then change root password with passwd. And restart the daemon rc-service sshd restart. You can now connect trough ssh to it.

Now you can connect through SSH and execute setup-alpine.

See full log

Commit changes and reboot

localhost:~# lbu commit

Persistent Storage

The install is in diskless mode and forces everything into memory, if you want additional storage we need to create loop-back storage onto the SD mounted with overlayfs.

Mount the storage:

echo "/dev/mmcblk0p2 /media/mmcblk0p2 ext4 rw,relatime,errors=remount-ro 0 0" >> /etc/fstab
mkdir /media/mmcblk0p2
mount -a

Make the overlay folders, we are doing /usr here, but you can do /home or anything else:

storageDir=/media/mmcblk0p2
for dir in /home /lib /root /sbin /usr /var/lib/docker; do
  if ! grep -q "overlay ${dir}" /etc/fstab; then
    cd $storageDir
    mkdir -p ./${dir} ${dir}
    cd ./${dir}
    mkdir -p data .work
    echo "overlay ${dir} overlay lowerdir=${dir},upperdir=${storageDir}${dir}/data,workdir=${storageDir}${dir}/.work 0 0" >> /etc/fstab
    mount -a
    echo "Mounted overlay ${dir}"
  else
    echo "Mountpoint ${dir} already exists"
  fi
done
Add a user
addgroup david
adduser -h /home/david -G david david
Important notes

Remember with this setup, if you install things and you have done this overlay for /usr, you must not commit the ‘apk add’, otherwise while it boots it will try and install it to memory and not to the persist storage.

If you do want to install something small at boot you can use apk add and lbu commit -d.

If it is something a bit bigger then you can use apk add but then not commit it, it will be persistent (in /user), but do check everything you need is in that directory and not in folders you have not made persistent.

Info

I had many issues with lbu detecting the changes, so I ended up making the apkovl by hand. Remounting the partition rw: mount /dev/mmcblk0p1 -o rw,remount. Extracting, adding the files and compressing them again.