Update swap.sh
This commit is contained in:
parent
34f3e59243
commit
95c88f7715
6
swap.sh
6
swap.sh
|
@ -5,11 +5,11 @@ create_swapfile() {
|
|||
# Detect the main disk by finding the partition mounted on root ('/')
|
||||
mount_point=$(df / | tail -1 | awk '{print $6}')
|
||||
|
||||
# Get available space on the partition in GB
|
||||
available_space=$(df -BG $mount_point | tail -1 | awk '{print $4}' | sed 's/G//')
|
||||
# Get available space on the 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))
|
||||
swap_size=$((available_space * 5 / 100 / 1024)) # Convert MB to GB
|
||||
if [ $swap_size -gt 30 ]; then
|
||||
swap_size=30
|
||||
elif [ $swap_size -lt 1 ]; then
|
||||
|
|
Loading…
Reference in New Issue