-
Notifications
You must be signed in to change notification settings - Fork 54
/
flash-sdcard.sh
104 lines (88 loc) · 2.37 KB
/
flash-sdcard.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
# flash-sdcard.sh
#
# Automated Arch Linux ARM install script
# This script installs the latest version of Arch Linux ARM to an SD card.
#
# Based on official installation recommendations:
# https://archlinuxarm.org/platforms/armv6/raspberry-pi#installation
#
# This script requires the following input:
# 1. The full path to a block device where Arch ARM is to be installed.
#
# This script performs the following actions:
# 1. Creates 100MB vfat (boot) partition on specified block device;
# 2. Creates ext4 (root) parition on remaining space;
# 3. Creates a temporary directory for mount points and download;
# 4. Downloads a tarball of the lastest ArchARM distribution;
# 5. Extracts files to new root partition;
# 6. Moves /boot directory to boot partiton.
#
# Usage:
# bash flash-sdcard.sh /dev/sdcard
#
## Set flags
set -u
#set -e # fdisk may throw error codes even on successful writes.
## Check if input value was given and exists.
## Show usage message if not.
if [ $# -ne 1 ] || [ ! -e $1 ]; then
echo
echo "Valid path to SD card device is a required argument."
echo
echo "Example:"
echo " bash $0 /dev/mmcblk0"
echo
exit 1
fi
## Wipe SD card.
#dd if=/dev/zero of=$1
## Create partitions using fdisk by simulating user input.
## (fdisk was not designed with non-interactive use in mind.)
echo "o
n
p
1
+100M
n
p
2
p
w
q
" | fdisk $1
## Sync changes and update partition table.
sync; partprobe $1; sync
## Create tempory directory for mounts and download.
cd `mktemp -d`
mkdir boot root
## If partition numbering for the device follows sda -> sda1 format.
if [ -e "$1"1 ]; then
mkfs.vfat "$1"1
mount "$1"1 boot
mkfs.ext4 "$1"2
mount "$1"2 root
## If partition numbering for the device follows mmcblk0 -> mmcblk0p1 format.
else
mkfs.vfat "$1"p1
mount "$1"p1 boot
mkfs.ext4 "$1"p2
mount "$1"p2 root
fi
## Download tarball
SRC="http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz" #RasPi
#SRC="http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz" #RasPi 2
wget $SRC
## Download and verify PGP signature
## (Best practice, but disabled for simplicity's sake.)
#wget "$SRC".sig
#gpg --recv-keys 2BDBE6A6
#gpg --verify $SRC
## Extract tarball
tar -xf ArchLinuxARM-rpi-latest.tar.gz -C root
sync
mv root/boot/* boot # Move /boot files to boot partition
sync
## Unmount mounts
umount boot root
## We're done.