Tweaks to resize

This commit is contained in:
natemaia 2019-04-17 20:01:43 -07:00
parent ce67bb37b3
commit 53a5328a6d

View File

@ -5,7 +5,7 @@
# Some ideas and code reworked from other resources
# AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due
VER="2.0.35" # installer version
VER="2.0.36" # installer version
DIST="ArchLabs" # linux distributor
MNT="/mnt" # install mountpoint
ANS="/tmp/ans" # dialog answer file
@ -918,16 +918,19 @@ part_resize()
if (( COUNT == 1 )) || dlg part menu "Resize" "\nWhich partition on $device do you want to resize?" $PARTS && [[ $part ]]; then
fs=$(lsblk -lno FSTYPE "$part")
case "$fs" in
ext[2-4]|ntfs)
ext*|ntfs)
msg "Resize" "\nGathering device size info.\n" 0
# shit hacks to get device size info
num="${part: -1}"
end=$(parted -s "$device" print | awk '/^\s*'"$num"'/ {print $3}')
devsize=$(parted -s "$device" print | awk '/Disk '"${device//\//\\/}"':/ {print $3}')
mount "$part" $MNT >/dev/null 2>&1
sleep 0.5
mount "$part" $MNT >/dev/null 2>&1; sleep 0.5
min=$(df "$part" | awk '/'"${part//\//\\/}"'/ {print int($3 / 1024)}') # used
max=$(df "$part" | awk '/'"${part//\//\\/}"'/ {print int($4 / 1024)}') # available
umount $MNT >/dev/null 2>&1
# get new size from user
tput cnorm
if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$min" "$max" $((max / 2)) 2>$ANS; then
(( (size = $(< "$ANS")) + 1025 <= max )) || return 1
@ -935,6 +938,7 @@ part_resize()
else
return 1
fi
clear
case "$fs" in
ext[2-4])
@ -943,14 +947,16 @@ part_resize()
errshow "resize2fs -f $part ${size}K" || return 1
;;
ntfs)
ntfsresize -fc -s ${size}k "$part" 2>$ERR
ntfsresize -f -s ${size}k "$part" 2>$ERR
errshow "ntfsresize -f -s ${size}k $part" || return 1
;;
esac
sleep 0.5
(( size += 1024 ))
parted "$device" resizepart "$num" ${size}Kib || return 1
sleep 0.5
if (( ++size < (max * 1024) )); then
if [[ $devsize == "$end" ]]; then
parted -s "$device" mkpart primary ext4 ${size}Kib 100% 2>$ERR
@ -959,12 +965,11 @@ part_resize()
fi
errshow "parted -s $device mkpart primary ext4 ${size}Kib 100%" || return 1
fi
sleep 1
msg "Resize Complete" "\n$part has been successfully resized to $(( (size - 1025) / 1024 ))M.\n"
;;
*)
msg "Invalid Filesystem: $fs" "\nCurrently resizing is only supported for ext2/3/4 and ntfs filesystems.\n\nFor unformatted partitions, cfdisk can be used without the need to resize the filesystem.\n"
;;
*) msg "Invalid Filesystem: $fs" "\nResizing only supports ext and ntfs.\n\nFor unformatted partitions, cfdisk can be used.\n" ;;
esac
fi
}