Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pdrok/b0b0eec7f75b5da40ae0f84a00367536 to your computer and use it in GitHub Desktop.
Save pdrok/b0b0eec7f75b5da40ae0f84a00367536 to your computer and use it in GitHub Desktop.

Install Alpine linux on a Raspeberry Pi 4 headless

Follow these tutorial:

https://tomcore.io/docs/howto/raspberrypi/install-alpine-linux-on-raspberrypi/

https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main

https://wiki.alpinelinux.org/wiki/Setting_up_a_SSH_server?ref=angelsanchez.me

Microsoft DiskPart version 10.0.19041.964

Copyright (C) Microsoft Corporation.
On computer: WORKHAUS

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          931 GB  1024 KB        *
  Disk 1    Online           14 GB      0 B        *

If your disk has GPT partion

Change to MBR instead of GPT because the pamarams id= later won't work

DISKPART> list disk

DISKPART> select disk 1

DISKPART> clean

DISKPART> convert mbr

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          931 GB  1024 KB        *
  Disk 1    Online           14 GB      0 B
DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> list partition

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary              9 GB  1024 KB
  Partition 2    Primary           5192 MB     9 GB


DISKPART> clean

DiskPart succeeded in cleaning the disk.

DISKPART> list partition

There are no partitions on this disk to show.

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> list partition

There are no partitions on this disk to show.

DISKPART> create partition primary size=256 id=0c

DiskPart succeeded in creating the specified partition.

DISKPART> create partition primary size=10240 id=83

DiskPart succeeded in creating the specified partition.

DISKPART> create partition primary id=82

DiskPart succeeded in creating the specified partition.

DISKPART> select partition 1

Partition 1 is now the selected partition.

DISKPART> list partition

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
* Partition 1    Primary            256 MB  1024 KB
  Partition 2    Primary             10 GB   257 MB
  Partition 3    Primary           4696 MB    10 GB

DISKPART> format fs=FAT32 LABEL="bootpart" QUICK

100 percent completed

DiskPart successfully formatted the volume.

DISKPART> exit

Download and unpack Alpine Linux

Download the latest Raspberry PI aarch64 Alpine version from the Alpine website. Next, unpack the gzip archive you have downloaded on your SD Card

Also copy these file from alpine-linux-headless-bootstrap repository on /boot folder of your SD Card:

headless.apkovl.tar.gz
wpa_supplicant.conf
authorized_keys

Change the value of wpa_supplicant.conf for the SSID and Password for your WIFI connections

The authorized_keys file should has your id_rsa.pub if you want to access by ssh without password

Create an emtpy file called ssh on the /boot folder of your SD Card to enable ssh server

log on you RPI by the IP it get by dhcp

ssh root@192.168.x.x

Setup network interfaces

Setup the Ethernet and/or the Wi-Fi interface by executing setup-interfaces:

~ # setup-interfaces
Available interfaces are: eth0 wlan0.
Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done') [eth0]

Also enable the wlan0 with dhcp

Setup timezone and ntp client

Run setup-timezone and setup-ntp to set up your time zone and start an ntp client (chronyd does the job)

set your timezone

~ # setup-timezone

setup and start ntp daemon chrony

~ # setup-ntp

check date / time and have been updated successfully

~ # date

Setup APK Repository

~ # setup-apkrepos

The script will ask you to choose your preferred mirror of the Alpine repository. If you are unsure choose the option “Detect and add fastest mirror from above list `

Install Alpine

Format system partition

Install file system tools (mkfs.ext4)

~ # apk add e2fsprogs

Format 2nd partition with ext4

~ # mkfs.ext4 /dev/mmcblk0p2

Mount 2nd partition under /mnt

~ # mount /dev/mmcblk0p2 /mnt

Optional: Format and enable swap partition

Format 3rd partition as swap space

~ # mkswap /dev/mmcblk0p3

Enable swap space

~ # swapon /dev/mmcblk0p3

Enable swap space upon booting

~ # rc-update add swap boot

Enable network upon booting

~ # rc-update add network boot

Enable network upon booting

~ # apk add openssh
~ # rc-update add sshd boot
~ # mkdir -p /mnt/root/.ssh
~ # cp /dev/mmcblk0p1/authorized_keys  /mnt/root/.ssh
~ # chmod 600 /mnt/root/.ssh
~ # chmod 400 /mnt/root/.ssh/authorized_keys

Run setup

Force the installation script to accept non FAT filesystems on the PI

~ # export FORCE_BOOTFS=1

Optional: Declare the swap partition

~ # export SWAP_DEVICES=/dev/mmcblk0p3

Run installation script

~ # setup-disk /mnt

Remount boot partition as read-write partition

~ # mount -o remount,rw /dev/mmcblk0p1

Remove all files

~ # rm /media/mmcblk0p1/\* -r

Copy all files required for booting from the new installation to the boot partition

~ # cp -r /mnt/boot/\* /media/mmcblk0p1/

Boot the new Alpine installation

~ # reboot

Now you can enable the community repository

https://wiki.alpinelinux.org/wiki/Repositories

neofetch
       .hddddddddddddddddddddddh.          root@alpi
      :dddddddddddddddddddddddddd:         ---------
     /dddddddddddddddddddddddddddd/        OS: Alpine Linux v3.19 aarch64
    +dddddddddddddddddddddddddddddd+       Host: Raspberry Pi 4 Model B Rev 1.4
  `sdddddddddddddddddddddddddddddddds`     Kernel: 6.6.14-0-rpi
 `ydddddddddddd++hdddddddddddddddddddy`    Uptime: 2 hours, 58 mins
.hddddddddddd+`  `+ddddh:-sdddddddddddh.   Packages: 105 (apk)
hdddddddddd+`      `+y:    .sddddddddddh   Shell: zsh 5.9
ddddddddh+`   `//`   `.`     -sddddddddd   Terminal: /dev/pts/1
ddddddh+`   `/hddh/`   `:s-    -sddddddd   CPU: (4) @ 1.500GHz
ddddh+`   `/+/dddddh/`   `+s-    -sddddd   Memory: 63MiB / 7810MiB
ddd+`   `/o` :dddddddh/`   `oy-    .yddd
hdddyo+ohddyosdddddddddho+oydddy++ohdddh
.hddddddddddddddddddddddddddddddddddddh.
 `yddddddddddddddddddddddddddddddddddy`
  `sdddddddddddddddddddddddddddddddds`
    +dddddddddddddddddddddddddddddd+
     /dddddddddddddddddddddddddddd/
      :dddddddddddddddddddddddddd:
       .hddddddddddddddddddddddh.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment