Ubuntu Pastebin

Paste from ogra at Tue, 18 Aug 2015 09:39:13 +0000

Download as text
 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
#! /bin/sh

writable_part="$(findfs LABEL=writable)"
writable_disk="$(echo $writable_part|sed 's/[0-9]*$//')"
partnum=$(echo $writable_part|sed 's/.*[a-z][^0-9]*//g')

# sanitize for mmcblk0p vs mmcblk0
case $(basename $writable_part) in
	mmcblk*)
	  DISKNAME="$(echo $writable_disk|sed 's/p$//')"
	  ;;
        *)
          DISKNAME="$writable_disk"
	  ;;
esac

# obtain partition sizes
disk_size="$(grep -w $(basename $DISKNAME) /proc/partitions|tr -s ' '|cut -d' ' -f4)"
part_size="$(grep -w $(basename $writable_part) /proc/partitions|tr -s ' '|cut -d' ' -f4)"
all_parts="$(($(grep $(basename $writable_disk)[0-9].*$ /proc/partitions|tr -s ' '|cut -d' ' -f4|tr '\n' '+'|sed 's/+$//')))"

# if the sum of all parts is leaving more than 10% unused, grow writable
# partition to full disk size
if [ "$(($disk_size/10))" -lt "$(($disk_size-$all_parts))" ]; then
    # grow our selected partition to max space available
    echo ", +"|LANG=C /sbin/sfdisk -N $partnum $DISKNAME
    # check the filesystem before attempting re-size
    LANG=C /sbin/e2fsck -fy $writable_part
    # resize the filesystem to full size of the partition
    LANG=C /sbin/resize2fs -p $writable_part
fi
Download as text