Classic install or sys mode on Raspberry Pi

From Alpine Linux
Revision as of 16:16, 1 December 2020 by Yeswearecoding (talk | contribs) (it is an error in the sed command. The 'root=..' need to be at the end of line (so with the '$') and not at the begin (with the '^'))
Jump to: navigation, search

A howto for classic installation, or "sys mode".

This method works with a desktop PC under Ubuntu and other Linuxes.


Download the archive from the Rasperry Pi armhf link here. Sha256 and GPG links appear next to the link to check the download.

On a class 10 sd-card with a size of 8Go or more, create two partitions:-

  • First in fat16 with size of 256Mo. You may have to check boot and lba flags
  • Second in ext4 with the remaining place

Eject and insert your SD card in order to recognize all the partitions.

Now go into the first partition (fat16).

Untar the archive with tar:

tar zxvf ~/Download/alpine-rpi-*-armhf.tar.gz

Due to a bug, it is recommended to add a file named usercfg.txt into the partition. The file should contain the following single line:


You could also add for headless use to maximize memory (32 megs is required for the rpi bootloader):


And to enable audio support:


Eject the SD card properly, insert it into the Raspberry Pi, plug a usb keyboard in plus the HDMI and network cables, and power on.

When a prompt displays, connect as root without a password.

OSX Preparation: creating a FAT16 partition on microSD

To create a FAT16 partition with OSX, use the diskutil program and a USB microSD card reader (I used an older version of this:

Put the microSD card in reader, the reader in a USB port, and type ls -1 /Volumes in a terminal. Note the name of the microSD volume; for example, VOL1 in the output below:

 $ ls -1 /Volumes
 Macintosh HD

Unmount the reader, unplug it and re-run ls -1 /Volumes. Verify the microSD volume name is no longer listed and then re-insert the USB reader.

Find the mount point of your microSD volume; for example, disk3 in the output below:

 $ diskutil list VOL1
 /dev/disk3 (external, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:     FDisk_partition_scheme                        *31.4 GB    disk3
    1:                 DOS_FAT_16 VOL1                    256.0 MB   disk3s1
    2:                      Linux                         30.0 GB    disk3s2
    3:                 Linux_Swap                         1.2 GB     disk3s3

(For help on diskutil command, type diskutil to list all command verbs. For help on a specific verb, add the verb; for example, diskutil partitionDisk)

Destroy all the existing partitions on the microSD card and create two new ones:

  1. a 256MB, FAT16, DOS-compatible partition and
  2. a free space gap for the rest of the card
 $ diskutil partitionDisk disk3 MBR   "MS-DOS FAT16" VOL1 256MB    "Free Space" VOL2 R
 Started partitioning on disk3
 Unmounting disk
 Creating the partition map
 Waiting for partitions to activate
 Formatting disk3s1 as MS-DOS (FAT16) with name VOL1
 512 bytes per physical sector
 /dev/rdisk3s1: 499472 sectors in 62434 FAT16 clusters (4096 bytes/cluster)
 bps=512 spc=8 res=1 nft=2 rde=512 mid=0xf8 spf=244 spt=32 hds=32 hid=2 drv=0x80 bsec=500000
 Mounting disk
 Finished partitioning on disk3
 /dev/disk3 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *31.4 GB    disk3
    1:                 DOS_FAT_16 VOL1                    256.0 MB   disk3s1

Change your current working directory to the new FAT16 partition and then pickup with the untar instruction in the parent prep section.

 $ cd /Volumes/VOL1/


Execute the following commands. Make sure there is an internet connection available otherwise setting up the apk mirrors will fail.


Set the mapping keyboard, the timezone, how to connect to the network (dhcp is the best method), say none at save config and save cache.

apk update

If the extra space in the sd card was left empty, a partition must be created now:

apk add cfdisk      # or the tool of your choice
cfdisk /dev/mmcblk0 # create the new partition with the free space
mkfs.ext4 /dev/mmcblk0p2  # create the ext4 filesystem in the new partition

Raspberry Pi has no battery for his hardware clock, so synchronize with an ntp server:

apk add chrony   
service chronyd restart
apk add e2fsprogs
mount /dev/mmcblk0p2 /mnt  # The second partition, in ext4 format, where Alpine Linux is installing in sys mode
setup-disk -m sys /mnt
mount -o remount,rw /media/mmcblk0p1  # An update in the first partition is required for the next reboot.

You may get some warning about syslinux when you run setup-disk. You can safely ignore this.

Clean up the boot folder in the first partition to drop unused files:

rm -f /media/mmcblk0p1/boot/*  
cd /mnt       # We are in the second partition 
rm boot/boot  # Drop the unused symbolink link

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

Don't worry about the error with the following:

ln -s media/mmcblk0p1/boot boot

Update /etc/fstab:

echo "/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0" >> etc/fstab
sed -i '/cdrom/d' etc/fstab   # Of course, you don't have any cdrom or floppy on the Raspberry Pi
sed -i '/floppy/d' etc/fstab
cd /media/mmcblk0p1

If you want to active edge repository

sed -i '/edge/s/^#//' etc/apk/repositories   # But enable the repository for community if you want vim, mc, php, apache, nginx, etc.

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  

That works on Raspberry Pi 3B and 1B, but if you have the 1B version, let's be very, very patient (several tens of minutes).

If a hard disk is connected via usb, you can replace the /dev/mmcblk0p2 above with /dev/sda1, for example.

If you don't like the sed above and its expressions, you can use a nano editor instead after executing the following command:

apk add nano


The Raspberry Pi (RPI) has no battery to keep the time updated. Therefore, we need to enable the right service to synchronize with an ntp server:

rc-update del hwclock boot
rc-update add swclock boot
service hwclock stop
service swclock start

Update and upgrade the system:

apk update
apk upgrade

If you want a cool editor (vim), a file manager (mc), and to determine which tasks are running and which services are starting on boot (htop), add the right packages:

apk add vim mc htop

The RPI 3B has wifi on board for networking, so start the service for the encrypted key on wpa2 protocol:

apk add wpa_supplicant
rc-update add wpa_supplicant boot
service wpa_supplicant start

Replace the IP address by dhcp for all the interfaces if necessary; select the SSID network for wifi; and add password.

ip addr    # to know the IP address for all interfaces

If you want to connect on your remote RPI via ssh, an additional user (foo) and the sudo package are required because it's forbidden to connect as root:

apk add sudo
adduser foo
adduser foo wheel

Uncomment line #82 with wheel ALL=(ALL) ALL. If vim is installed, save the changes by typing Esc :x


Following the prepare instructions for setting up the boot partition as outlined, using the armv7 image (3.10.3), my rpi2 would not even boot, and I was trapped in the dreaded rainbow screen, with the green led blinking a few times in a row, repeatedly.

The rpi2 I had appears to require fat32 for the boot partition, NOT fat16 as suggested in prepare. Use linux fdisk to set the boot partition type as "c" (for fat32/lba) amd set the lba and boot flags for the partition as suggested. Created the boot partition filesystem as fat32 with:

mkdosfs -F 32 /dev/sdX1 

Mount and unpacked the tarball to that, and everything should then work as documented after prepare.

After booting you may also find less system memory available than you expect. Currently the Pi requires a minimum of 32 megs gpu to boot, unless you have the cutdown boot loader installed, in which case you can use 16. However, you may find more gpu memory is still being used, even if you configure for less, if you enable audio or camera support. To find out how your system is actually split, you can do:

apk add raspberrypi
/opt/vc/bin/vcgencmd get_mem gpu
/opt/vc/bin/vcgencmd get_mem arm

See also