Update swap configuration
This commit is contained in:
parent
717af2c45e
commit
d7eaa318fa
11
init_priv.sh
11
init_priv.sh
@ -212,20 +212,23 @@ configure_oomkiller() {
|
||||
}
|
||||
|
||||
configure_swap() {
|
||||
# Input the swap size
|
||||
read -p "Swap size (MB): " swap_size
|
||||
# Create a virtual memory file
|
||||
sudo dd if=/dev/zero of=/mnt/swap bs=1M count=4096
|
||||
sudo dd if=/dev/zero of=/mnt/swap bs=1M count=$swap_size
|
||||
sudo chmod 0600 /mnt/swap
|
||||
sudo mkswap /mnt/swap
|
||||
sudo swapon /mnt/swap
|
||||
# Write auto mount parameters
|
||||
if ! grep -q swap /etc/fstab; then
|
||||
echo "/mnt/swap swap swap defaults 0 0" >> /etc/fstab
|
||||
echo "/mnt/swap swap swap defaults 0 0" | sudo tee -a /etc/fstab >/dev/null
|
||||
fi
|
||||
# Set virtual memory usage
|
||||
if ! grep -q swappiness /etc/sysctl.conf; then
|
||||
echo "vm.swappiness = 10" >> /etc/sysctl.conf
|
||||
echo "vm.swappiness = 10" | sudo tee -a /etc/sysctl.conf >/dev/null
|
||||
else
|
||||
sed -i 's/vm.swappiness = 0/vm.swappiness = 10/' /etc/sysctl.conf
|
||||
# sed -i 's/vm.swappiness = 0/vm.swappiness = 10/' /etc/sysctl.conf
|
||||
sudo sed -i 's/^vm.swappiness.*/vm.swappiness = 10/' /etc/sysctl.conf
|
||||
fi
|
||||
# Make the configuration take effect
|
||||
sysctl -p
|
||||
|
||||
Loading…
Reference in New Issue
Block a user