Last active
March 11, 2024 13:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -exu | |
dd if=arch-linux-*.img of=/dev/<blockdevice> status=progress | |
sync |
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
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
atroot
isn't writable for some reason. Any ideasEDIT: image was too small! I just had to increase the size of the image and it works great.