Classic install or sys mode on Raspberry Pi

This page documents the traditional or sys mode installation of Alpine Linux on a Raspberry Pi. 
== Recommended installation method ==
Refer Raspberry Pi page to create SD card based install media. To complete the sys mode install of Alpine Linux on the sd card based Install media, proceed further. 
# Follow the Installation guide to complete until step 11(i.e SSH) of the base configuration. A working Internet access is mandatory to complete this installation.
# For the option, No disks available. Try boot media /media/mmcblk0? (y/n) [n] change the default option and type y.
# For the option, Which disk(s) would you like to use? (or '?' for help or 'none') [none], change the default option and type device name mmcblk0 based on displayed information.
# For the question How would you like to use it? ('sys', 'data', 'crypt', 'lvm' or '?' for help) [?], type sys.
# Verify the disk(s) name and if you are sure, then accept the WARNING: Erase the above disk(s) and continue? (y/n) [n] by changing the default option to y to proceed with the installation.
# At the end of Installation, you can reboot to boot into the newly installed Alpine Linux and configure further.
The above steps are shown below for reference. Depending on the size of your install media and pi model, the information may vary.
 Disk & Install
----------------
No disks available. Try boot media /media/mmcblk0? (y/n) [n] y
 * WARNING: you are stopping a sysinit service
 * Caching service dependencies ... [ ok ]
 * Unmounting /.modloop ... [ ok ]
Available disks are:
 mmcblk0	(64.1 GB )
Which disk(s) would you like to use? (or '?' for help or 'none') [none] mmcblk0
The following disk is selected:
 mmcblk0	(64.1 GB )
How would you like to use it? ('sys', 'data', 'crypt', 'lvm' or '?' for help) [?] sys
100% ████████████████████████████████████████████████████████████████████████████████████████████████████████████
/usr/sbin/update-raspberrypi-bootloader: WARNING: no kernel found
WARNING: The following disk(s) will be erased:
 mmcblk0	(64.1 GB )
WARNING: Erase the above disk(s) and continue? (y/n) [n] y
Partition #2 contains a ext4 signature.
Creating file systems...
mkfs.fat 4.2 (2021-01-31)
Installing system on /dev/mmcblk0p2:
100% ████████████████████████████████████████████████████████████████████████████████████████████████████████████
==> initramfs: creating /boot/initramfs-rpi for 6.12.8-0-rpi
/usr/sbin/update-raspberrypi-bootloader: INFO: replaced config.txt and saved config.txt.old
Configured kernel vmlinuz-rpi / initramfs-rpi
Installation is complete. Please reboot.
== Manual installation ==
The following steps were used in the past. They are not needed since Alpine Linux v3.21.
Create an MBR partition table with two partitions on an 8 GB (or larger) class 10 sd-card:
* First one, a fat32 type, of 256MB. You may have to set boot and lba flags
* The second one, an ext4 type, occupying the remaining space on the media
* Eject and re-insert your SD card to ensure recognition of all the partitions. 
* Go into the first partition (fat32). Untar the archive with :
Eject the SD card properly. Insert it into the Raspberry Pi. Plug in a usb keyboard as well as the HDMI and network cables. Power on. When the command prompt displays, log in as root. (no password)
=== Update boot partition (keep alpine-rpi* image layout) ===
From here we can either update boot partition to keep the alpine-rpi* image layout
or to keep the system partition/setup-alpine's layout (see next section).
We only need one of the two. Not both.
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 symbolic link
Move the image and initramfs 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 when you execute the following:
 ln -s media/mmcblk0p1/boot boot
=== Update boot partition (keep system partition/setup-alpine layout) ===
It turns out that the system partition created by setup-alpine has a working boot layout. To keep this, perform the following steps instead of the steps in the previous chapter.
Clean up the boot / first partition to drop unused files:
 rm -Rf /media/mmcblk0p1/*
 cd /mnt # We are in the second partition 
 rm boot/boot # Drop the unused symbolink link
Move the boot folder created by setup-alpine into the right place:
 cd /media/mmcblk0p1
 mkdir boot
 cd /mnt
 mv boot/* /media/mmcblk0p1/ 
 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 when you execute the following:
 ln -s media/mmcblk0p1 boot
=== End of update boot partition - continue here in both cases ===
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 activate the 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 
 reboot
That works on Raspberry Pi 3B and 1B, but if you have the 1B version, you'll need to 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.
== Convert diskless to sys mode ==
Split your SD card into two partitions: the FAT32 boot partition described above (in this example it'll be mmcblk0p1) , and a second partition to hold the root filesystem (here it'll be mmcblk0p2). Boot and configure your diskless system as above, then create a root filesystem:
Now do a disk install via a mountpoint. The setup-disk script will give some errors about syslinux/extlinux, but you can ignore them.
The Raspberry Pi doesn't need them to boot.
Add a line to /stage/etc/fstab to mount the Pi's boot partition again:
Now add a root=/dev/mmcblk0p2 parameter to the Pi's boot command line, either cmdline-rpi2.txt or cmdline-rpi.txt depending on model:
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 at shutdown.
N.B. 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. To update the kernel, initfs or modules, you will need to manually (generate and) copy these to the boot partition or you could use bind mount, in which case,
copying the files to boot partition manually, is not needed.
Execute the following commands. Make sure there is an internet connection available otherwise setting up the apk mirrors will fail.
 setup-alpine 
Set the keyboard map, 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 # 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 hardware clock, so synchronize with an ntp server:
 apk add 
 service chronyd restart
 mount /dev/mmcblk0p2 /mnt # The second partition, in ext4 format, where Alpine Linux is installing in sys mode
 export FORCE_BOOTFS=1 # work around for issue 12353
 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.
== See also ==
* Raspberry Pi
Category:Installation
category: Raspberry