mirror of
https://github.com/kevinveenbirkenbach/create-linux-swapfile.git
synced 2024-12-22 05:56:15 +01:00
Create create-linux-swap-file.sh
This commit is contained in:
parent
5f9b70ea6a
commit
2e2c4b4711
14
create-linux-swap-file.sh
Normal file
14
create-linux-swap-file.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
FSTAB_SWAP_ENTRY="/swapfile none swap defaults 0 0"
|
||||
SWAP_FILE="/swapfile"
|
||||
FSTAB_FILE="/etc/fstab"
|
||||
if grep -q "$FSTAB_SWAP_ENTRY" "$FSTAB_FILE"; then
|
||||
echo "Skipping creation of swap partion because entry allready exists in \"$FSTAB_FILE\"!"
|
||||
else
|
||||
echo "Creating swap partition..." &&
|
||||
sudo fallocate -l 16G "$SWAP_FILE" &&
|
||||
sudo chmod 600 "$SWAP_FILE" &&
|
||||
sudo mkswap "$SWAP_FILE" &&
|
||||
sudo swapon "$SWAP_FILE" &&
|
||||
sudo sh -c "echo \"$FSTAB_SWAP_ENTRY\">>\"$FSTAB_FILE\""
|
||||
fi
|
Loading…
Reference in New Issue
Block a user