mirror of
https://codeberg.org/Computertruhe/Setup-Skripte.git
synced 2025-06-28 03:16:21 +02:00
welche größe der swapfiles anhand der größe des installierten RAM bestimmt
This commit is contained in:
parent
c036739c81
commit
2ca2c13a83
1 changed files with 19 additions and 1 deletions
|
@ -1,5 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
get_total_ram_in_mb() {
|
||||
# Verwenden von /proc/meminfo, um die Gesamtgröße des RAM zu ermitteln
|
||||
total_ram_kb=$(grep MemTotal /proc/meminfo | awk '{print $2}')
|
||||
|
||||
# Umrechnung von KB in MB
|
||||
total_ram_mb=$((total_ram_kb / 1024))
|
||||
}
|
||||
|
||||
|
||||
# skript baut ein subvol /@swap unten drunter und mountet das
|
||||
# ganze als /swap um darin /swap/swapfile als swapspace
|
||||
# zu aktivieren - größe 8G oder was man sich ausdenkt
|
||||
|
@ -49,8 +58,17 @@ sudo chmod 600 /swap/swapfile
|
|||
# Disable COW for this file.
|
||||
sudo chattr +C /swap/swapfile
|
||||
|
||||
# Determine Size of Swapfile
|
||||
# if RAM is below 8GB we default to 8GB SWAP
|
||||
# if we have above 8GB we assume RAM Size for SWAP Size 1to1
|
||||
|
||||
if [total_ram_mb < 8192]; then
|
||||
swapsize=8192
|
||||
else
|
||||
swapsize=$total_ram_mb
|
||||
|
||||
# Set size of the swap file to 8G as an example.
|
||||
sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=8192
|
||||
sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=$swapsize
|
||||
|
||||
# Format the swapfile.
|
||||
sudo mkswap /swap/swapfile
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue