if [ "$min_free_space" -lt "$free_space" ]; then
echo "initrd: found more than 10% free space on disk, resizing ${writable_part}" >/dev/kmsg || true
echo "initrd: partition to full disk size, see ${LOGFILE} for details" >/dev/kmsg || true
# back up the original partition table for later use or debugging
parted -ms "$device" unit B print >$TMPFILE 2>/dev/null
# grow our selected partition to max space available
table="$(parted -ms "$device" print| grep ^/| cut -d: -f6)"
case $table in
gpt)
# do_gpt needs the device name
do_gpt "$device" >>$LOGFILE 2>&1
resizeopts="-p"
;;
mbr|msdos)
# do_mbr needs the device node and partition number
do_mbr "$device" "$partition" >>$LOGFILE 2>&1
resizeopts="-f -p"
;;
*)
echo "unknown partition table type, not resizing" >>$LOGFILE
exit 0
;;
esac
# make sure the partitions are ready for further use
udevadm settle >>$LOGFILE 2>&1
# check the filesystem before attempting re-size
e2fsck -fy "$writable_part" >>$LOGFILE 2>&1
# resize the filesystem to full size of the partition
resize2fs "$resizeopts" "$writable_part" >>$LOGFILE 2>&1
fi