1
0
Fork 1

Update swap.sh

This commit is contained in:
colin 2024-09-13 16:46:03 -04:00
parent 34f3e59243
commit 95c88f7715
1 changed files with 3 additions and 3 deletions

View File

@ -5,11 +5,11 @@ create_swapfile() {
# Detect the main disk by finding the partition mounted on root ('/') # Detect the main disk by finding the partition mounted on root ('/')
mount_point=$(df / | tail -1 | awk '{print $6}') mount_point=$(df / | tail -1 | awk '{print $6}')
# Get available space on the partition in GB # Get available space on the partition in MB
available_space=$(df -BG $mount_point | tail -1 | awk '{print $4}' | sed 's/G//') 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) # Calculate 5% of the available space, and ensure it's within the limits (max 30GB)
swap_size=$((available_space * 5 / 100)) swap_size=$((available_space * 5 / 100 / 1024)) # Convert MB to GB
if [ $swap_size -gt 30 ]; then if [ $swap_size -gt 30 ]; then
swap_size=30 swap_size=30
elif [ $swap_size -lt 1 ]; then elif [ $swap_size -lt 1 ]; then