-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS15resize_data
More file actions
executable file
·46 lines (43 loc) · 1.64 KB
/
Copy pathS15resize_data
File metadata and controls
executable file
·46 lines (43 loc) · 1.64 KB
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
#!/bin/sh
#
# Resize the last partition to fill the SD card if it has not been already
# The number of the partition to be resized
PARTNUM=8
exec > /var/log/init.log
exec 2>&1
# If the partition is too small, resize it, and then reboot
FIRST=$(sgdisk /dev/mmcblk0 -i 8 | grep "First sector" | awk '{print $3}')
LAST=$(sgdisk /dev/mmcblk0 -i 8 | grep "Last sector" | awk '{print $3}')
SECTORS=$(expr $LAST - $FIRST)
echo "Partition is currently $SECTORS sectors"
if [[ $SECTORS -lt 2000000 ]]; then
umount /data
echo "Resizing partition..."
# Get the last block of the previous partition
PREV_END=$(sgdisk /dev/mmcblk0 -i $(expr $PARTNUM - 1) | grep "Last sector" | awk '{print $3}')
# Sector to tart new partition on
START=$(expr $PREV_END + 1)
# delete existing partition
sgdisk -d $PARTNUM /dev/mmcblk0
# recreate, setting partition, type is 8300 (linux partition)
sgdisk -a 1 -n $PARTNUM:$START: -c $PARTNUM:Data -t $PARTNUM:8300 /dev/mmcblk0
sync
echo "Rebooting..."
reboot -f
else
# make sure mount point exists
mkdir -p /data
# The filesystem has to be mounted to determine its size
mount /dev/mmcblk0p$PARTNUM /data
# Read the size of the filesystem
FS_SECTORS=$(df /dev/mmcblk0p$PARTNUM | grep "/dev/mmcblk0p$PARTNUM" | awk '{print $2}')
echo "Filesystem is $FS_SECTORS sectors"
if [[ $FS_SECTORS -lt 1000000 ]]; then
echo "Resizing partition"
umount /data
# if the filesystem is too small, recreate it
# (it does not appear to be possible to resize an exfat fs without reformating)
mkfs.exfat -L Data /dev/mmcblk0p$PARTNUM
sync
fi
fi