1
0
Fork 1

Update swap.sh

This commit is contained in:
colin 2024-09-13 17:03:51 -04:00
parent 95c88f7715
commit 2f712d05de
1 changed files with 13 additions and 5 deletions

18
swap.sh
View File

@ -2,17 +2,25 @@
# Function to create swap file
create_swapfile() {
# Detect the main disk by finding the partition mounted on root ('/')
# Detect the partition mounted on root ('/')
mount_point=$(df / | tail -1 | awk '{print $6}')
# Get available space on the partition in MB
# Get available space on the root partition in MB
available_space=$(df -BM $mount_point | tail -1 | awk '{print $4}' | sed 's/M//')
# Calculate 5% of the available space, and ensure it's within the limits (max 30GB)
swap_size=$((available_space * 5 / 100 / 1024)) # Convert MB to GB
# Calculate 5% of the available space in MB
swap_size=$((available_space * 5 / 100)) # 5% of available space in MB
# Convert swap size from MB to GB
swap_size=$((swap_size / 1024)) # Convert MB to GB
# Set upper limit of 30GB for the swap file
if [ $swap_size -gt 30 ]; then
swap_size=30
elif [ $swap_size -lt 1 ]; then
fi
# Abort if the calculated swap size is less than 1GB
if [ $swap_size -lt 1 ]; then
echo "Not enough disk space to create a swap file."
exit 1
fi