Skip to content

Instantly share code, notes, and snippets.

@ungeskriptet
Last active June 9, 2024 10:14
Show Gist options
  • Save ungeskriptet/25bd890d8f6606dc6fa403b8bfd5003d to your computer and use it in GitHub Desktop.
Save ungeskriptet/25bd890d8f6606dc6fa403b8bfd5003d to your computer and use it in GitHub Desktop.
Installing Alpine Linux "the Arch way"
# Installing Alpine Linux "the Arch way" by bootstrapping a chroot
# This sequence of commands will setup a sys install with edge repos for an EFI system
# Setup internet connection and keyboard layout
# Exit with Ctrl+C once it asks you to change the root password
setup-alpine
# Create 512 MiB EFI boot partition and rootfs partition
apk add sfdisk e2fsprogs
sfdisk /dev/vda
label: gpt
,512M,U
;
write
# Reload partition table
blockdev --rereadpt /dev/vda
# Format and mount both partitions
mkfs.vfat /dev/vda1
mkfs.ext4 /dev/vda2
mount -t ext4 /dev/vda2 /mnt
mkdir -p /mnt/boot
mount -t vfat /dev/vda1 /mnt/boot
# Setup rootfs
apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main -X https://dl-cdn.alpinelinux.org/alpine/edge/community -U --allow-untrusted -p /mnt --initdb add alpine-base linux-edge efibootmgr kbd-bkeymaps tzdata vim doas/sudo wpa_supplicant dnsmasq networkmanager networkmanager-dnsmasq networkmanager-wifi networkmanager-tui networkmanager-cli eudev udev-init-scripts udev-init-scripts-openrc dosfstools e2fsprogs file iputils dmesg
# Mount necessary filesystems for efibootmgr
mount --bind /sys /mnt/sys
mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
mount --bind /dev /mnt/dev
# Get internet working inside chroot
cp -L /etc/resolv.conf /mnt/etc/
# Chroot into new rootfs
chroot /mnt
setup-hostname
setup-keymap
setup-timezone
passwd
# Enable necessary services
for i in dmesg udev udev-trigger udev-settle; do rc-update add $i sysinit; done
for i in loadkmap seedrng modules; do rc-update add $i boot; done
for i in acpid crond udev-postmount networkmanager; do rc-update add $i default; done
# NOTE: Use efistub for booting kernel. Secure boot must be off for this to work!
efibootmgr --create --disk /dev/vda --part 1 --label "Alpine Linux" --loader /vmlinuz-edge --unicode "root=/dev/vda2 rootfstype=ext4 initrd=initramfs-edge quiet loglevel=3 sysrq_always_enabled=1"
# If efibootmgr does not work, you can add the boot entry manually through UEFI shell. Copy over the shell efi binary from e.g. the edk2-shell Arch Linux package to a FAT32 formatted USB drive under EFI/BOOT/BOOTX64.EFI
# X is the drive where kernel and initramfs are located
Shell> fsX
Shell> bcfg boot add 1 vmlinuz-edge "Alpine Linux"
# Due to the UTF-16LE encoding, the first charachter will be cut off. The whitespace was left there for purpose.
# Press F2 to save and F3 to exit
Shell> edit cmdline.txt
root=/dev/vda2 rootfstype=ext4 initrd=initramfs-edge quiet loglevel=3 sysrq_always_enabled=1
Shell> bcfg boot -opt 1 cmdline.txt
Shell> reset
# Setup edge apk repositories
echo -e "https://dl-cdn.alpinelinux.org/alpine/edge/main\nhttps://dl-cdn.alpinelinux.org/alpine/edge/community" > /etc/apk/repositories
# Create new user with UID 1000
adduser -s /bin/ash -u 1000 -G wheel -g "User" user
passwd user
# If you installed doas, run these commands below. Replace "presist" with nopass to disable password authentication.
mkdir -p /etc/doas.d
echo "permit persist :wheel" >> /etc/doas.d/doas.conf
# If you installed sudo, comment out one line that starts with '%wheel'. If you uncomment the line with NOPASSWD, sudo will not ask your for a password
EDITOR=vim visudo
# Reboot computer and boot into the newly installed Alpine Linux system
reboot
# Setup internet connection
sudo nmtui
# Optional: Setup KDE Plasma
sudo apk add xorg-server xf86-input-libinput mesa-dri-gallium sddm elogind ark bluedevil breeze breeze-gtk dbus discover drkonqi font-noto gwenview kate kde-cli-tools kde-gtk-config kde-icons kdeplasma-addons kgamma kinfocenter kio-fuse kmenuedit konsole kscreen ksshaskpass kwallet-pam kwayland-integration pinentry-qt pipewire-alsa pipewire-pulse plasma-browser-integration plasma-desktop plasma-disks plasma-nm plasma-pa plasma-systemmonitor plasma-vault plasma-welcome plasma-workspace-wallpapers polkit-elogind polkit-kde-agent-1 powerdevil print-manager sddm-breeze sddm-kcm spectacle systemsettings udisks2 xdg-desktop-portal-kde xdg-user-dirs firefox ocean-sound-theme
for i in dbus elogind sddm; do sudo rc-update add $i; done
# Setup keyboard layout for SDDM
mkdir -p /etc/X11/xorg.conf.d
echo Section '"InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "de"
EndSection' >> /etc/X11/xorg.conf.d/00-keyboard.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment