Ask for swap size

This commit is contained in:
Santiago Lo Coco 2022-01-03 16:08:31 -03:00
parent 66cd1b9226
commit 008d364575
1 changed files with 21 additions and 8 deletions

View File

@ -83,12 +83,22 @@ partDisks() {
exitIfCancel "You must select the swap partition." "partDisks" exitIfCancel "You must select the swap partition." "partDisks"
swapPart=$(echo $result | cut -d' ' -f1) swapPart=$(echo $result | cut -d' ' -f1)
else else
whiptail --yesno "Do you want a swapfile?" 0 0 whiptail --yesno "Do you want to create a swapfile?" 0 0
[ $? -eq 0 ] && createSwapfile if [ $? -eq 0 ]; then
sizeStr=$(whiptail --inputbox "Enter the size of the swapfile (in GB)." 0 0 3>&1 1>&2 2>&3)
exitIfCancel "You must enter a size." "partDisks"
size=$(echo $sizeStr | awk -F'[^0-9]+' '{ print $1 }')
createSwapfile $size
fi
fi fi
else else
whiptail --yesno "Do you want a swapfile?" 0 0 whiptail --yesno "Do you want to create a swapfile?" 0 0
[ $? -eq 0 ] && createSwapfile if [ $? -eq 0 ]; then
sizeStr=$(whiptail --inputbox "Enter the size of the swapfile (in GB)." 0 0 3>&1 1>&2 2>&3)
exitIfCancel "You must enter a size." "partDisks"
size=$(echo $sizeStr | awk -F'[^0-9]+' '{ print $1 }')
createSwapfile $size
fi
fi fi
else else
autoSelection=true autoSelection=true
@ -99,11 +109,14 @@ partDisks() {
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
result=$(whiptail --title "Select the swap space." --menu "" 0 0 0 "Partition" "" "Swapfile" "" 3>&1 1>&2 2>&3) result=$(whiptail --title "Select the swap space." --menu "" 0 0 0 "Partition" "" "Swapfile" "" 3>&1 1>&2 2>&3)
exitIfCancel "You must select a swap space." "partDisks" exitIfCancel "You must select a swap space." "partDisks"
sizeStr=$(whiptail --inputbox "Enter the size of the ${result} (in GB)." 0 0 3>&1 1>&2 2>&3)
exitIfCancel "You must enter a size." "partDisks"
size=$(echo $sizeStr | awk -F'[^0-9]+' '{ print $1 }')
if [ "$result" = "Partition" ]; then if [ "$result" = "Partition" ]; then
swapPart=${disk}2 swapPart=${disk}2
rootPart=${disk}3 rootPart=${disk}3
else else
createSwapfile createSwapfile $size
fi fi
fi fi
@ -116,7 +129,7 @@ partDisks() {
createSwapfile() { createSwapfile() {
swapfile=/mnt/swapfile swapfile=/mnt/swapfile
dd if=/dev/zero of=$swapfile bs=1M count=512 status=progress dd if=/dev/zero of=$swapfile bs=1M count=$1 status=progress
chmod 600 $swapfile chmod 600 $swapfile
mkswap $swapfile mkswap $swapfile
swapon $swapfile swapon $swapfile
@ -127,7 +140,7 @@ autoPart() {
sgdisk $disk -n=1:0:+300M -t=1:ef00 2>&1 | debug sgdisk $disk -n=1:0:+300M -t=1:ef00 2>&1 | debug
if [ -n "$swapPart" ]; then if [ -n "$swapPart" ]; then
sgdisk $disk -n=2:0:+1024M -t=2:8200 2>&1 | debug sgdisk $disk -n=2:0:+${size}G -t=2:8200 2>&1 | debug
sgdisk $disk -n=3:0:0 2>&1 | debug sgdisk $disk -n=3:0:0 2>&1 | debug
else else
sgdisk $disk -n=2:0:0 2>&1 | debug sgdisk $disk -n=2:0:0 2>&1 | debug