#!/bin/bash set -e fail() { echo -e "$1" >&2 exit 1 } # Prüfen, ob genügend RAM frei ist (in KB) RAM_FREE=$(grep MemAvailable /proc/meminfo | awk '{print $2}') if [ "$RAM_FREE" -lt 3000000 ]; then # 3GB als Mindestgrenze fail "Nicht genügend freier RAM!" fi # RAMFS als neues Root mounten echo "Erstelle RAM-basiertes Root-Dateisystem..." mount -t ramfs -o mode=0755 ramfs /mnt || fail "Fehler beim Mounten von ramfs" # Sicherstellen, dass notwendige Verzeichnisse existieren mkdir -p /mnt/{proc,sys,dev,run,tmp} # Komplettes Root-Dateisystem nach RAMFS kopieren echo "Kopiere System nach RAM..." cp -ax / /mnt || fail "Fehler beim Kopieren nach RAMFS" # Mountpunkte ins neue Root verschieben mount --move /proc /mnt/proc mount --move /sys /mnt/sys mount --move /dev /mnt/dev mount --move /run /mnt/run # Wechsle zum neuen Root-FS cd /mnt pivot_root . oldroot || fail "pivot_root fehlgeschlagen" # Altes Root unmounten umount -l /oldroot/proc || true umount -l /oldroot/sys || true umount -l /oldroot/dev || true umount -l /oldroot/run || true umount -l /oldroot || true # Startet das System normal weiter exec /sbin/init