- mtpnt=$(grep "^${DISK}2" /proc/mounts | awk '{print $2}')
- if [ -n "$mtpnt" ]; then
- umount $mtpnt >/dev/null 2>&1
+ PART1_BLKID=$(blkid $PART1)
+ blkid $PART1
+
+ if echo $PART1_BLKID | grep -E -q -i 'TYPE=ntfs|TYPE=.ntfs'; then
+ echo "Partition 1 contains NTFS filesystem"
+
+ which ntfsresize
+ if [ $? -ne 0 ]; then
+ echo "###[FAIL] ntfsresize not found. Please install ntfs-3g package."
+ exit 1
+ fi
+
+ echo "ntfsfix -b -d $PART1 ..."
+ ntfsfix -b -d $PART1
+
+ echo "ntfsresize --size ${PART1_NEW_MB}Mi $PART1 ..."
+ ntfsresize -f --size ${PART1_NEW_MB}Mi $PART1
+ if [ $? -ne 0 ]; then
+ echo "###[FAIL] ntfsresize failed."
+ exit 1
+ fi
+ elif echo $PART1_BLKID | grep -E -q -i 'TYPE=ext[2-4]|TYPE=.ext[2-4]'; then
+ echo "Partition 1 contains EXT filesystem"
+
+ which resize2fs
+ if [ $? -ne 0 ]; then
+ echo "###[FAIL] resize2fs not found. Please install e2fsprogs package."
+ exit 1
+ fi
+
+ echo "e2fsck -f $PART1 ..."
+ e2fsck -f $PART1
+
+ echo "resize2fs $PART1 ${PART1_NEW_MB}M ..."
+ resize2fs $PART1 ${PART1_NEW_MB}M
+ if [ $? -ne 0 ]; then
+ echo "###[FAIL] resize2fs failed."
+ exit 1
+ fi
+ else
+ echo "###[FAIL] Unsupported filesystem in partition 1."
+ exit 1