Last active
August 1, 2023 09:05
-
-
Save nablaa/98df2ad96cd63f1b2d76 to your computer and use it in GitHub Desktop.
Arch Linux ARM installation script for Raspberry Pi
This file contains hidden or 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/bash | |
set -e | |
set -u | |
usage() { | |
echo "Usage: $0 DEVICE HOSTNAME" | |
echo "Example: $0 /dev/sdX mypi" | |
exit 1 | |
} | |
[ $# -ne 2 ] && { usage; } | |
DEVICE="$1" | |
HOSTNAME="$2" | |
if [ ! -e "$DEVICE" ]; then | |
echo "Device $DEVICE not found!" | |
echo "Give a valid device (e.g. /dev/sdX)" | |
exit 2 | |
fi | |
echo "Flashing device $DEVICE and setting hostname to $HOSTNAME" | |
TMP_DIR=$(mktemp -d) | |
echo "Temp directory: $TMP_DIR" | |
cd "$TMP_DIR" | |
cleanup() { | |
echo "Cleaning up $TMP_DIR" | |
rm -rf "$TMP_DIR" | |
} | |
trap cleanup 0 | |
echo "Creating partitions" | |
echo "o | |
p | |
n | |
p | |
1 | |
+100M | |
p | |
t | |
c | |
n | |
p | |
2 | |
p | |
w | |
w | |
" | fdisk "$DEVICE" | |
echo "Creating boot filesystem" | |
mkfs.vfat "$DEVICE"1 | |
mkdir boot | |
mount "$DEVICE"1 boot | |
echo "Creating root filesystem" | |
mkfs.ext4 "$DEVICE"2 | |
mkdir root | |
mount "$DEVICE"2 root | |
echo "Copying base image" | |
wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz | |
tar -xf ArchLinuxARM-rpi-latest.tar.gz -C root | |
sync | |
echo "Copying boot files to boot partition" | |
mv root/boot/* boot | |
echo "Setting hostname to $HOSTNAME" | |
echo "$HOSTNAME" > root/etc/hostname | |
echo "Unmounting partitions" | |
sync | |
umount boot root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment