-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_sd_card.sh
executable file
·123 lines (81 loc) · 3.28 KB
/
part_sd_card.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
#please specify the SD card location.
#It will paritionate the SDcard to have 2 parts.
echo -e "$c_good *** START `basename "$0"` *** $c_default"
sdcard_abs="$1"
echo -e "$c_info Print last dmesg lines $c_default"
dmesg_var=`dmesg | tail -n 3`
dmesg_var_grep=`echo $dmesg_var | grep "new high speed SD card"`
if [ -n ${dmesg_var+x} ]; then
echo -e $dmesg_var
fi
if [ ! -b "${sdcard_abs}" ]; then
while [ ! -b "${sdcard_abs}" ]; do
echo "Error: could not find \"${sdcard_abs}\""
echo "You can plug the SD card or quit the script with CTRL + C"
read -p "Press [Enter] key to restart..."
done
fi
if [ "$(echo "${sdcard_abs}" | grep -P "/dev/sd\w$")" ]; then
sdcard_fat32_partition_number="1"
sdcard_dev_ext3_id="2"
sdcard_preloader_partition_number="3"
elif [ "$(echo "${sdcard_abs}" | grep -P "/dev/mmcblk\w$")" ]; then
sdcard_fat32_partition_number="p1"
sdcard_dev_ext3_id="p2"
sdcard_preloader_partition_number="p3"
else
echo "You entered a partition. Please enter only the name of the sdcard.. "
exit 1
fi
echo -e "$c_info The fdisk utility does not erase the first few bytes of the first sector in the card$c_default"
echo -e "$c_info dd is used to erase the first sector.$c_default"
#The fdisk utility does not erase the first few bytes of the first sector in the card
#dd is used to erase the first sector.
sudo dd if=/dev/zero of=${sdcard_abs} bs=1024 count=1
size_sd_byte=`sudo fdisk -l ${sdcard_abs} | head -n 2`
echo -e "$c_info Size sd card: $size_sd_byte bytes$c_default"
arrIN=(${size_sd_byte// / })
size_sd_card=${arrIN[4]}
#Look for the size of the device in bytes and calculate the new number of cylinders
#using the following formula, dropping all fractions:
#new_cylinders = <size> / 8225280
new_cylinders=$(($size_sd_card/8225280))
echo $new_cylinders
#Partition the SD card.
#Create two partitions on the SD card.
# One 200 MB sized boot partition.
# Second partition taking the remaining space on the SD card.
#Configure the sectors, heads and cylinders of the SD card.
#x Expert command
#h #heads
#255
#s #sector
#63
#c #cylinders
#$new_cylinders
#r
heads=255
sectors=63
lastsector="+200M"
echo -e "$c_info Use fdisk to part the SD card.$c_default"
echo -e "$c_info Create two partitions on the SD card.$c_default"
echo -e "$c_info One 200 MB sized boot partition. $c_default"
echo -e "$c_info Second partition taking the remaining space on the SD card.$c_default"
echo -e "x\nh\n$heads\ns\n$sector\nc\n$new_cylinders\nr\nn\np\n1\n\n$lastsector\nn\np\n2\n\n\na\n1\nt\n1\nc\nt\n2\n83\np\nw\n" | sudo fdisk "${sdcard_abs}"
sudo mkfs.vfat -F 32 -n boot ${sdcard_abs}$sdcard_fat32_partition_number
sudo mkfs.ext4 -L root ${sdcard_abs}$sdcard_dev_ext3_id
sudo mkdir -p /mnt/boot
sudo mount ${sdcard_abs}$sdcard_fat32_partition_number /mnt/boot
sudo umount ${sdcard_abs}$sdcard_fat32_partition_number
sudo umount ${sdcard_abs}$sdcard_dev_ext3_id
# delete mount points for sdcard
sudo rm -rf /mnt/boot
sudo sync
if [ "$2" -eq "1" ]; then
echo -e "$c_info Call ./sd_write_image.sh $c_default"
./sd_write_image.sh ${sdcard_abs}
fi
echo -e "$c_info $c_default"
echo -e "$c_info You may need to plug/unplug the SD card to see the partitions. $c_default"
echo -e "$c_info $c_default"