#!/bin/bash ### BEGIN INIT INFO # Provides: resize2fs # Required-Start: $local_fs # Required-Stop: # Should-Start: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Resize the root filesystem to fill whole rootfs partition # Description: ### END INIT INFO case "$1" in start) set -e # Try to get rootfs device and type ROOTFS=$(findmnt / | awk -F" " '/\/dev\// {print $2"\t"$3}') set ${ROOTFS} device=$1 rootfstype=$2 # If this doesn't work (wheezy) then try it the old way if [ -z $rootfstype ]; then device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0) PARTITIONS=$(($(fdisk -l $device | grep $device | wc -l)-1)) device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0)"p"$PARTITIONS N=/etc/init.d/resize2fs root_device=$(mountpoint -d /) for file in /dev/* ; do CURRENT_DEVICE=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" $file)) if [ $CURRENT_DEVICE = $root_device ]; then root_partition=$file break; fi done rootfstype=$(blkid -s TYPE -o value $root_partition) fi # if ext4 and rootfs should be resized then do it if [[ $rootfstype == ext4 && ! -f "/root/.no_rootfs_resize" ]]; then echo -e "\n### [resize2fs] Start resizing partition now\n" >>/var/log/armhwinfo.log /sbin/resize2fs $device >>/var/log/armhwinfo.log 2>&1 fi # disable further executions of this script update-rc.d -f resize2fs remove >/dev/null 2>&1 ;; esac