~aleteoryx/muditaos

ref: 3ac4bd4935e598da305b77e7dea8af20413ba668 muditaos/config/partition_emmc.sh -rwxr-xr-x 1.9 KiB
3ac4bd49 — Wojtek Rzepecki [EGD-7127] Store imported contacts in DB 4 years ago
                                                                                
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
#!/bin/bash
# Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

# set -eo pipefail
if [ ! -e config/common.sh ]; then
	echo "No config/common.sh, run this script from git root"
	exit 1
fi

if [ ! $(which sfdisk) ]; then
	echo "No sfdisk, please install"
	exit 1
fi

if [ ! $(which parted) ]; then
	echo "No parted, please install"
	exit 1
fi

source config/common.sh
is_root=`id -u`
if [ "$1" == "" ] || [ $is_root != 0 ]; then
	echo "Refuse to work with no device. Runme as root [uid=$is_root]"
	echo -e "$0 <dev> [-f]\n"
	exit 1
else
	dev=$1
fi

if [ "$2" == "-f" ]; then
	use_the_force=1
else
	use_the_force=0
fi

pcount=$(sfdisk --dump $dev | grep "start=" | wc -l)
is_mounted=$(grep $dev /etc/mtab | awk '{print $2}')
if [ "$is_mounted" == "" ]; then
	echo "$dev is not mounted"
else
	echo "$dev is mounted at $is_mounted, please unmount it first"
	exit 1
fi

if [ $pcount == 2 ] && [ $use_the_force == 0 ]; then
	echo "device $dev already has 2 partitions (use -f to force)"
	exit 1
else
	echo "$dev has $pcount partitions"
fi

echo "!!! $dev will be wiped, no recovery at this point"
echo "!!! press ENTER to continue or CTRL+C to cancel"
echo -ne "?"
read

echo "wipe disk header"
dd if=/dev/zero of=$dev bs=8192 count=8192
echo "create msdos partition table"
parted $dev mklabel msdos

sleep 1

echo "Sleep and re-probe disk"

sleep 1
partprobe

echo "write partition table"
sfdisk --wipe always $dev < config/emmc_partition_table.dump

if [ $? != 0 ]; then
	echo "partitioning device $dev failed"
	exit 1
fi

part1=$(sfdisk $dev --dump | grep bootable | awk '{print $1}')
part2=$(sfdisk $dev --dump | tail -n 1 | awk '{print $1}')

echo "create FATs"
echo "FAT: $MUDITAOS_PARTITION_PRIMARY $part1"
mkfs.vfat -n $MUDITAOS_PARTITION_PRIMARY $part1
echo "FAT: $MUDITAOS_PARTITION_RECOVERY $part2"
mkfs.vfat -n $MUDITAOS_PARTITION_RECOVERY $part2

echo "probe new partitions to OS"
partprobe