-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathformat-fat32-ums
209 lines (202 loc) · 5.41 KB
/
format-fat32-ums
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
# Advanced script to install and configure Arch with ppp on indicated sdcardtoformat
# More info and newest @ http://www.github.com/iugamarian/raspberrypisetup
# Version 1.73 tested and it works
# Forked from ShorTie <[email protected]>
# Brought to you by iugamarian <[email protected]>
# Configuration - choose here carefuly
sdcardtoformat=/dev/sdwhat # Before running, lsblk to indicate card here
partitionname=MUSIC64
#********** END Configuration **************************************************************
# Check to see if device is indicated
if [ `echo $sdcardtoformat | grep sdwhat |wc -c` -eq 0 ]; then
echo ""
echo "The drive to move root to is $sdcardtoformat."
echo ""
else
lsblk
echo ""
echo "Specify the drive by editing the beginning of this script."
echo ""
exit 1
fi
# Check to see if running as root
echo -e "\nChecking for root."
if [ `id -u` != 0 ]; then
echo "Not root."
echo -e "Need to be run as root.\n"
echo " Try 'sudo sh rpiarchppp' as a user. Exiting."
echo ""
exit 1
else
echo "Root."
fi
# Allowing dd to be able to clear MBR (permission)
viewsudouser=`logname`
viewroot=""
# A string echo "" is seen by wc as having 1 character so n+1, and a failed grep has a wc of 0
if [ `echo $viewsudouser | grep "root" |wc -c` != 0 ] && [ `echo $viewsudouser |wc -c` = 5 ]; then
viewroot="root"
fi
# On Arch a no login name gives a wc of 1
if [ `echo $viewsudouser |wc -c` = 1 ]; then
viewroot="root"
fi
# On other systems no login name maybe gives no login name
if [ `echo $viewsudouser | grep "no login name" |wc -c` != 0 ]; then
viewroot="root"
fi
if [ `echo $viewroot |wc -c` != 1 ]; then
echo ""
echo "Only root."
echo "Adding root to the disk group."
echo""
usermod -G disk --append root
else
echo ""
echo "Sudo is used by a user named $viewsudouser."
echo "Adding user named $viewsudouser to the disk group."
echo ""
usermod -G disk --append $viewsudouser
fi
echo ""
echo "Checking for programs that are needed:"
echo ""
# On other distributions the user installs them
neededprograms=""
if [ `which fdisk |wc -c` != 0 ]; then
echo "Found fdisk."
else
neededprograms+="fdisk "
fi
if [ `which mkfs.vfat |wc -c` != 0 ]; then
echo "Found mkfs.vfat."
else
neededprograms+="mkfs.vfat "
fi
if [ `which wget |wc -c` != 0 ]; then
echo "Found wget."
else
neededprograms+="wget "
fi
echo ""
if [ "$neededprograms" = "" ]; then
echo "All needed programs available."
else
echo "Missing needed programs, install them:"
echo ""
echo $neededprograms
echo ""
echo "On Arch fdisk is in util-linux which is in base-devel."
echo ""
echo "On Arch mkfs.vfat is in dosfstools."
echo ""
echo "Exiting."
echo ""
exit 1
fi
# Detecting availability of indicated device
if ! (fdisk -l | grep $sdcardtoformat); then
echo "Can't find ($sdcardtoformat). Insert and indicate it."
echo "No files. Only devices. Exiting."
echo ""
exit 1
else
echo "Found indicated device $sdcardtoformat."
echo ""
fi
echo ""
echo "============================================================"
echo ""
sleep 2
# Safety unmounting of possible partitions, logicals can start from 5
echo "Unmounting partitions, up to 9, with or without p in front:"
echo ""
umount "$sdcardtoformat"1
umount "$sdcardtoformat"2
umount "$sdcardtoformat"3
umount "$sdcardtoformat"4
umount "$sdcardtoformat"5
umount "$sdcardtoformat"6
umount "$sdcardtoformat"7
umount "$sdcardtoformat"8
umount "$sdcardtoformat"9
umount "$sdcardtoformat"p1
umount "$sdcardtoformat"p2
umount "$sdcardtoformat"p3
umount "$sdcardtoformat"p4
umount "$sdcardtoformat"p5
umount "$sdcardtoformat"p6
umount "$sdcardtoformat"p7
umount "$sdcardtoformat"p8
umount "$sdcardtoformat"p9
swapoff "$sdcardtoformat"1
swapoff "$sdcardtoformat"2
swapoff "$sdcardtoformat"3
swapoff "$sdcardtoformat"4
swapoff "$sdcardtoformat"5
swapoff "$sdcardtoformat"6
swapoff "$sdcardtoformat"7
swapoff "$sdcardtoformat"8
swapoff "$sdcardtoformat"9
swapoff "$sdcardtoformat"p1
swapoff "$sdcardtoformat"p2
swapoff "$sdcardtoformat"p3
swapoff "$sdcardtoformat"p4
swapoff "$sdcardtoformat"p5
swapoff "$sdcardtoformat"p6
swapoff "$sdcardtoformat"p7
swapoff "$sdcardtoformat"p8
swapoff "$sdcardtoformat"p9
echo ""
sleep 5
echo ""
echo "Deleting MBR and fat allocation table general area with dd:"
# Need to dd more because fat filesystems may get confused about random
# data in their first part where they store the fat allocation table
dd if=/dev/zero of=$sdcardtoformat bs=1M count=32 iflag=fullblock
echo ""
echo ""
echo "Partitioning indicated device:"
echo ""
# On fdisk older than 25, setting bootable flag adds 1 after a: "a,1" < 25, "a" >= 25
# But I follow the archlinuxarm instructions which don't set booteble flag
# "Fdisk area". Be careful about the new lines (Enter).
fdisk $sdcardtoformat <<EOF
o
n
t
c
w
EOF
# Finished partitioning. Be careful about the new lines (Enter).
sleep 5
echo ""
echo "=================================================="
echo ""
echo ""
echo "Detecting if the device is seen as a mmcblk so that partitions have a p in front"
echo ""
if [ `echo $sdcardtoformat | grep mmcblk |wc -c` != 0 ]; then
echo ""
echo "Partition numbers have a p in front of them..."
bootpart="$sdcardtoformat"p1
else
echo ""
echo "Partition numbers don't have a p in front of them..."
bootpart="$sdcardtoformat"1
fi
echo ""
echo -n "Boot partition is "
echo $bootpart
echo ""
echo ""
echo "Formatting partition:"
echo ""
mkfs.vfat -n $partitionname $bootpart
echo "Exiting happy."
echo ""
sleep 2
sync
sleep 2
exit 0