Raspberry Pi K3s Alpine Linux Part 1
Vietnamese version can be read at Vie-Ver.
Setup OS
- Download the Raspberry Pi build.
Which version should I install?
There are currently three versions of Alpine for Raspberry Pi:
armhf
,armv7
, andaarch64
. The aarch64 build should be compatible Raspberry Pi 3 and Compute Module 3, and Raspberry Pi 4 Model B. i will choiceaarch64
.cd /tmp wget https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/aarch64/alpine-rpi-3.16.2-aarch64.tar.gz
Partition and format the memory card.
I using
Raspbian
to createusb
alpineboot
for rpi. Install GNU Parted (parted) if not available.sudo apt install parted
First of all Insert the SD card and check it have been existed. My sd card is
sda
.$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 58.2G 0 disk `-sda1 8:1 1 58.2G 0 part /media/pi/SDCARD mmcblk0 179:0 0 29.7G 0 disk |-mmcblk0p1 179:1 0 256M 0 part /boot `-mmcblk0p2 179:2 0 29.5G 0 part /
Create a small partition for
/boot
, then allocate the rest of the disk to a separate partition.sudo parted /dev/sda --script -- mklabel msdos sudo parted /dev/sda --script -- mkpart primary fat32 1 256M sudo parted /dev/sda --script -- mkpart primary ext4 256M 100%
Format the boot partition to
FAT32
and the rest isext4
:sudo parted /dev/sda --script -- set 1 boot on sudo parted /dev/sda --script -- set 1 lba on sudo mkfs.vfat -F32 /dev/sda1 sudo mkfs.ext4 /dev/sda2
Verify by printing the partition table.
$ sudo parted /dev/sda --script print Model: SD Card Reader (scsi) Disk /dev/sda: 62.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 256MB 255MB primary fat32 lba 2 256MB 62.5GB 62.3GB primary ext4
Mount the boot partition.
sudo mkdir /mnt/sd sudo mount /dev/sda1 /mnt/sd
Unpack the Alpine package onto the partition.
# i have download alpine image at /tmp in step-1 sudo tar xf /tmp/alpine-rpi-**.tar.gz -C /mnt/sd --no-same-owner
Create the
usercfg.txt
file into the boot partition:/mnt/sd/usercfg.txt
.# Enable mini UART as serial port (/dev/ttyS0). # Also, fixes VideoCore IV (aka the GPU or the VPU) frequency to 250MHz. enable_uart=1 # give the GPU the least amount of RAM it can get by with (16MB). # This also triggers the Pi to use a cutdown version of the firmware (start_cd.elf). gpu_mem=16 # Optionally turn off audio and bluetooth. (Note "dt" stands for device tree) dtparam=audio=off,pi3-disable-bt
Headless Installation (optional)
If you don’t have direct access to your system, such as via a display and keyboard you can install Alpine with the overlay directory structure and headless script.
sudo curl -L -o /mnt/sd/headless.apkovl.tar.gz https://github.com/davidmytton/alpine-linux-headless-raspberrypi/releases/download/2021.06.23/headless.apkovl.tar.gz
Wifi Configuration (optional)
With the headless script installed. Create the
wifi.txt
into the boot partition:/mnt/sd/wifi.txt
.ssid password
Unmount.
sudo umount /mnt/sd
Installation
Log in into Alpine with the default username and password. If you have a headless installation you can ssh into the Raspberry Pi.
Default Alpine login credentials are username
root
with empty password.Run setup.
setup-alpine
Create system partitions.
Resize the FAT32 partition to 1GB and use the remaining space to create a new primary bootable partition where Alpine Linux is gonna being installed.
apk add e2fsprogs mkfs.ext4 /dev/mmcblk0p2 mount /dev/mmcblk0p2 /mnt
Install the system files.
setup-disk -m sys /mnt
If you get
ext4 is not supported . Only supported are: vfat
error, run withFORCE_BOOTFS
set.FORCE_BOOTFS=1 setup-disk -m sys /mnt
Remount old partition in RW. An update in the first partition is required for the next reboot.
mount -o remount,rw /media/mmcblk0p1
Clean up the boot folder in the first partition to drop unused files.
rm -f /media/mmcblk0p1/boot/* cd /mnt rm boot/boot
Move the image and init ram for Alpine Linux into the right place.
mv boot/* /media/mmcblk0p1/boot rm -Rf boot mkdir media/mmcblk0p1 # It's the mount point for the first partition on the next reboot
Update /etc/fstab:
echo "/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0" >> etc/fstab sed -i '/cdrom/d' etc/fstab sed -i '/floppy/d' etc/fstab
Enable edge repository.
sed -i '/edge/s/^#//' /mnt/etc/apk/repositories
For the next boot, indicate that the root filesystem is on the second partition. If the cmdline.txt file contains a line that starts with /root, then use sed:
sed -i 's/$/ root=\/dev\/mmcblk0p2 /' /media/mmcblk0p1/cmdline.txt
Make sure that appropriate cgroups are enabled
sed -i "s/$/ cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1/" /media/mmcblk0p1/cmdline.txt
If using chrony, allow the system clock to be stepped in the first three updates if its offset is larget than 1 second.
echo "makestep 1.0 3" >> /etc/chrony/chrony.conf
Reboot
Continue read Part 2 (Install K3s on Alpine) at Raspberry Pi K3s Alpine Linux Part 2