Skip to content

Instantly share code, notes, and snippets.

@alzeih
Created September 20, 2016 04:28
Show Gist options
  • Save alzeih/0062fbd57b41fb761bf07cbbe7b94419 to your computer and use it in GitHub Desktop.
Save alzeih/0062fbd57b41fb761bf07cbbe7b94419 to your computer and use it in GitHub Desktop.
A script to automatically create a sdcard with Arch Linux ARM for Raspberry Pi
#!/bin/bash
DEVICE=/dev/mmcblk0
MOUNTPOINT=/mnt
# Raspberry Pi 1
#IMAGE="ArchLinuxARM-rpi-latest.tar.gz"
# Raspberry Pi 2 & 3
IMAGE="ArchLinuxARM-rpi-2-latest.tar.gz"
URL="http://archlinuxarm.org/os/${IMAGE}"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
if [ ! -b "${DEVICE}" ]; then
echo "${DEVICE} is not a block device"
exit 1
fi;
if mountpoint -q "${MOUNTPOINT}"; then
echo "${MOUNTPOINT} contains a mounted filesystem. Refusing to continue"
exit 1
fi;
wipefs --all "${DEVICE}"
sfdisk "${DEVICE}" -X dos << EOF
,100MiB,c;
,,L
EOF
echo "Formatting filesystems"
mkfs.ext4 "${DEVICE}p2"
mount "${DEVICE}p2" "${MOUNTPOINT}"
mkdir "${MOUNTPOINT}/boot"
mkfs.vfat "${DEVICE}p1"
mount "${DEVICE}p1" "${MOUNTPOINT}/boot"
if [ ! -f "${IMAGE}" ]; then
echo "Downloading image"
curl -O -L "${URL}"
fi
echo "Extracting filesystem"
bsdtar -xpvf "${IMAGE}" -C "${MOUNTPOINT}"
echo "Sync (this may take a long time)"
sync
echo "Unmounting filesystem"
umount -R "${MOUNTPOINT}"
echo "Done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment