Install Alpine Linux Raspberry PI 1 Model B (256MB RAM)

Alpine Linux is a great Linux distro. It is very lightweight (for example, a clean installation runs in 20MB of RAM) and APK package manager is one of the most fastest packager managers.

Alpine is widely used in Docker containers, but it can be used as host operating system. Because it is so lightweight and fast, it is one of the best options for a limited resources computer like Raspberry PI is, much better than Raspbian. The downside is the small community. You can follow the reasons why Alpine is great for Raspberry PI in a post in Raspberry PI forum.

Alpine Linux supports all versions of Raspberry PI but, for some reason, it does not work on older models of Raspberry PI. The model used was Raspberry PI 1 Model B with 256MB of RAM. It was one of the first Raspberry PIs to be released (Raspberry P1 2011.12 with SAMSUMG memory).

It seems that it cannot boot if the kernel is inside a folder. You find questions about this issue in Raspberry PI Forum and in Alpine Forum.

Next, you will find a guide to install Alpine on the Raspberry PI that tries to solve this problem by working around. If you cannot boot Alpine in Raspberry PI, this guide is for you!

Installation

  1. Download the latest version of Alpine for Raspberry PI (current v3.6.2)

    Alternatively, you can download a prepared version of the Alpine installer (v3.6.2). If you use this tarball, you can skip the steps 4. and 5.

  2. Partition the SD Card with 2 partitions, in MS-DOS partition table format (or other layout you want). You can follow the instructions in Alpine Wiki:

    • First partition should have around 150MB and formatted in FAT32 (W95 FAT32 (LBA), partition ID is 0xC). It will contain the Alpine Installer and the Linux Kernel.

    • Second partition should fill the remaining space of the card and be formatted in ext4. It will contain the root filesystem and all personal files. You can split this partition into more advanced layouts.

  3. Extract the tarball contents to your FAT32 partition

    If you are using the official image and you try to boot now, you should only get the LED ACT blinking 7 times. This means U-Boot cannot find the kernel to boot. If your Raspberry PI boots, you do not need to follow this tutorial.

  4. Move the files inside the boot folder to the partition’s root. You can delete the files *-rpi2 because they are not necessary. Run the following commands inside the FAT32 partition:

    rm boot/*-rpi2
    mv boot/* .
    
  5. Update and cleanup the file config.txt accordingly with the new changes. The file should look like this:

    disable_splash=0
    boot_delay=0
    gpu_mem=256
    gpu_mem_256=32
    kernel=vmlinuz-rpi
    initramfs initramfs-rpi
    

    The minimum amount of GPU memory is 32MB, otherwise it will not boot.

  6. Boot and install Alpine normally, as described in Alpine Wiki:

    • Insert the SD Card into the Raspberry Pi and turn it on
    • Login into the Alpine system as root. Leave the password empty.
    • Type setup-alpine. Select none when asked where to install Alpine in setup-disk.
    • Once the installation is complete, commit the changes by typing lbu commit -d

    Type reboot to verify that the installation was indeed successful.

    At this point, we are only working with the FAT32 partition. Following we will perform
    Traditional disk-based (sys) installation
    because this frees all the memory otherwise needed for the root filesystem.

  7. Create the filesystem in /dev/mmcblk0p2 if you have not already created it:

    apk add e2fsprogs
    mkfs.ext4 /dev/mmcblk0p2
    
  8. Now do a disk install via a mountpoint. The setup-disk script will give some errors about syslinux/extlinux, but you can ignore these: the Raspberry Pi doesn’t need this to boot anyway.

    mkdir /stage
    mount /dev/mmcblk0p2 /stage
    setup-disk -o /media/mmcblk0p1/MYHOSTNAME.apkovl.tar.gz /stage
    # (ignore errors about syslinux/extlinux)
    
  9. Add a line to /stage/etc/fstab to mount the Pi’s boot partition again:

    /dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0
    
  10. Now add a root=/dev/mmcblk0p2 parameter to the Pi’s boot command line cmdline.txt:

    mount -o remount,rw /media/mmcblk0p1
    sed -i '$ s/^/root=\/dev\/mmcblk0p2 /' /media/mmcblk0p1/cmdline.txt
    

    You might also consider overlaytmpfs=yes here, which will cause the underlying SD card root filesystem to be mounted read-only, with an overlayed tmpfs for modifications which will be discarded on shutdown.

    If reboot now, guess what happens: the kernel is loaded (you can see ACT led activity), but no image! This is because the init script is expecting the installer and the ROOT device (/dev/mmcblk0p2) don’t have them.

  11. Copy the kernel et al files from boot folder to the FAT32 partition. You might want to backup the previous files:

    cd /media/mmcblk0p1
    mkdir kernel-installer
    mv System.map-rpi config-rpi initramfs-rpi vmlinuz-rpi kernel-installer
    cp -v /stage/boot/* .
    
  12. You can reboot into you Alpine Linux!!

Post Installation

For more details, you can follow the instructions in Alpine Wiki.

Kernel update

Beware, though, that the contents of /boot will be ignored when the Pi boots: it will use the kernel, initramfs, and modloop images from the FAT32 boot partition. You can fix this manually or automatically:

  • To update the kernel, initfs or modules, you will need to manually (generate and) copy these to the boot partition. You might want to backup the current kernel:

    cd /media/mmcblk0p1
    mkdir kernel-<version>
    mv System.map-rpi config-rpi initramfs-rpi vmlinuz-rpi kernel-<version>
    cp -v /boot/* .
    

    You might want update manually because, if the update break the boot, you can easily restore the kernel.

  • Or you could use bind mount to install the files automatically when the kernel is updated. Edit the file /etc/fstab and add the following line:

    /media/mmcblk0p1/boot /boot none defaults,bind 0 0
    

Swap

Swap is not necessary but recommended, especially if you are running low on RAM. You can use it from a partition or from a file:

  • If you have a partition for swap, add an entry in /etc/fstab:

    /media/mmcblk0p3 swap swap defaults 0 0
    
  • You can also have swap in a file stored in the filesystem.

    Create a file for swap:

    dd if=/dev/zero of=/swapfile bs=1M count=<size in MB>
    

    Add an entry in /etc/fstab:

    /swapfile none swap defaults 0 0
    

    And activate the swap service:

    rc-update add swap boot
    

LVM and RAID

If you want to mount LVM and RAID partitions during boot, you need to configure /etc/fstab and activate the corresponding service:

 rc-update add lvm boot
 rc-update add mdadm-raid boot