-
Notifications
You must be signed in to change notification settings - Fork 9
/
make-sdcard.sh
62 lines (49 loc) · 1.86 KB
/
make-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
#!/bin/bash
echo "[ INFO ] Checking for precesne of pi.tar.gz tarball.";
if [[ -e $(ls pi.tar.gz 2> /dev/null) ]] ; then
echo "[INFO] pi.tar.gz found.";
else
echo "[ ERROR ] The pi.tar.gz tarball needs to be in the same directory as this script.";
exit;
fi
echo "[ INFO ] Checking for presence of sdcard at /dev/mmcblk";
if (( var=$(sudo fdisk -l /dev/mmcblk0 1>& /dev/null) $? == 0 )) ; then
echo "[ INFO ] Found sdcard.";
else
echo "[ ERROR ] Cannot find sdcard.";
exit;
fi
mountpoint=$(mount | awk '/mmcblk0p2/{print $3}');
if [[ $mountpoint ]] ; then
sudo umount -R $mountpoint;
fi
echo "[ INFO ] Partitioning sdcard.";
for n in {1..4}; do parted -a optimal /dev/mmcblk0 rm $n 2> /dev/null; done
sudo parted -a optimal /dev/mmcblk0 mkpart primary fat32 0% 513MB
sudo parted -a optimal /dev/mmcblk0 mkpart primary ext4 513MB 100%
echo "[ INFO ] Creating FAT32 filesystem on /dev/mmcblk0p1.";
echo 'y' | sudo mkfs.vfat -F32 /dev/mmcblk0p1
echo "[ INFO ] Creating EXT4 filesystem on /dev/mmcblk0p2.";
echo 'y' | sudo mkfs.ext4 /dev/mmcblk0p2
echo "[ INFO ] Checking if mountpoint /mnt/pi exists.";
if [[ -e /mnt/pi ]] ; then
echo "[ INFO ] Mountpoint /dev/pi exists.";
else
sudo mkdir -p /mnt/pi;
echo '[ WARNING ] /mnt/pi doesnt exist - creating it now.';
fi
echo "[ INFO ] Mounting /dev/mmcblk0p2 on /mnt/pi";
sudo mount /dev/mmcblk0p2 /mnt/pi;
echo "[ INFO ] Checking if mountpoint /mnt/pi/boot exists.";
if [[ -e /mnt/pi/boot ]] ; then
echo "[ INFO ] Mountpoint /dev/pi/boot exists.";
else
sudo mkdir -p /mnt/pi/boot;
echo '[ WARNING ] /mnt/pi/boot doesnt exist - creating it now.';
fi
echo "[ INFO ] Mounting /dev/mmcblk0p1 on /mnt/pi/boot";
sudo mount /dev/mmcblk0p1 /mnt/pi/boot;
echo "[ INFO ] Unpacking tarball onto your sdcard.";
tar -xzf pi.tar.gz -C /mnt/pi/ ;
echo "[ INFO ] Unmounting your sdcard now.";
sudo umount -R /mnt/pi ;