Clean up part_shrink()
This commit is contained in:
parent
3a9fc5cbce
commit
fb03b85fee
@ -5,7 +5,7 @@
|
|||||||
# Some ideas and code reworked from other resources
|
# Some ideas and code reworked from other resources
|
||||||
# AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due
|
# AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due
|
||||||
|
|
||||||
VER="2.0.44" # installer version
|
VER="2.0.45" # installer version
|
||||||
DIST="ArchLabs" # linux distributor
|
DIST="ArchLabs" # linux distributor
|
||||||
MNT="/mnt" # install mountpoint
|
MNT="/mnt" # install mountpoint
|
||||||
ANS="/tmp/ans" # dialog answer file
|
ANS="/tmp/ans" # dialog answer file
|
||||||
@ -931,13 +931,11 @@ part_shrink()
|
|||||||
part_find "${device##*/}[^ ]" || return 1
|
part_find "${device##*/}[^ ]" || return 1
|
||||||
(( COUNT == 1 )) && part="$(awk '{print $1}' <<< "${PARTS[@]}" )"
|
(( COUNT == 1 )) && part="$(awk '{print $1}' <<< "${PARTS[@]}" )"
|
||||||
|
|
||||||
if (( COUNT == 1 )) || dlg part menu "Resize" "\nWhich partition on $device do you want to resize?" $PARTS && [[ $part ]]; then
|
if (( COUNT == 1 )) || dlg part menu "Resize" "\nWhich partition on $device do you want to resize?" $PARTS; then
|
||||||
fs=$(lsblk -lno FSTYPE "$part")
|
fs=$(lsblk -lno FSTYPE "$part")
|
||||||
case "$fs" in
|
case "$fs" in
|
||||||
ext*|ntfs)
|
ext*|ntfs)
|
||||||
msg "Resize" "\nGathering device size info.\n" 0
|
msg "Resize" "\nGathering device size info.\n" 0
|
||||||
|
|
||||||
# get device size info
|
|
||||||
num="${part: -1}"
|
num="${part: -1}"
|
||||||
end=$(parted -s "$device" unit KiB print | awk '/^\s*'"$num"'/ {print $3}') # part size in KiB
|
end=$(parted -s "$device" unit KiB print | awk '/^\s*'"$num"'/ {print $3}') # part size in KiB
|
||||||
devsize=$(parted -s "$device" unit KiB print | awk '/Disk '"${device//\//\\/}"':/ {print $3}') # whole device size in KiB
|
devsize=$(parted -s "$device" unit KiB print | awk '/Disk '"${device//\//\\/}"':/ {print $3}') # whole device size in KiB
|
||||||
@ -945,35 +943,34 @@ part_shrink()
|
|||||||
min=$(df --output=used --block-size=MiB "$part" | awk 'NR == 2 {print int($1) + 256}')
|
min=$(df --output=used --block-size=MiB "$part" | awk 'NR == 2 {print int($1) + 256}')
|
||||||
max=$(df --output=avail --block-size=MiB "$part" | awk 'NR == 2 {print int($1)}')
|
max=$(df --output=avail --block-size=MiB "$part" | awk 'NR == 2 {print int($1)}')
|
||||||
umount $MNT >/dev/null 2>&1
|
umount $MNT >/dev/null 2>&1
|
||||||
|
|
||||||
# get new size from user
|
|
||||||
tput cnorm
|
tput cnorm
|
||||||
if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$min" "$max" $((max / 2)) 2>$ANS; then
|
if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$min" "$max" $((max / 2)) 2>$ANS; then
|
||||||
size=$(< "$ANS"); size=$((size * 1024))
|
size=$(< "$ANS")
|
||||||
|
size=$((size * 1024))
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
clear
|
clear
|
||||||
case "$fs" in
|
case "$fs" in
|
||||||
ext[2-4])
|
ntfs)
|
||||||
|
if ntfsresize -fc "$part"; then
|
||||||
|
ntfsresize -ff --size $(( (size * 1024) / 1000 ))k "$part" 2>$ERR # k=10^3 bytes
|
||||||
|
errshow "ntfsresize -f -s $(( (size * 1024) / 1000 ))k $part" || return 1
|
||||||
|
else
|
||||||
|
msg "Resize" "\nThe ntfs partition $part cannot be resized because it is scheduled for a consistency check.\n\nTo do a consistency check in windows open command prompt as admin and run:\n\n\tchkdsk /f /r /x\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
e2fsck -f "$part"; sleep 0.5
|
e2fsck -f "$part"; sleep 0.5
|
||||||
resize2fs -f "$part" ${size}K 2>$ERR # K=2^10 bytes
|
resize2fs -f "$part" ${size}K 2>$ERR # K=2^10 bytes
|
||||||
errshow "resize2fs -f $part ${size}K" || return 1
|
errshow "resize2fs -f $part ${size}K" || return 1
|
||||||
;;
|
;;
|
||||||
ntfs)
|
|
||||||
ntfsresize -fc "$part" || { msg "Resize" "\nThe ntfs partition $part cannot be resized because it is scheduled for a consistency check.\n\nTo do a consistency check in windows open command prompt as admin and run:\n\n\tchkdsk /f /r /x\n"; return 1; }
|
|
||||||
ntfsresize -ff --size $(( (size * 1024) / 1000 ))k "$part" 2>$ERR # k=10^3 bytes
|
|
||||||
errshow "ntfsresize -f -s $(( (size * 1024) / 1000 ))k $part" || return 1
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo "filesystem shrunk successfully, now the partition"
|
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
parted "$device" resizepart "$num" ${size}KiB || return 1
|
parted "$device" resizepart "$num" ${size}KiB || return 1
|
||||||
(( size++ ))
|
(( size++ ))
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
|
|
||||||
if [[ $devsize == "$end" ]]; then
|
if [[ $devsize == "$end" ]]; then
|
||||||
parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2>$ERR
|
parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2>$ERR
|
||||||
errshow "parted -s $device mkpart primary ext4 ${size}KiB 100%" || return 1
|
errshow "parted -s $device mkpart primary ext4 ${size}KiB 100%" || return 1
|
||||||
@ -981,10 +978,10 @@ part_shrink()
|
|||||||
parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2>$ERR
|
parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2>$ERR
|
||||||
errshow "parted -s $device mkpart primary ext4 ${size}KiB ${end}KiB" || return 1
|
errshow "parted -s $device mkpart primary ext4 ${size}KiB ${end}KiB" || return 1
|
||||||
fi
|
fi
|
||||||
|
msg "Resize Complete" "\n$part has been successfully resized to $((size / 1024))M.\n" 1
|
||||||
msg "Resize Complete" "\n$part has been successfully resized to $((size / 1024))M.\n"
|
|
||||||
;;
|
;;
|
||||||
*) msg "Invalid Filesystem: $fs" "\nResizing only supports ext and ntfs.\n\nFor unformatted partitions, cfdisk can be used.\n" ;;
|
"") msg "No Filesystem" "\nFor unformatted partitions, cfdisk can be used in the partition menu.\n" ;;
|
||||||
|
*) msg "Invalid Filesystem: $fs" "\nResizing only supports ext and ntfs.\n" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user