Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save arvati/06e6d2f1b51506b656dba8d60be557c3 to your computer and use it in GitHub Desktop.

Select an option

Save arvati/06e6d2f1b51506b656dba8d60be557c3 to your computer and use it in GitHub Desktop.
Install Alpine into Raspberry Pi 2 Model B Rev 1.1

Install Alpine into Raspberry Pi 2 Model B Rev 1.1.md

With cat /proc/cpuinfo find out your raspberry oi version, check table at: https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md

Create boot up disk: https://wiki.alpinelinux.org/wiki/Create_a_Bootable_USB#Format_USB_stick

fdisk /dev/mmcblk0 
* d - dele all partiotions
* n - create new partition
* p - primary partition
* 1 - Partition number 1
* Use defaults for first and size +128M
* t Change partition type
* c Partition type (Win95 FAT32/LBA)
* a Make the partition bootable (set boot flag)
* 1 Partition number 1
* n - create new partition
* p - primary partition
* 1 - Partition number 2
* Use defaults for first and last cylinder (just press [Enter] twice).
* w Write your changes to the device

sudo fdisk /dev/mmcblk0 -l
Disco /dev/mmcblk0: 1,9 GiB, 1990197248 bytes, 3887104 setores
Unidades: setor de 1 * 512 = 512 bytes
Tamanho de setor (lógico/físico): 512 bytes / 512 bytes
Tamanho E/S (mínimo/ótimo): 512 bytes / 512 bytes
Tipo de rótulo do disco: dos
Identificador do disco: 0x90a51a95

Dispositivo    Inicializar Início     Fim Setores Tamanho Id Tipo
/dev/mmcblk0p1 *             2048  264191  262144    128M  c FAT32 W95 (LBA)
/dev/mmcblk0p2             264192 3887103 3622912    1,7G 83 Linux
sudo mkfs.vfat /dev/mmcblk0p1
sudo mkdosfs -F 32 /dev/mmcblk0p1
sudo mkfs.f2fs -f /dev/mmcblk0p2
sudo mount -t vfat /dev/mmcblk0p1 /mnt/disk
mkdir -p ~/Documentos/raspberrypi/alpine
wget -O ~/Documentos/raspberrypi/alpine/alpine-rpi-3.12.0-armv7.tar.gz http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/armv7/alpine-rpi-3.12.0-armv7.tar.gz
sudo tar -C /mnt/disk --no-same-owner -zxvf ~/Documentos/raspberrypi/alpine/alpine-rpi-3.12.0-armv7.tar.gz
sudo rm /mnt/disk/*-{rpi-b*,rpi-cm*,rpi-zero*,rpi-3*,rpi-4-b,rpi-a*}.dtb
sudo rm /mnt/disk/fixup4.dat
sudo rm /mnt/disk/start4.elf
sudo rm /mnt/disk/boot/*4
su root
cat > /mnt/disk/usercfg.txt <<-EOF
disable_overscan=1
hdmi_drive=2
enable_uart=1
gpu_mem=32
dtparam=audio=on
dtparam=i2s=on
dtoverlay=lirc-rpi:gpio_in_pin=26
dtoverlay=hifiberry-digi
EOF
exit

Download the Alpine for Raspberry Pi tarball - link: http://alpinelinux.org/downloads/
The armv7 build is compatible with Raspberry Pi 2 Model B
Mount the partition /mnt/disk and extract the tarball contents unto it.

Follow instructions here: https://wiki.alpinelinux.org/wiki/Raspberry_Pi

Insert the SD card into the Raspberry Pi and turn it on

  1. Login into the Alpine system as root. Leave the password empty.
  2. Type setup-alpine
  3. Once the installation is complete, commit the changes by typing lbu commit -d

Optional add ssh server

nano /etc/ssh/sshd_config

Optional hack setup-disk (testing)

Change /sbin/setup-disk to allow f2fs

apk add nano
nano /sbin/setup-disk

Change the lines bellow related to f2fs and rpi

.....
supported_boot_fs() {
        local supported="ext2 ext3 ext4 btrfs xfs vfat"
	[ "$KERNEL_FLAVOR" = "rpi2" ] && supported="$supported f2fs"
        local fs=
        for fs in $supported; do
                [ "$fs" = "$1" ] && return 0
        done
        echo "$1 is not supported. Only supported are: $supported" >&2
        return 1
}

# setup RPI bootloader
setup_rpi() {
        local mnt="$1" root="$2" modules="$3" kernel_opts="$4" bootdev="$5"
        # need to improve this later
	local $bootmedia="/media/mmcblk0p1"
	mount -o remount,rw "$bootmedia"
	echo "root=$rootdev modules=$modules $kernel_opts" > "$bootmedia"/cmdline.txt
}
.....
install_mounted_root() {
.....
	local initfs_features="ata base ide scsi usb virtio"
	[ "$KERNEL_FLAVOR" = "rpi2" ] && local initfs_features="base squashfs mmc usb kms dhcp https"
	local pvs= dev= rootdev= bootdev= extlinux_raidopt= root= modules=
	local kernel_opts="quiet"
	[ "$KERNEL_FLAVOR" = "rpi2" ] && kernel_opts="$kernel_opts console=tty1"
.....
	modules="sd-mod,usb-storage,${root_fs}${raidmod}"
	[ "$KERNEL_FLAVOR" = "rpi2" ] && modules="loop,squashfs,$modules"
.....
        case "$BOOTLOADER" in
                grub) setup_grub "$mnt" "$root" "$modules" "$kernel_opts" "$bootdev" $disks ;;
                syslinux) setup_syslinux "$mnt" "$root" "$modules" "$kernel_opts" "$bootdev" ;;
                zipl) setup_zipl "$mnt" "$root" "$modules" "$kernel_opts" ;;
		rpi) setup_rpi "$mnt" "$root" "$modules" "$kernel_opts" "$bootdev" $disks ;;
                *) die "Bootloader \"$BOOTLOADER\" not supported!" ;;
        esac
	if [ "$KERNEL_FLAVOR" = "rpi2" ]; then
        	cat >>"$mnt"/etc/fstab <<-__EOF__
                /dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0
                /media/mmcblk0p1/boot /boot none defaults,bind 0 0
        __EOF__
	fi
.....
select_bootloader() {
        local bootloader=syslinux
        if [ "$ARCH" = "ppc64le" ]; then
                bootloader=grub-ieee1275
        elif [ "$ARCH" = "s390x" ]; then
                bootloader=s390-tools
        elif [ "$KERNEL_FLAVOR" = "rpi2" ]; then
                bootloader=rpi
        elif [ -n "$USE_EFI" ]; then
                bootloader=grub-efi
        elif [ "$BOOTLOADER" = "grub" ]; then
                bootloader=grub-bios
        fi
        echo "$bootloader"
}

# install needed programs
init_progs() {
        local raidpkg= lvmpkg= fs= fstools= grub=
        [ -n "$USE_RAID" ] && raidpkg="mdadm"
        [ -n "$USE_LVM" ] && lvmpkg="lvm2"
        for fs in $BOOTFS $ROOTFS $VARFS; do
                # we need load btrfs module early to avoid the error message:
                # 'failed to open /dev/btrfs-control'
                if ! grep -q -w "$fs" /proc/filesystems; then
                        modprobe $fs
                fi

                case $fs in
                xfs) fstools="$fstools xfsprogs";;
                ext*) fstools="$fstools e2fsprogs";;
                btrfs) fstools="$fstools btrfs-progs";;
                vfat) fstools="$fstools dosfstools";;
		f2fs) fstools="$fstools f2fs-tools";;
                esac
        done
        apk add --quiet sfdisk $lvmpkg $raidpkg $fstools $@
}
.....
if [ -d "$1" ]; then
	# install to given mounted root
	[ "$KERNEL_FLAVOR" = "rpi2" ] && BOOTLOADER=rpi
	[ "$BOOTLOADER" = "syslinux" ] && apk add --quiet syslinux
	install_mounted_root "${1%/}" \
		&& echo "You might need fix the MBR to be able to boot" >&2
	exit $?
fi

Install sys mode

apk add e2fsprogs f2fs-tools
#mkfs.ext4 /dev/mmcblk0p2
mkfs.f2fs /dev/mmcblk0p2
mkdir /stage
mount /dev/mmcblk0p2 /stage
setup-disk -v -o /media/mmcblk0p1/raspberrypi2.apkovl.tar.gz /stage
#echo "/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0" >>  /stage/etc/fstab
mount -o remount,rw /media/mmcblk0p1
#sed -i '$ s/$/ root=\/dev\/mmcblk0p2/' /media/mmcblk0p1/cmdline.txt
cp /stage/boot/*-rpi2 /media/mmcblk0p1/boot/
### need to improve and copy contents of '/stage/boot/dtbs-rpi2' into /media/mmcblk0p1
reboot
echo /media/mmcblk0p1/boot /boot none defaults,bind 0 0 >> /etc/fstab
apk add haveged
rc-update add haveged boot
mount -o remount,rw /media/mmcblk0p1
cat > /media/mmcblk0p1/usercfg.txt <<-EOF
disable_overscan=1
hdmi_drive=2
enable_uart=1
gpu_mem=32
dtparam=audio=on
dtparam=i2s=on
dtoverlay=lirc-rpi:gpio_in_pin=26
dtoverlay=hifiberry-digi
EOF
lbu commit -d

Install xfce (testing)

setup-xorg-base xfce4 xfce4-terminal lightdm-gtk-greeter xfce4-screensaver dbus-x11 sudo
apk add xf86-input-libinput xf86-video-fbdev
addgroup manager input
addgroup manager video
addgroup root input
addgroup root video
nano /etc/X11/xorg.conf
Section "Device"
        Identifier      "Default"
        Driver          "fbdev"
        Option          "fbdev" "/dev/fb0"
        Option          "SwapbuffersWait" "true"
EndSection

link: https://www.raspberrypi.org/forums/viewtopic.php?t=60569

--- /root/setup-disk
+++ /sbin/setup-disk
@@ -208,6 +208,7 @@
supported_boot_fs() {
local supported="ext2 ext3 ext4 btrfs xfs vfat"
+ [ "$KERNEL_FLAVOR" = "rpi2" ] && supported="$supported f2fs"
local fs=
for fs in $supported; do
[ "$fs" = "$1" ] && return 0
@@ -268,6 +269,14 @@
done
}
+# setup RPI bootloader
+setup_rpi() {
+ local mnt="$1" root="$2" modules="$3" kernel_opts="$4" bootdev="$5"
+ # need to improve this later
+ mount -o remount,rw /media/mmcblk0p1
+ echo "root=$rootdev modules=$modules $kernel_opts" > /media/mmcblk0p1/cmdline.txt
+}
+
# setup GRUB bootloader
setup_grub() {
local mnt="$1" root="$2" modules="$3" kernel_opts="$4" bootdev="$5"
@@ -344,8 +353,10 @@
shift 1
local disks="${@}" mnt_boot= boot_fs= root_fs=
local initfs_features="ata base ide scsi usb virtio"
+ [ "$KERNEL_FLAVOR" = "rpi2" ] && initfs_features="base squashfs mmc usb kms dhcp https"
local pvs= dev= rootdev= bootdev= extlinux_raidopt= root= modules=
local kernel_opts="quiet"
+ [ "$KERNEL_FLAVOR" = "rpi2" ] && kernel_opts="$kernel_opts console=tty1"
[ "$ARCH" = "s390x" ] && initfs_features="$initfs_features qeth dasd_mod"
rootdev=$(find_mount_dev "$mnt")
@@ -442,6 +453,7 @@
kernel_opts="nomodeset $kernel_opts"
fi
modules="sd-mod,usb-storage,${root_fs}${raidmod}"
+ [ "$KERNEL_FLAVOR" = "rpi2" ] && modules="loop,squashfs,$modules"
# generate the fstab
if [ -f "$mnt"/etc/fstab ]; then
@@ -466,14 +478,22 @@
grub) setup_grub "$mnt" "$root" "$modules" "$kernel_opts" "$bootdev" $disks ;;
syslinux) setup_syslinux "$mnt" "$root" "$modules" "$kernel_opts" "$bootdev" ;;
zipl) setup_zipl "$mnt" "$root" "$modules" "$kernel_opts" ;;
+ rpi) setup_rpi "$mnt" "$root" "$modules" "$kernel_opts" "$bootdev" $disks ;;
*) die "Bootloader \"$BOOTLOADER\" not supported!" ;;
esac
+ if [ "$KERNEL_FLAVOR" = "rpi2" ]; then
+ cat >>"$mnt"/etc/fstab <<-__EOF__
+ /dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0
+ /media/mmcblk0p1/boot /boot none defaults,bind 0 0
+ __EOF__
+ fi
+
# apk reads config from target root so we need to copy the config
mkdir -p "$mnt"/etc/apk/keys/
cp /etc/apk/keys/* "$mnt"/etc/apk/keys/
- local apkflags="--initdb --quiet --progress --update-cache --clean-protected"
+ local apkflags="--initdb --progress --update-cache --clean-protected"
local pkgs=$(grep -h -v -w sfdisk "$mnt"/etc/apk/world \
"$mnt"/var/lib/apk/world 2>/dev/null)
@@ -594,6 +614,8 @@
bootloader=grub-ieee1275
elif [ "$ARCH" = "s390x" ]; then
bootloader=s390-tools
+ elif [ "$KERNEL_FLAVOR" = "rpi2" ]; then
+ bootloader=rpi
elif [ -n "$USE_EFI" ]; then
bootloader=grub-efi
elif [ "$BOOTLOADER" = "grub" ]; then
@@ -619,6 +641,7 @@
ext*) fstools="$fstools e2fsprogs";;
btrfs) fstools="$fstools btrfs-progs";;
vfat) fstools="$fstools dosfstools";;
+ f2fs) fstools="$fstools f2fs-tools";;
esac
done
apk add --quiet sfdisk $lvmpkg $raidpkg $fstools $@
@@ -1212,6 +1235,7 @@
if [ -d "$1" ]; then
# install to given mounted root
+ [ "$KERNEL_FLAVOR" = "rpi2" ] && BOOTLOADER=rpi
[ "$BOOTLOADER" = "syslinux" ] && apk add --quiet syslinux
install_mounted_root "${1%/}" \
&& echo "You might need fix the MBR to be able to boot" >&2
@arvati
Copy link
Author

arvati commented Jul 30, 2020

@arvati
Copy link
Author

arvati commented Jul 30, 2020

@arvati
Copy link
Author

arvati commented Jul 30, 2020

initfs_features = base squashfs mmc usb kms dhcp https
kernel_cmdline="console=tty1"
modules=loop,squashfs,sd-mod,usb-storage quiet ${kernel_cmdline}

https://git.alpinelinux.org/aports/tree/scripts/mkimg.arm.sh

@arvati
Copy link
Author

arvati commented Aug 1, 2020

https://www.pair.com/support/kb/paircloud-diff-and-patch/
cp /sbin/setup-disk ~/
nano /sbin/setup-disk
diff -u ~/setup-disk /sbin/setup-disk > patchfile.patch
patch /sbin/setup-disk patchfile.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment