Utoljára aktív 1719142278

swap.sh Eredeti
1#!/bin/bash
2
3# Define the swap file location and size
4SWAPFILE="/swapfile"
5SWAPSIZE="64G"
6
7# Check if the script is being run as root
8if [ "$(id -u)" -ne 0 ]; then
9 echo "This script must be run as root"
10 exit 1
11fi
12
13# Ensure util-linux is installed for mkswap and swapon commands
14apt-get update
15apt-get install -y util-linux
16
17# Create the swap file with the defined size
18fallocate -l $SWAPSIZE $SWAPFILE
19
20# Set the correct permissions for the swap file
21chmod 600 $SWAPFILE
22
23# Set up the swap area
24/sbin/mkswap $SWAPFILE
25
26# Enable the swap file
27/sbin/swapon $SWAPFILE
28
29# Add the swap file to /etc/fstab for automatic mounting at boot
30echo "$SWAPFILE none swap sw 0 0" >> /etc/fstab
31
32# Verify the swap file is active
33/sbin/swapon --show
34
35# Confirm the swap file entry in /etc/fstab
36grep swapfile /etc/fstab
37
38echo "Swap file created and activated successfully."
39