Skip to content

Instantly share code, notes, and snippets.

@crowz-fx
Last active April 13, 2020 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowz-fx/9b4e8c2c4d8dee004f0371e562502370 to your computer and use it in GitHub Desktop.
Save crowz-fx/9b4e8c2c4d8dee004f0371e562502370 to your computer and use it in GitHub Desktop.
a shell script to be run on a linux box that burns a raspberry Pi flavour Arch Linux install to an SD card (or other media)
#!/bin/sh
###################
# Author: Lui Crowie (crowz-fx // crowzfx.co.uk)
#
# Requirements;
# 1. sudo apt-get install bsdtar // tar should work fine, just modify line 98
# 2. You know how to use lsblk to get your device identifier i.e. /dev/sdb
# #################
###################
# Pre-reqs and checks
###################
printUsage() {
echo "Usage: burn_arch.sh {drive identifier i.e. b} {raspberry pi version i.e. 4}"
echo ""
echo "Example:"
echo " burn_arch.sh b 3"
echo ""
}
if [ -z "$1" ]; then
printUsage
exit 1
fi
if [ -z "$2" ]; then
printUsage
exit 1
fi
echo "PRE-REQ; Ignore if the following two lines fails..."
sudo umount /dev/sd${1}1
sudo umount /dev/sd${1}2
echo "PRE-REQ; Wiping disk..."
sudo sfdisk --delete /dev/sd${1}
partprobe
sleep 3
partprobe
sync
echo "PRE-REQ; Disk passed in has been erased!"
# setup folders
folder_to_use="/tmp/arch_install"
sudo rm -rf ${folder_to_use}
mkdir -p ${folder_to_use}
cd ${folder_to_use}
echo "PRE-REQ; In folder --> ${folder_to_use}"
echo "### Pre-reqs done!"
###################
# Information print out of system and script
###################
echo ""
echo " Date Executed: ["$(date)"]"
echo ""
echo ""
echo " Burning Arch Linux to SD CARD: [/dev/sd${1}]..."
echo ""
echo " PI board architecture version: [${2}]..."
echo ""
echo ""
###################
# Burn partions to the device
###################
echo "start= 2048, size= 204800, type=c" | sudo sfdisk /dev/sd${1}
partprobe
sleep 3
partprobe
sync
# no size denoted here as want to use the maximum the disk allows
# also -a is to append and not wipe out the above partion we just created
echo "start= 206848, type=83" | sudo sfdisk -a /dev/sd${1}
partprobe
sleep 3
partprobe
sync
echo "### Created partions!"
###################
# Mount volumes and explode tar into it
###################
sudo mkfs.vfat /dev/sd${1}1
mkdir boot
sudo mount /dev/sd${1}1 boot
echo "### boot volume mounted!"
yes | sudo mkfs.ext4 /dev/sd${1}2
mkdir root
sudo mount /dev/sd${1}2 root
echo "### root volume mounted!"
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-${2}-latest.tar.gz
sudo bsdtar -xpf ArchLinuxARM-rpi-${2}-latest.tar.gz -C root
echo "### Exploded the tar archive "
sync
sudo mv root/boot/* boot
sudo umount boot root
echo "### Final boot files moved, synced and unmounted!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment