Skip to content

Instantly share code, notes, and snippets.

@larsch
Last active March 11, 2024 13:55
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • 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 28, 2019

Great script! I'm trying to get this to run in travis.ci and running into issues on the bsdtar step. It seems the mounted loop0p2 at root isn't writable for some reason. Any ideas

EDIT: image was too small! I just had to increase the size of the image and it works great.

@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