Skip to content

Instantly share code, notes, and snippets.

Last active February 3, 2023 01:58
Show Gist options
  • Save pklaus/0e90aaa2d91064edd731fa30f44fce3f to your computer and use it in GitHub Desktop.
Save pklaus/0e90aaa2d91064edd731fa30f44fce3f to your computer and use it in GitHub Desktop.
Raspberry Pi 3: Arch Linux ARM 64bit to SDcard Script. This is for the Rapsberry Pi 3. For the RPi 2 (or the 3 32bit), see . For the RPi 1, see .
# <>
echo -e "\n\nArch Linux ARM to SD Card"
echo -e "For the Raspberry Pi 3, if you want to use the unofficial arm64 variant."
echo -e "(Otherwise use the Raspberry Pi 2 version of this script!)\n\n"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
echo -e "\nAll drives on this computer:\n"
ls -1 /dev/sd?
echo -e "\nLast messages in syslog:\n"
dmesg | tail
echo -e "\nChoose sd card (like /dev/sdX):\n"
echo -e "\n\nCurrent partitioning of $SDCARD:\n"
parted $SDCARD print
echo -e "\n\nYou chose $SDCARD\nAre you sure to continue? Press Ctrl-C to abort!"
cd /tmp
echo -e "\nDownloading the Arch Linux ARM root filesystem (if needed):\n"
# Sometimes the download server is slow. In that case, try a different one instead:
FNAME=$(basename "$URL")
FSIZE=$(curl --head --location --silent "$URL" --write-out '%{http_code} %{size_download} \n' | tac | grep -m1 Content-Length | cut -f 2 -d' ' | tr -d '\r')
if [ -n "$FNAME" ]
CURSIZE=$(wc -c <"$FNAME")
if [ $CURSIZE -ne $FSIZE ]; then
rm "$FNAME"
echo "Removing any downloaded and leftover Arch Linux ARM image"
curl --location --remote-name --time-cond "$FNAME" "$URL"
if [ $? -ne 0 ]; then
echo "Could not download the image file, please check the mirror"
exit 1
echo -e "\nUnmounting partitions found on ${SDCARD}\n"
for MOUNT in ${SDCARD}?
echo $MOUNT
umount $MOUNT
parted -s $SDCARD unit s print
parted -s $SDCARD mktable msdos
parted -s $SDCARD mkpart primary fat32 8192s 128MiB
parted -s $SDCARD mkpart primary 128MiB 100%
parted -s $SDCARD unit s print
mkfs.vfat ${SDCARD}1
mkfs.ext4 ${SDCARD}2
rm -rf boot
rm -rf root
mkdir boot
mkdir root
mount ${SDCARD}1 boot
mount ${SDCARD}2 root
echo -e "\nExtracting the root filesystem\n"
bsdtar -xpf ArchLinuxARM-rpi-3-latest.tar.gz -C root
echo -e "\nMoving boot files to the first partition\n"
mv root/boot/* boot
echo -e "\nUnmounting the two partitions\n"
umount boot root
rmdir boot root
echo "Insert the SD card into the Raspberry Pi 2, connect ethernet, and apply 5V power."
echo "Use the serial console or SSH to the IP address given to the board by your router. The username/password combination is alarm/alarm. The default root password is 'root'."
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment