Skip to content

Instantly share code, notes, and snippets.

@larsch
Last active March 11, 2024 13:55
Show Gist options
  • Save larsch/4ae5499023a3c5e22552 to your computer and use it in GitHub Desktop.
Save larsch/4ae5499023a3c5e22552 to your computer and use it in GitHub Desktop.
Shell script that creates a Arch Linux image for the Raspberry Pi 2. Downloads the latest distribution from archlinuxarm.org and creates the flash filesystems including boot partition. Partitions are aligned for typical SD cards and ext filesystem tuned accordingly.
#!/bin/sh -ex
losetup /dev/loop0 && exit 1 || true
image=arch-linux-$(date +%Y%m%d).img
wget -q -N http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
truncate -s 1G $image
losetup /dev/loop0 $image
parted -s /dev/loop0 mklabel msdos
parted -s /dev/loop0 unit s mkpart primary fat32 -- 1 65535
parted -s /dev/loop0 set 1 boot on
parted -s /dev/loop0 unit s mkpart primary ext2 -- 65536 -1
parted -s /dev/loop0 print
mkfs.vfat -I -n SYSTEM /dev/loop0p1
mkfs.ext4 -F -L root -b 4096 -E stride=4,stripe_width=1024 /dev/loop0p2
mkdir -p root
mount /dev/loop0p2 root
bsdtar xfz ArchLinuxARM-rpi-2-latest.tar.gz -C root
mv root/boot root/boot-temp
mkdir -p root/boot
mount /dev/loop0p1 root/boot
mv root/boot-temp/* root/boot/
rm -rf root/boot-temp
sed -i "s/ defaults / defaults,noatime /" root/etc/fstab
umount root/boot root
losetup -d /dev/loop0
#!/bin/sh -exu
dd if=arch-linux-*.img of=/dev/<blockdevice> status=progress
sync
@bcomnes
Copy link

bcomnes commented Jan 31, 2019

I turned this into a CI/CD workflow: https://github.com/bcomnes/archlinux-arm-img with images releasing to the releases page: https://github.com/bcomnes/archlinux-arm-img/releases

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