Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Daemonslayer2048/3a6d9f78ec3418574250320496da8327 to your computer and use it in GitHub Desktop.
Save Daemonslayer2048/3a6d9f78ec3418574250320496da8327 to your computer and use it in GitHub Desktop.
Build AlpineLinux
# Mount your USB
mkdir /tmp/usb
mount *your usb*
cd /tmp/usb
# As we speak latest version is apk-tools-static-2.9.1-r0. If you get 404 you will need to change it with actual version.
wget http://uk.alpinelinux.org/alpine/latest-stable/main/aarch64/apk-tools-static-2.9.1-r0.apk
tar -xzf apk-tools-static-*.apk
# Pulling the "stage3" binaries;
./sbin/apk.static -X http://uk.alpinelinux.org/alpine/latest-stable/main --arch aarch64 -U --allow-untrusted --root . --initdb add alpine-base
# Mounting the chrooted environment;
# Prep environment
mount -t proc none proc
mount -o bind /sys sys
mount -o bind /dev dev
cp /etc/resolv.conf etc/
# Enter chroot
chroot . /bin/sh -l
source /etc/profile
export PS1="(alpine) ${PS1}"
# Adding the APK repo;
echo "http://uk.alpinelinux.org/alpine/latest-stable/main" > /etc/apk/repositories
echo "http://uk.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories
- Installing few essential packages;
apk update && apk upgrade
apk add chrony
apk add util-linux
apk add openssh openssh-server
apk add sudo
apk add shadow
apk add bash
apk add lshw
apk add file
apk add e2fsprogs
# Enabling a bunch of rc services;
rc-update add devfs sysinit
rc-update add dmesg sysinit
rc-update add mdev sysinit
rc-update add modules boot
rc-update add sysctl boot
rc-update add hostname boot
rc-update add bootmisc boot
rc-update add networking boot
rc-update add syslog boot
rc-update add mount-ro shutdown
rc-update add killprocs shutdown
rc-update add savecache shutdown
rc-update add networking boot
rc-update add swclock boot
rc-update add sshd default
rc-update add local default
rc-update add ntpd default
# Your /etc/fstab should look similar to this (this is a simple rootfs plus /boot layout);
/dev/mmcblk0p1 /boot vfat noauto,noatime 1 2
/dev/mmcblk0p2 / ext4 noatime 0 1
- This create a 50mb compressed zram swap disk. The script goes into /etc/local.d/zram.start;
``` sh
#!/bin/sh
modprobe zram
SIZE=50
echo $((50*1024*1024)) > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon /dev/zram0 -p 20
```
chmod +x /etc/local.d/zram.start
# This will unmount the zram swap disk prior to shutdown. Script goes into /etc/local.d/zram.stop;
``` sh
#!/bin/sh
swapoff /dev/zram0
echo 1 > /sys/block/zram0/reset
modprobe -r zram
```
chmod +x /etc/local.d/zram.stop
# Add the following to /etc/network/interfaces;
auto eth0
iface eth0 inet dhcp
# Specifying a server for ntpd to work;
echo 'NTPD_OPTS="-4 -N -p pool.ntp.org"' > /etc/conf.d/ntpd
# Create a new user;
adduser alpine -s /bin/bash -h /home/alpine
addgroup alpine wheel
# No testing for below has been done yet
- In order for the Wireless NIC to work you will need to install the linux-firmware package which contains the Broadcom drives;
# apk update && apk add linux-firmware
- Since /lib/firmware/brcm is only really needed, if you want to save space you could backup the brcm folder, remove the linux-firmware package and place back the brcm folder to /lib/firmware/ .
- Load the Broadcom modules on boot
# echo -e 'b43 \nbrcmfmac' >> /etc/modules
- Add the following entries to /boot/cmdline.txt. Make sure root= matches the / partition;
root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes rootwait
- If you made it this far you should now have a minimal Alpinelinux 3.7 aarch64 rootfs. Though you might also want a kernel to actually boot the system up...
- Here is the /boot folder https://goo.gl/hKECev which contains kernel 4.10.17-v8+, blobs for the Wireless NIC the bootcode as well as the usual overlays for the RPI3.
- Basically just extract it directly to the /boot partition of the sdcard;
# tar xvjf rpi3-alpine-boot.tar.bz2 -C /path/of/whatever/boot
- Installation guide needs to be revised, though aside from some nonesense it should work just fine https://pastebin.com/raw/RfNQ5tXv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment