====== Swap-Datei ====== ===== Swap-Datei auf lokaler Platte betreiben ===== > dd if=/dev/zero of=/usr/swap0 bs=1024k count=1024 > chmod 0600 /usr/swap0 > mkswap -L swap0 /usr/swap0 > echo "/usr/swap0 none swap sw 0 0" >> /etc/fstab > swapon /usr/swap0 > free -m gesamt belegt frei gemeinsam Zwischen verfügbar Speicher: 32044 3285 20928 219 7830 28087 Auslager: 1023 0 1023 ===== Swap-Datei für USB-Stick-System auf lokaler Platte ===== #!/bin/bash # # Dieses Skript ist NUR für bootfähige Linux-USB-Sticks geschrieben worden. # # Das Ziel dieses Skriptes ist es, # für ein Linux, welches von einem USB-Stick gebootet ist, # eine nutzbare Swap-Datei bereitzustellen. # # Es ermittelt alle fest verbauten Festplatten, # mountet sie "ro" nacheinander und ermittelt wieviel freier Platz auf der # Partition vorhanden ist. # anschließend wird bewertet ob der freie Platz ausreicht. # # Sollte eine Partition nur per FUSE gemountet werden können, # dann wird automatisch die Swap-Aktivität des Systems auf "1" (Minimum) # reduziert. # # Bei mehreren nutzbaren Partitionen, wir die "beste" ausgewählt. # #set -x VERSION="v2013092200" SWAPMEHR="512" # extra-Swap in MB, der bei Suspend mehr als RAM gebraucht wird SWAPOPTI="$(free | awk -v swapmin=${SWAPMEHR} '/^Mem:/{printf("%.1u\n",(($2/102400)*101)+swapmin)}')" SWAPDATEN="$(for i in $(fgrep 0 /sys/class/block/*/removable | egrep -v '/loop|ram|dm-/' | awk '{gsub("/"," ");gsub(":"," ");print $4}') do blkid /dev/${i}[0-9]* done|while read HDD IDS do umount -f /mnt 2>/dev/null mount -o ro $(echo "${HDD}"|sed 's/[:]//') /mnt PARTINFOS="$(df -lTP -BM /mnt 2>/dev/null | egrep '[ ]+[\/]mnt$')" umount -f /mnt #echo "'${PARTINFOS}'" PARTITION="$(echo "${PARTINFOS}" | awk '{print $1}')" DATEISYST="$(echo "${PARTINFOS}" | awk '{print $2}')" FREIPLATZ="$(echo "${PARTINFOS}" | awk '{gsub("M[ ]"," ");print $5}')" if [ -n "${FREIPLATZ}" ] ; then ### größe beurteilen # ist er groß genug für Suspend ? if [ "${FREIPLATZ}" -gt "${SWAPOPTI}" ] ; then SWAPPINESS=60 SWAPGR="${SWAPOPTI}" else ### swappiness muss skaliert werden # ist er größer als minimum ? if [ "${FREIPLATZ}" -gt "${SWAPMEHR}" ] ; then # ist er größer als minimum SWAPID=$(echo "512 8469 ${FREIPLATZ}" | awk '{ram=$2-$1;printf("%.0u\n",$3*(1/(ram/59)))}') SWAPPINESS=$(if [ "${SWAPID}" -gt 2 ] ; then echo "${SWAPID} 2"|awk '{print $1 - $2}';else echo 0;fi) SWAPGR="$(echo "${FREIPLATZ}" | awk '{print $1-10}')" else # ist er kleiner als minimum SWAPPINESS=0 fi fi ### bei FUSE den SWAP minimieren TYPFUSE="$(echo "${DATEISYST}" | fgrep -i fuse)" if [ -n "${TYPFUSE}" ] ; then SWAPPINESS=1 fi else # keine beschreibbare Platte mit Platz gefunden SWAPPINESS=0 fi ### nur ausgeben, wenn neuer vm.swappiness > 0 if [ "${SWAPPINESS}" -gt 0 ] ; then echo "${SWAPPINESS} ${PARTITION} ${SWAPGR}" fi done | sort -nr | head -n1)" SWAPPINESS="$(echo "${SWAPDATEN}" | awk '{print $1}')" PARTITION="$(echo "${SWAPDATEN}" | awk '{print $2}')" SWAPGR="$(echo "${SWAPDATEN}" | awk '{print $3}')" #echo " mkdir -p /SWAP mount ${PARTITION} /SWAP dd if=/dev/zero of=/SWAP/LinuxSwap.img bs=1M count=${SWAPGR} mkswap -L swap /SWAP/LinuxSwap.img swapon /SWAP/LinuxSwap.img sysctl vm.swappiness=${SWAPPINESS} #"