Skip to content

Instantly share code, notes, and snippets.

@vitorcalvi
Last active December 30, 2025 15:19
Show Gist options
  • Select an option

  • Save vitorcalvi/d5d787dcdab807a9bc2699763758cab6 to your computer and use it in GitHub Desktop.

Select an option

Save vitorcalvi/d5d787dcdab807a9bc2699763758cab6 to your computer and use it in GitHub Desktop.
Alpine Linux AMD GPU Workstation Setup Script
#!/bin/sh
# Alpine Linux System Setup Script - V2 (ROBUST FIX)
# Target: AMD Ryzen 7 H 255 (Zen 4) / Radeon 780M
# Alpine Linux v3.23+
set -e
echo "=== Alpine Linux System Setup ==="
echo "This script will install and configure packages for an AMD Ryzen APU workstation"
echo ""
# --- Pre-reqs & Repositories ---
echo "[0/10] Enabling Community Repository..."
# Safely uncomment community repo
sed -i '/^#http:\/\/.*\/community/s/^#//' /etc/apk/repositories
apk update
# --- Core Installations ---
echo "[1/10] Installing core system utilities..."
apk add \
bash \
curl \
git \
nano \
htop \
btop \
unzip \
tar \
openssl \
ca-certificates \
build-base \
shadow \
util-linux \
dbus \
dbus-openrc
echo "[2/10] Installing hardware tools..."
apk add \
pciutils \
usbutils \
hwinfo \
lshw \
drm_info
echo "[3/10] Installing AMD GPU (Radeon 780M) and Audio support..."
# Switching to PipeWire for modern Audio/Video handling
apk add \
linux-firmware-amdgpu \
sof-firmware \
mesa \
mesa-dri-gallium \
mesa-vulkan-ati \
mesa-egl \
mesa-gl \
mesa-gles \
mesa-gbm \
mesa-va-gallium \
mesa-demos \
mesa-utils \
vulkan-loader \
libva \
libva-utils \
radeontop \
eudev \
eudev-openrc \
alsa-utils \
alsa-ucm-conf \
pipewire \
pipewire-pulse \
wireplumber \
pipewire-alsa
echo "[4/10] Installing networking tools..."
apk add \
openssh \
openssh-server \
tailscale \
iproute2 \
iptables \
nftables \
bridge-utils \
wpa_supplicant
# --- Docker Installation ---
echo "[5/10] Installing Docker Engine..."
apk add \
docker \
docker-cli \
docker-cli-buildx \
docker-cli-compose \
containerd \
runc
# --- LLaMA.cpp & CPU Optimizations ---
echo "[6/10] Installing CPU Optimizations for LLaMA.cpp..."
apk add linux-tools numactl
# Set CPU Governor to 'performance'
if command -v cpupower >/dev/null 2>&1; then
modprobe msr 2>/dev/null || true
cpupower frequency-set -g performance 2>/dev/null || echo " [!] cpupower: unable to set governor (may require reboot or kernel module)"
else
echo " [!] cpupower command not found, skipping governor setup"
fi
# Create Environment Profile for LLMs
cat <<EOF > /etc/profile.d/llama-cpu.sh
# LLaMA.cpp Optimizations for Ryzen 7 H 255 (Zen 4)
# Mobile Zen 4 AVX-512 is 256-bit wide; forcing AVX2 often sustains higher clocks.
export OMP_NUM_THREADS=8
export OMP_SCHEDULE=static
export GOMP_CPU_AFFINITY=0-7
# Alias for running LLaMA.cpp with NUMA support
alias llama-run='numactl --cpunodebind=0 --membind=0'
EOF
echo "[7/10] Configuring Docker..."
mkdir -p /etc/docker
cat <<EOF > /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"live-restore": true,
"storage-driver": "overlay2",
"ip6tables": true,
"experimental": false
}
EOF
# Add docker group if missing
addgroup docker 2>/dev/null || true
echo "[8/10] Installing System Tools..."
apk add \
doas \
e2fsprogs \
dosfstools \
grub \
grub-efi \
linux-lts \
linux-lts-dev \
linux-headers \
mkinitfs \
efibootmgr \
zram-init
# --- Post-Configurations ---
echo "[9/10] Applying System Post-Configurations..."
# 1. Set Hostname
echo "brain" > /etc/hostname
hostname -F /etc/hostname
# 2. Configure Locale
apk add musl-locales
echo 'export LANG=en_US.UTF-8' > /etc/profile.d/locale.sh
# 3. Configure Timezone (UTC)
apk add tzdata
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
echo "UTC" > /etc/timezone
# Clean up tzdata to save space
rm -rf /usr/share/zoneinfo/*
# 4. Configure Keymaps (US) - Non-interactive
apk add kbd-bkeymaps
cat <<EOF > /etc/conf.d/keymaps
keymap="us"
windowkeys="YES"
extended_keymaps="euro2"
EOF
# 5. Enable ZRAM
rc-update add zram-init default
# Set ZRAM to use 50% of RAM (Critical for Alpine)
echo "ALGO=lzo-rle" > /etc/conf.d/zram-init
echo "PERCENT=50" >> /etc/conf.d/zram-init
# 6. Optimize Grub for AMD IOMMU & Framebuffers
if [ -f /etc/default/grub ]; then
if ! grep -q "amd_iommu=on" /etc/default/grub; then
# Using awk to safely append to existing cmdline
awk -v val="amd_iommu=on iommu=pt video=efifb:nobgrt" '
/^GRUB_CMDLINE_LINUX_DEFAULT="/ {
sub(/"$/, " " val "\"");
}
{ print }
' /etc/default/grub > /tmp/grub.tmp && mv /tmp/grub.tmp /etc/default/grub
echo " [+] Updated GRUB with AMD IOMMU parameters"
fi
fi
# 7. Configure Doas
if [ ! -f /etc/doas.conf ]; then
echo 'permit persist :wheel' > /etc/doas.conf
chmod 600 /etc/doas.conf
fi
# 8. Add System Aliases
cat <<'EOF' >> /etc/profile
# User Aliases
alias ll='ls -laFh'
alias la='ls -A'
alias l='ls -CF'
alias df='df -h'
alias free='free -h'
alias update='apk update && apk upgrade'
# Docker Aliases
alias d-ps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'
alias d-stats='docker stats --no-stream'
alias d-prune='docker system prune -f'
EOF
# --- Services ---
echo "[10/10] Enabling Services..."
# --- ROBUST SERVICE FIX ---
# Detect the udev service name and ensure it's installed
UDEV_SERVICE=""
if [ -f /etc/init.d/eudev ]; then
UDEV_SERVICE="eudev"
elif [ -f /etc/init.d/udev ]; then
UDEV_SERVICE="udev"
else
echo " [!] Udev init script not found. Forcing reinstall..."
apk add --force-reinstall eudev-openrc
# Re-check
if [ -f /etc/init.d/eudev ]; then
UDEV_SERVICE="eudev"
else
echo " [!] CRITICAL ERROR: Still cannot find eudev service script."
echo " [!] Aborting service configuration to prevent half-configured state."
exit 1
fi
fi
echo " [+] Detected udev service: $UDEV_SERVICE"
# 1. Remove mdev (default) and enable udev
rc-update del mdev sysinit 2>/dev/null || true
rc-update add ${UDEV_SERVICE} sysinit
rc-update add ${UDEV_SERVICE}-trigger sysinit
rc-update add ${UDEV_SERVICE}-settle default
# 2. Standard Services
rc-update add dbus default
rc-update add docker default
rc-update add containerd default
rc-update add tailscale default
rc-update add sshd default
rc-update add acpid default
rc-update add crond default
# 3. Audio Services (PipeWire)
rc-update add pipewire default
# Start critical services immediately (Best effort)
rc-service dbus start
rc-service ${UDEV_SERVICE} start || true
rc-service ${UDEV_SERVICE}-trigger start || true
rc-service pipewire start || true
echo ""
echo "=== CRITICAL FINAL STEPS ==="
echo ""
echo "1. Update GRUB (Required for IOMMU & GPU support):"
echo " grub-mkconfig -o /boot/grub/grub.cfg"
echo ""
echo "2. Create User & Groups:"
echo " adduser <username>"
echo " addgroup <username> wheel"
echo " addgroup <username> audio"
echo " addgroup <username> video"
echo " addgroup <username> docker"
echo ""
echo "3. CPU Optimization Status:"
echo " - Governor: attempt made (verify with 'cpupower frequency-info')"
echo " - LLaMA CPU Profile: /etc/profile.d/llama-cpu.sh"
echo ""
echo "4. COMPILE LLAMA.CPP (Recommended Flags for Mobile Zen 4):"
echo " git clone https://github.com/ggerganov/llama.cpp.git"
echo " cd llama.cpp"
echo " cmake -B build -DLLAMA_AVX2=ON -DLLAMA_FMA=ON -DLLAMA_F16C=ON"
echo " cmake --build build -j8"
echo ""
echo " Note: AVX-512 is DISABLED in recommendation above. Mobile Ryzen"
echo " chips throttle significantly with AVX-512, resulting in slower"
echo " inference speeds than AVX2. Only add -DLLAMA_AVX512=ON if you have"
echo " aggressive cooling and want to test thermal limits."
echo ""
echo "5. Test GPU:"
echo " vainfo (Should show VA-API drivers)"
echo " vulkaninfo --summary"
echo ""
echo "6. Reboot:"
echo " reboot"
echo ""
echo "=== Setup Complete ==="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment