dphys-swapfile/FAQ0000644000175500017550000000345310542754243014274 0ustar neilneil00000000000000http://neil.franklin.ch/Projects/dphys-swapfile/FAQ author Neil Franklin, last modification 2006.12.22 copyright ETH Zuerich Physics Departement use under either modified/non-advertising BSD or GPL license Frequently* Asked Questions (FAQ) for the dphys-swapfile project * not really frequent, but that is what such files are called Q: Why are you building an swap file script? A: Because we want to get rid of the inflexibility of swap partitions Q: Why not simply make an swap file by hand? A: Because we want to dynamically resize fitting to RAM size, and also want automatic installation of our systems Q: Why not simply mount from /etc/fstab? A: Because we can not (re-)size/generate File until /var is mounted and need to do so before swapon, and at least under Debian (and most likely under many others) we can not insert our setup code in between them (both are in then same init.d script) Q: Will this work on my $DISTRIBUTION? A: The actual script should work with any Linux distribution. It auto-installs everything it needs. And can uninstall all of this, when called with "uninstall" as parameter. It has actually been tested under Debian Linux 3.0 (woody) and 3.1 (sarge) and under Slackware 9.1 and 10.0, so it seems to be totally portable Q: Why is this called dphys-swapfile ? A: Departement of PHYSics - SWAP FILE script Q: Where can I get code? A: The current (read: in edit, sometimes not functional) from: http://neil.franklin.ch/Projects/dphys-swapfile/ or: http://neil.franklin.ch/Projects/dphys-swapfile.tar.gz or Various milestones/releases (read: archives, working) from: http://neil.franklin.ch/Projects/dphys-swapfile-/ or: http://neil.franklin.ch/Projects/dphys-swapfile-.tar.gz where last milestone/release is =20061020 dphys-swapfile/INSTALL0000644000175500017550000000177410542754310014772 0ustar neilneil00000000000000http://neil.franklin.ch/Projects/dphys-swapfile/INSTALL author Neil Franklin, last modification 2006.12.22 copyright ETH Zuerich Physics Departement use under either modified/non-advertising BSD or GPL license To install/config/use dphys-swapfile do the following: Source install ============== 1. Download and unpack the .tar.gz archive file from: http://neil.franklin.ch/Projects/dphys-swapfile.tar.gz or http://neil.franklin.ch/Projects/dphys-swapfile-.tar.gz where last milestone/release is =20061020 make make install Configuration ============= 1. install this software 2. set up the config file (system wide /etc/default/dphys-swapfile or /etc/dphys-swapfile or both) if you dislike the defaults - They should be good enough for most sites 3. run the dphys-swapfile script at startup: - /sbin/dphys-swapfile setup - if you want to auto-resize when RAM changes - /sbin/dphys-swapfile swapon - allways and shutdown: - /sbin/dphys-swapfile swapoff - allways dphys-swapfile/Logfile0000644000175500017550000003723511370610335015244 0ustar neilneil00000000000000http://neil.franklin.ch/Projects/dphys-swapfile/Logfile - done, to do author Neil Franklin, last modification see last entry near bottom copyright ETH Zuerich Physics Departement use under either modified/non-advertising BSD or GPL license background is the dphys2 project, read its Logfile at: http://nic.phys.ethz.ch/projects/dphys2/Logfile and its successor, the dphys3 project, read its Logfile at: http://nic.phys.ethz.ch/projects/dphys3/Logfile as part of that wrote this tool to auto-generate/us an swapfile here only log of the events pertaining to making this tool 2003.01.09 Thu dphys2 milestone 1 is reached, make archive copy to ../dphys2-20021218 2003.04.17 Thu dphys2 milestone 2 is reached, make archive copy to ../dphys2-20030417 2003.08.04 Mon dphys2 milestone 3 is reached, make archive copy to ../dphys2-20030804 2003.08.14 Thu setup-dphys2, dbootstrap, INSTALL added option for no swap partition only make option for partition/none, for file set to none and add later so simply set ${CONF_SWAP_SIZE} to 0 or comment out its definition also avoids trouble if user gives 0 and system tries to mkswap/use it all mounting seems to be in /etc/rcS.d, check when swap need to be up before S35mountall.sh the swap file needs be be ready but also used in S10checkroot.sh, for while fsck, and that before writable 2003.08.15 Fri make package dphys-swapfile to set up and later resize existing swap file run between rcS.d 30 (fsck, /var ready) and 35 (mount, uses swapfile) making 1G takes 25s and mkswap 5s, so not every time, just when resize compute new size, compare with old, if diff remove and make new if config file do that size, else 2*RAM, usually about 1G looking at host berlin, only 1.9G free from 10G disk, is 1.8G apt cache add an apt-get clean to dphys-admin, as unlikely to reinstall, have LAN decided to auto-select 2*RAM, unless user config /etc/default/dpyhs-swapfile also limit to max 2G kernel limit script is an init.d, will start on reboot, also run once on pkg install added --purge to drop swapfile from fstab, swapoff, rm packaged version 20030815.175513-1, changelog: "auto-generated release from versionless (=current) upstream" 2003.10.03 Fri convert existing binary packages to using makesourcepackage dsbg leave old hosts arizona,bludger,dudley (will be deleted later) do as last with him site (he is actively working on it) every package that is converted and on server, remove from CVS do all other dphys-build/*/DEBIAN: admin, host-hagrid, ide-dma, reboot, site-franklin-experimental, swapfile, user-info 2003.10.31 Fri setup-dphys2 default swap off (for using use dphys-swap or similar) dphys2-swap worked over dphys-swap, /etc/rcS.d script S32 is too early, /var may not be mounted (only in S35), use S37 S37 after swapon in S35, so need own swapo[n|ff], no line in fstab, comment 2003.11.06 Thu further with converting dphys-swap to dphys2-swap, make upstream Makefile move over existing changelog (uncompressed and renamed) to start new one move over existing conffiles, fix packagename in /e/i.d/ extend makesourcepackage to insert conffiles into package also more than just README upstream doc, improve commenting dh_* sections also to conffiles and postinst|prerm add also preinst and postrm also install init.d script from debian/init.d, not in upstream Makefile postinst angepasst, kein swapon, da init.d start das schon macht prerm macht eh nix, standard nehmen postrm muss nicht mehr benutztes swapfile loeschen kann nicht /e/i.d/d2-s purge benutzen weil das bereits geloescht ist 2003.11.07 Fri dphys2-swap init.d makesourcepackage to modify/generate postinst and postrm makesourcepackage rules file call to execute this section dphys2-swap upload to package server, apt-get update and install, OK stop and start, OK, remove and install, OK, purge and install, OK packaged version 20031107.173603-1, changelog: "ported to makesourcepackage, fixed runlevel" 2003.11.13 Thu deleted old dphys-swapfile package from server, only in use on my home machines index.html rename dphys-swap to dphys2-swap and link .tar|.dsc|.tar.gz files doku remarks that PXE net boot is possible (user failled to notice it) added remark that makepackage is deprecated, use makesourcepackage dphys2 root disk option to autoinstall dphys2-swap package setup-dphys2 option, makeroot copy into root image dbootstrap copy into target system and install base-config script dropped use of SWAP_TYPE variable, directly use CONF_SWAP_SIZE base-config script install package using dpkg --install for this endfirstrun SYS_BASECONF_DIR in setup-dphys2, for dbootstrap also same with DEBUG_LEAVE_SCRIPTS, renamed to DEBUG_LEAVE_BC_SCRIPTS enfirstrun eliminate last CONF_* variable, direct in code, simpler 2003.11.14 Fri dphys2 autoinstall dphys2-swap package finished additions 2003.11.20 Thu dphys2-swapfile fixed init.d script bug, missing output redirect to /dev/null dphys2-swapfile added an example config file in /etc/default/dphys2-swapfile extended makesourcepackage to install such an config if existant testing noticed init.d start when already running gives swapon error same on init.d stop if not still running, or on deconfig, correct this changes to use variable names CONF_SWAPFILE and CONF_SWAPSIZE CVS deleted old dphys-swapfile stuff, package also gone, and no use any more setup-dphys2 option dphys2-swapfile tidy up code in dbootstrap put entire part that works in /target in subshell ( chroot /target ... ) packaged version 20031120.124554-1, changelog: "fixed init.d start output redirect bug" packaged version 20031120.135304-1, changelog: "added /etc/default example config file" packaged version 20031120.142404-1, changelog: "fixed init.d dual start|stop swapon|off error message" 2003.11.27 Thu dphys2-swapfile still messes up output, with "Adding Swap: ... (priority -1)" between the keeping it and , done. outputs from init.d script test swapoff/swapon has no such output, but it appears on the console is kernel -> klogd -> syslogd which is doing this, no option, leave it 2003.12.04 Thu swapfile syslog output cannot be prevented, so finish our line before syslog packaged version 20031204.141601-1, changelog: "no makesourcepackage stuff in init.d, separate script" 2004.02.19 Thu dphys2 release 4th milestone, copy to ../dphys2-20040219, make tar file of it 2004.05.14 Fri convert dphys2-swapfile to new dh_* based makesourcepackage updated Makefile preset variables, debian/control added Build debhelper rm debian/conffiles (was auto-generated anyway) mv default dphys2-swapfile.default, changed it to normal hand edited, not gen mv init.d dphys2-swapfile.init, removed automatic modifications, hand edited rm debian/postinst (will be generated), prerm (same) postrm changed to include #DEBHELPER#, and only mod fstab and del swapfile CONF_SWAPFILE as variable, even if set only here, not by /etc/default/* renamed to debian/.postrm, man dh_installdb incomprehensible generated new style debian/rules file, so ready to package 2004.05.27 Thu dphys2-swapfile heeb file should not be 644, can have root processes in it added an chmod 600 to start), while at it uninstall) in init.d script init.d script, default, postrm comments updated, made package and uploaded it packaged version 20040527.143106-1, changelog: "change to using dh_* based source package" 2004.05.28 Fri dphys2-swapfile separate project, as only replacing swappartit, not installing rename it into dphys-swapfile, no 2 as not part of dphys2 any more made FAQ, INSTALL, (this) Logfile, Makefile add tar stuff, new own README debian dir, rename files and names in them index.html.en, linked from projects and startup page make tar, generating standard .tar.gz file packaged, (re-)generating .dsc, debianised .tar.gz and .deb files no new makesourcepackage -l yet, as release most likely next week index.html.en link to also to the package stuff, still old number dito also in FAQ and INSTALL remarks which is newest package version 2004.06.03 Thu renaming makes this package replace old name package heeb policy discussion, no Conflicts:/Provides:/Replaces: in control simply - dphys2-swapfile + dphys-swapfile in main-pkglist worst case if no swapoff possible 2nd nameless swap remains until reboot init script added full paths to all programs, so path/pwd independant split init script, most in main dir (/sbin/), only call in debian (/etc/init.d) updated Makefile to package it, and index.html.en to show this also Makefile code to install it, independant from Debian part delete swapfile moved from postrm to prerm, when script and config still exists so it can use /sbin script (with uninstall), and config stuff used by that user who removes and reinstalls package will have to regenerate swapfile config as such is not lost, and that is then auto-deleted when purge 2004.06.04 Fri wrote man page for /sbin Script, added to Makefile in swapon and uninstall added test for file, in swapon error if not present improved docs with better description of reason for own swapon/off added makesourcepackage -l with descriptions, change all references CVS remove dphys-admin, commit, update, this time it really is gone packaged version 20040604.142815-1, changelog: "separate project, renamed, separate action/init, delete in prerm" 2004.06.11 Fri bug in config file reading, fixed packaged version 20040611.145856-1, changelog: "fixed config file reading bug" 2004.07.21 Wed index.html.en added man page 2004.07.29 Thu improved docs, INSTALL show what steps need to be done, i.e. are important created debian/dphys-swapfile.docs, with README, FAQ, index.html.en release 5th milestone, copy to ../dphys-swapfile-20040729, make tar file of it modifed index.html and FAQ and INSTALL to show the milestone release redo ../dphys-swapfile.tar.gz tar archive of current state packaged version 20040729.164251-1, changelog: "added docs, new upstream milestone" 2004.08.27 Fri man pages expand explanation, added examples of use section showing typical usage, including an minimal example init.d script change copyright remarks to mention modified/non-advertising BSD packaged version 20040827.135743-1, changelog: "expanded man page" 2005.04.21 Thu checked up that this package has no woody dependencies, will run under sarge not really surprising, as it also runs OK on my personal slackware systems as no needed changes, leave the slight problem with /etc/default unchanged imported this package into local sarge package server 2006.08.11 Fri added all "packaged version ????????.??????-?, changelog:" lines 2006.09.15 Fri get ready for publication as an official Debian Linux ?.? (etch) package all actions here analog to everything done in dphys-config reworked and updated documentation, FAQ, INSTALL, README, index.html.en senguen wanst to make own debian/* as lintian complains about native package looked into any information lost if deleting debian/* to avoid collision debian/changelog is all info duplicated in this Logfile, deleted it debian/control is just docu text, add to other docs, README and index.html.en debian/copyright is nearly same as in README, updated that debian/dphys-swapfile.default moved to dphys-swapfile.example changed code and man page to reflect no /etc/default/* any more will also install into /usr/share/doc/examples and not /etc/default was already on "todo" since 2005.04.21 entry up above debian/dphys-swapfile.docs is nothing, deleted it debian/dphys-swapfile.init is simple example, move to main dir add to Makefile installation into examples directory debian/dphys-swapfile.prerm notified senguen what he needs to do, deleted it debian/rules has nothing specific, deleted it as only producing an "upstream" and senguen doing "maintainer" version remove FAQ and INSTALL and index.html.en references to my old packages bug source check possibility of cut -f 2- or similar where no delimitors bug source check echo "${blah}" against possible * or similar ${blah} data better bug discovery addition set -e changed code to read in config file only once, no after computation overwrite released 6th (and 2nd feature completed, just repackaged and fixes) milestone modified index.html and FAQ and INSTALL to show the milestone release no Debian packaging any more, senguen does this now, no changelog entry copy to ../dphys-swapfile-20060915, made tar file of that remade ../dphys-swapfile.tar.gz archive for current state 2006.10.13 Fri do all changes done since then to dphys-config, get up to same code standard PATH= revised, removed absolute paths in commands no /usr/local stuff, as no FreeBSD port intended, too Linux specific Makefile dphys-swapfile init.d.example check possibly problematic code features echo -e replaced by normal echo, no \? in it anyway no ./ config script called, cut -f only 1 harmless one "" quoting updated in dphys-swapfile init.d.example no ~ used anywhere, as is not user software no shell functions, so no keyword function to remove remade ../dphys-swapfile.tar.gz archive 2006.10.20 Fri analog to dphys-config also run automatic quoting check added all missing, even in places where it can never fail, so check quiet remade ../dphys-swapfile.tar.gz archive after all bugfixes and changes new release updated FAQ, INSTALL, README, index.html.en copy to ../dphys-swapfile-20061020, made tar file of that remade ../dphys-swapfile.tar.gz archive for current state 2006.12.22 Fri as part of taking this over als personal project, after leaving job moved everything from www.phys.ethz.ch/~franklin to neil.franklin.ch website changes all URLs to refer to new home, expanded links to other projects we decided that I will keep on maintaining this project (and dphys-config) as I also use these 2 projects at home on my own non-Debian systems 2010.05.04 Wed bugfixes for reported bug by the new Debian maintainer Axel Beckert this was not prevented because of the old maintainers unreported patch which apparently was changed to have no 2048M limit any more request to make SWAPFACTOR and MAXSWAP into user CONF_* variables and user switchable fixed size CONF_SWAPSIZE or above computed size newer 2.6.32 AMD64 kernels report senselessly large 128T /proc/kcore sizes dphys-swapfile tries to genrate 2*kcore File, fills /var or / Partition also noticed 2 spelling mistakes in comments and man page 2010.05.05 Thu renamed SWAPFACTOR and MAXSWAP to CONF_*, modified/improved comments there while at it also allow CONF_MAXSWAP to be undefined, for limitless this is apparently what the old maintainer wanted to achieve updated man page with the new CONF_* stuff, and improved descriptions updated dphys-swapfile.example for /etc/dphys-swapfile to fit program CONF_* change now kernelupgrade-broken old size estimation, use /proc/meminfo fix a few typos, overwride -> override (or was that intended as overwrite?) dphys-config uses override, so use that here also for consistency allready -> already, overwriding -> overriding, man neccessary -> necessary also a bit of general code tidy up, newer structures from dphys-config remade ../dphys-swapfile.tar.gz archive for current state mail to Axel Beckert for his packaging and site testing mail answer from Axel Beckert about only integral swap factor problem switch to using dc instead of expr, as in all my other private scripts allows CONF_SWAPFACTOR to also hab non integral values, such as 1.5 report that Debian kFreeBSD predictably fails, on swapon -s while investigation noticed /etc/fstab comment no linebreaks, fixed it ------ project status doing: todo: possible extensions: dphys-swapfile/Makefile0000644000175500017550000000361610542756615015410 0ustar neilneil00000000000000# http://neil.franklin.ch/Projects/dphys-swapfile/Makefile # author Franklin, last modification 2006.12.22 # This Makefile is copyright ETH Zuerich Physics Departement # use under either modified/non-advertising BSD or GPL license # --- various site dependant user config variables # for creating an [-].tar.gz archive DIR = dphys-swapfile # --- no user configurable stuff below here # /usr/local added for Slackware, because self installed stuff ends up in there PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin PREFIX = $(DESTDIR)/usr BINDIR = $(PREFIX)/bin SBINDIR = $(PREFIX)/sbin MAN1DIR = $(PREFIX)/share/man/man1 MAN8DIR = $(PREFIX)/share/man/man8 DOCDIR = $(PREFIX)/share/doc/dphys-swapfile EXADIR = $(DOCDIR)/examples # use R_PREFIX (root prefix) as not in /usr, this is early run start up stuff R_PREFIX = $(DESTDIR) R_SBINDIR = $(R_PREFIX)/sbin # --- code for acting out the various make targets all: @gzip -9 -c dphys-swapfile.8 > dphys-swapfile.8.gz clean: @rm -f dphys-swapfile.8.gz distclean: clean install: @mkdir -p $(R_SBINDIR) @cp -p dphys-swapfile $(R_SBINDIR) @mkdir -p $(MAN8DIR) @cp -p dphys-swapfile.8.gz $(MAN8DIR) @mkdir -p $(EXADIR) @cp -p dphys-swapfile.example $(EXADIR) @cp -p init.d.example $(EXADIR) uninstall: @rm -f $(EXADIR)/init.d.example @rm -f $(EXADIR)/dphys-config.example @rmdir $(EXADIR) @rm -f $(MAN8DIR)/dphys-swapfile.8.gz @rm -f $(R_SBINDIR)/dphys-swapfile # --- project management stuff .PHONY: tar tar: @# package this project into an .tar.gz for one nice download @echo packaging source and doc files into an .tar.gz ... @(cd ..; tar zcf $(DIR).tar.gz \ $(DIR)/FAQ $(DIR)/INSTALL $(DIR)/Logfile $(DIR)/Makefile \ $(DIR)/README $(DIR)/dphys-swapfile $(DIR)/dphys-swapfile.8 \ $(DIR)/dphys-swapfile.example $(DIR)/index.html.de \ $(DIR)/index.html.en $(DIR)/init.d.example ) dphys-swapfile/README0000644000175500017550000000265010542755170014620 0ustar neilneil00000000000000http://neil.franklin.ch/Projects/dphys-swapfile/README author Neil Franklin, last modification 2006.12.22 This text (and all dphys-swapfile) copyright ETH Zuerich Physics Departement use under either modified/non-advertising BSD or GPL license Introduction to dphys-swapfile setup/mount script Aim This program is aimed at using an automatically installed and RAM size dependantly (re-)sized swap file instead of an fixed size (from partitioning) swap partition. Install the system without an swap partition and then install and run this. Preconditions This program should work on any Linux system. It is unlikely to be portable to any non-Linux without lots of work (near rewrite). Tools This project has produced an script for (re-)creating an swap file on every boot, and then mounting it, also unmounting it on shutdown, and offering removal of the swap file when not needed any longer. Code This project is fully open source. Documentation gets written together with the code. Everything I write is immediately available for download. Current version is what I am working on, if I write a bug you crash the next day. Older stable versions are archived as Milestones. State Working package, in productive use on over 100 machines. Installation There is a installation guide at: http://neil.franklin.ch/Projects/dphys-swapfile/INSTALL Questions There is a FAQ file at: http://neil.franklin.ch/Projects/dphys-swapfile/FAQ dphys-swapfile/dphys-swapfile0000755000175500017550000001522711370610012016612 0ustar neilneil00000000000000#! /bin/sh # /sbin/dphys-swapfile - automatically set up an swapfile # author Neil Franklin, last modification 2010.05.05 # This script is copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license # this script is intended to be run as root user, usually while booting ### ------ configuration for this site # --- CONF_* various site dependant user config variables # where we want the swapfile to be, this is the default CONF_SWAPFILE=/var/swap # set size to absolute value, leaving empty (default) then uses computed value # you most likely don't want this, unless you have an special disk situation CONF_SWAPSIZE= # set size to computed value, this times RAM size, dynamically adapts, # guarantees that there is enough swap without wasting disk space on excess CONF_SWAPFACTOR=2 # restrict size (computed and absolute!) to maximally this limit # can be set to empty for no limit, but beware of filled partitions! # this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it # but is also sensible on 64bit to prevent filling /var or even / partition CONF_MAXSWAP=2048 ### ------ actual implementation from here on # no user settings any more below this point set -e # sanitise this place, else some commands may fail PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH # what we are NAME=dphys-swapfile PNAME=dphys-swapfile # check user config file, let user override settings # swap file place/filename and size if [ -f /etc/"${PNAME}" ] ; then . /etc/"${PNAME}" fi case "$1" in setup) # (re-)size/-generate, fast if no memory size change if [ "${CONF_SWAPSIZE}" = "" ] ; then # no absolute size given, so automatically compute optimal size echo -n "computing size, " # this seems to be the nearest to physical RAM size, lacks about 60k # but it actually then fails from AMD64 kernel 2.6.32 onwards #KCORESIZE="`ls -l /proc/kcore | awk '{ print $5 }'`" ## make MBytes which rounded down will be exactly 1 too few, so add 1 #MEMSIZE="`echo "${KCORESIZE} 1048576 / 1 + p q" | dc`" # so second attempt at finding out physical RAM size, lacks about 10M # see how long this variant stays usable :-) MEMTOTAL="`grep '^MemTotal:' /proc/meminfo | awk '{ print $2 }'`" # make MBytes which rounded down will be about 10 too few, so add 10 MEMSIZE="`echo "${MEMTOTAL} 1024 / 10 + p q" | dc`" # compute desired swap size, as factor * RAM CONF_SWAPSIZE="`echo "${MEMSIZE} ${CONF_SWAPFACTOR} * p q" | dc`" # remove any fractional MBytes CONF_SWAPSIZE="`echo "${CONF_SWAPSIZE}" | cut -f 1 -d '.'`" fi # announce end resulting config echo -n "want ${CONF_SWAPFILE}=${CONF_SWAPSIZE}MByte" if [ "${CONF_MAXSWAP}" != "" ] ; then # check for swap size limit and restrict to it if [ "${CONF_SWAPSIZE}" -gt "${CONF_MAXSWAP}" ] ; then echo -n ", restricting to config limit: ${CONF_MAXSWAP}MBytes" CONF_SWAPSIZE="${CONF_MAXSWAP}" fi fi # we will be later starting, and in between possible deleting/rebuilding # so deactivate any already running swapfile, to avoid errors "$0" swapoff # compare existing swapfile (if one exists) to see if it needs replacing if [ -f "${CONF_SWAPFILE}" ] ; then echo -n ", checking existing" # we need bytes for comparing with existing swap file SWAPBYTES="`echo "${CONF_SWAPSIZE} 1048576 * p q" | dc`" FILEBYTES="`ls -l "${CONF_SWAPFILE}" | awk '{ print $5 }'`" # wrong size, get rid of existing swapfile, after remake if [ "${FILEBYTES}" != "${SWAPBYTES}" ] ; then echo -n ": deleting wrong size file (${FILEBYTES})" # deactivate and delete existing file, before remaking for new size "$0" uninstall else echo -n ": keeping it" fi fi # if no swapfile (or possibly old one got deleted) make one if [ ! -f "${CONF_SWAPFILE}" ] ; then echo -n ", generating swapfile ..." # first deleting existing mount lines, if any there (same code as above) grep -v "^${CONF_SWAPFILE}" /etc/fstab > /etc/.fstab mv /etc/.fstab /etc/fstab dd if=/dev/zero of="${CONF_SWAPFILE}" bs=1048576 \ count="${CONF_SWAPSIZE}" 2> /dev/null mkswap "${CONF_SWAPFILE}" > /dev/null # ensure that only root can read possibly critical stuff going in here chmod 600 "${CONF_SWAPFILE}" # do not mount swapfile via fstab, because swapfile may only # be created after partitions are all mounted, not here yet # so just add warning comment line that swapfile is not in fstab # and because of this will get mounted by this script # get rid of possibly already existing comment about # swapfile mounted by this script, to avoid duplicate comments grep -v "a swapfile is not" /etc/fstab > /etc/.fstab grep -v "${NAME}" /etc/.fstab > /etc/fstab # add new comment about this echo "# a swapfile is not a swap partition, no line here" >> /etc/fstab echo "# use ${NAME} swap[on|off] for that" >> /etc/fstab # and inform the user what we did echo -n " of ${CONF_SWAPSIZE}MBytes" fi echo ;; install) # synonym for setup, in case someone types this "$0" setup ;; swapon) # as there can be no swapon in /etc/fstab, do it from here # this is due to no possible insertion of code (at least in Debian) # between mounting of /var (where swap file most likely resides) # and executing swapon, where the file already needs to be existing if [ -f "${CONF_SWAPFILE}" ] ; then swapon "${CONF_SWAPFILE}" 2>&1 > /dev/null else echo "$0: ERROR: swap file ${CONF_SWAPFILE} missing!" \ "you need to first run $0 setup to generate one" fi ;; swapoff) # as there can also be no swapoff in /etc/fstab, do it from here # first test if swap is even active, else error from swapoff if [ "`swapon -s | grep "${CONF_SWAPFILE}" | \ cut -f 1 -d ' '`" != "" ] ; then swapoff "${CONF_SWAPFILE}" 2>&1 > /dev/null fi ;; uninstall) # note: there is no install), as setup) can run from any blank system # it auto-installs as side effect of recomputing and checking size # deactivate before deleting "$0" swapoff if [ -f "${CONF_SWAPFILE}" ] ; then # reclaim the file space rm "${CONF_SWAPFILE}" fi # and get rid of now superfluous comment about swapfile mounting grep -v "a swapfile is not" /etc/fstab > /etc/.fstab grep -v "${NAME}" /etc/.fstab > /etc/fstab ;; *) echo "Usage: $0 {setup|swapon|swapoff|uninstall}" exit 1 ;; esac exit 0 dphys-swapfile/dphys-swapfile.80000644000175500017550000000744311370605046016771 0ustar neilneil00000000000000.\" /usr/share/man/man8/dphys-swapfile.8(.gz) .\" author Neil Franklin, last modification 2010.05.05 .\" copyright ETH Zuerich Physics Departement .\" use under either modified/non-advertising BSD or GPL license .TH DPHYS-SWAPFILE 8 "2010.05.05" "D-PHYS Swapfile Tools" .SH NAME dphys-swapfile \- set up, mount/unmount, and delete an swap file .SH SYNOPSIS .B dphys-swapfile \fBsetup\fP|\fBinstall\fP|\fBswapon\fP|\fBswapoff\fP|\fBuninstall\fP .SH DESCRIPTION dphys-swapfile computes the size for an optimal swap file (and resizes an existing swap file if necessary), mounts an swap file, unmounts it, and deletes it it is not wanted any more. .SH OPTIONS There is only one parameter, an command, which can be either of these: .TP .B setup and .B install Both tell dphys-swapfile to compute the optimal swap file size and (re-)generate an fitting swap file. Default it 2 times RAM size. This can be called at boot time, so the file allways stays the right size for current RAM, or run by hand whenever RAM size has changed. .TP .B swapon and .B swapoff These run the \fIswapon \fPand \fIswapoff\fP commands on the swapfile. Note that direct swapon/off from \fI/etc/fstab\fP is not possible, as that is (at least on Debian) done in the same script that mounts /var (which is where the swap file most likely resides). And we need to do our setup between those actions. So we pass up on \fI/etc/fstab\fP, and do our own swapon/off here. .TP .B uninstall Gets rid of an unwanted swap file, reclaiming its disk space. .SH CONFIG The config file \fI/etc/dphys-swapfile\fP allows the user to set up the working environment for dphys-swapfile. .PP This config file is a sh script fragment full of assignments, which is sourced. Standard sh syntax rules apply. Assignments are: .TP .B CONF_SWAPFILE Set where the swap file should be placed. Defaults to /var/swap. It is unlikely that you will need to change this, unless you have very strange partitioning, and then you will most likely be using an swap partition anyway. .TP .B CONF_SWAPSIZE Set size to this absolute value, in MBytes. Leaving this empty (which is the Default) uses an computed value as size instead. This is unlikely to ever be needed, unless in some strange diskspace situations. Note, that swap enabled and size smaller than RAM may causes kernal-internal VM troubles on some kernels/systems. .TP .B CONF_SWAPFACTOR Set size to computed value. Uses this value times RAM size. It so dynamically adapts to RAM size, guarantees enough swap on large RAM, without going into excess diskspace on small RAM (and disk?) systems. Defaults to 2, which gives swap size = 2 * RAM size. .TP .B CONF_MAXSWAP Set size restriction of maximal computed and absolute(!) values, in MBytes. Defaults to 2048 which was a former 32bit kernel limit for the swapfile size and is now a limit to prevent unusually and senselessly big swap files on systems with a lot of RAM. .SH FILES .TP .B /etc/dphys-swapfile user config .TP .B $CONF_SWAPFILE the swap file, target of the whole action (defaults to \fI/var/swap\fP) .SH EXAMPLES dphys-swapfile is usually run at system startup and shutdown from an /etc/init.d (or /etc/rc.d) script, such as this (minimal) one: .PP .nf #!/bin/sh\! # /etc/init.d/dphys-swapfile \- automatically set up an swapfile\! # author franklin, last modification 2004.06.04\! # This script is copyright ETH Zuerich Physics Departement,\! # use under either modified/non-advertising BSD or GPL license\! case "$1" in\! start)\! /sbin/dphys-swapfile setup\! /sbin/dphys-swapfile swapon\! ;;\! stop)\! /sbin/dphys-swapfile swapoff\! ;;\! esac\! exit 0\! .fi .PP If an sysadmin wants to have the swapfile in another place, say /var/run/swap, he can use: .PP In \fI/etc/dphys-swapfile\fP: .PP CONF_SWAPFILE=/var/run/swap .SH AUTHOR neil@franklin.ch, http://neil.franklin.ch/ dphys-swapfile/dphys-swapfile.example0000644000175500017550000000211211370605002020231 0ustar neilneil00000000000000# /etc/dphys-swapfile - user settings for dphys-swapfile package # author Neil Franklin, last modification 2010.05.05 # copyright ETH Zuerich Physics Departement # use under either modified/non-advertising BSD or GPL license # this file is sourced with . so full normal sh syntax applies # the default settings are added as commented out CONF_*=* lines # where we want the swapfile to be, this is the default #CONF_SWAPFILE=/var/swap # set size to absolute value, leaving empty (default) then uses computed value # you most likely don't want this, unless you have an special disk situation #CONF_SWAPSIZE= # set size to computed value, this times RAM size, dynamically adapts, # guarantees that there is enough swap without wasting disk space on excess #CONF_SWAPFACTOR=2 # restrict size (computed and absolute!) to maximally this limit # can be set to empty for no limit, but beware of filled partitions! # this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it # but is also sensible on 64bit to prevent filling /var or even / partition #CONF_MAXSWAP=2048 dphys-swapfile/index.html.de0000777000175500017550000000000010542075617020715 2index.html.enustar neilneil00000000000000dphys-swapfile/index.html.en0000644000175500017550000001730610542764737016353 0ustar neilneil00000000000000 dphys-swapfile Auto-setup/-activation System Home | Projects | dphys-swapfile

dphys-swapfile Auto-setup/-activation System

Project Basics
Project Status
Code Download
External Stuff (Links)

Project Basics

This project is aimed at using an swap file on our Linux systems. We want to be able to generate an RAM size dependant swap file in /var, instead of using an fixed sized swap partition. And automatically regenerate the swap file if RAM size changes, to fit the new size.

This project has produced an dphys-swapfile script for sizing, setting up and mounting an swap file. And an init.d script that runs this script at boot and shutdown time.

This project was spawned from the dphys2 project (later replaced and made obsolete by the dphys3 project).

Project Status

For the full details of done/doing/todo of the project best read the Logfile. A short excerpt from it is here:

Done are:

Milestone/Release 4 (2004.02.19):
  • This was still as part of dphys2. Made dphys-swapfile script to automatically generate/resize and activate an swapfile, default 2*RAM size, and also deactivate and delete it at the approriate times
Milestone/Release 5 (2004.07.29):
  • Split out of dphys2 into an separate project, as this tool is also usefull without dphys2, on any Linux system
  • Reworked as separate /sbin and /etc/init.d scripts
Milestone/Release 6 (2006.09.15):
  • Repackaged as separate non-debianised upstream for later debianisation by separate maintainer
  • Slight code and documentation improvements
Milestone/Release 7 (2006.10.20):
  • Code and docs tidy up, extensive quoting improvements, no absolut paths in commands
Current (= development, = may be broken):
  • Nothing done

Todo are:

  • Nothing planned

Code Download

Current (= development, = may be broken): Milestone/Release 7 (2006.10.20):
  • Installation Guide
  • entire project: dphys-swapfile-20061020.tar.gz
  • single files:
  • Milestone/Release 6 (2006.09.15):
  • Installation Guide
  • entire project: dphys-swapfile-20060915.tar.gz
  • single files:
  • Milestone/Release 5 (2004.07.29): Milestone/Release 4 (2004.02.19) was done as part of: dphys2. Milestones/Releases 1-3 of dphys2 predate dphys-swapfile.

    External Stuff (Links)

    Various links that may be usefull:
    Home | Projects | dphys-swapfile

    This page is by Neil Franklin, last modification 2006.12.22 dphys-swapfile/init.d.example0000755000175500017550000000323510542755753016514 0ustar neilneil00000000000000#!/bin/sh # /etc/init.d/dphys-swapfile - automatically set up an swapfile # author Neil Franklin, last modification 2006.12.22 # This script is copyright ETH Zuerich Physics Departement, # use under either modified/non-advertising BSD or GPL license # this init.d script is intended to be run from rcS.d # must run after mount of /var which may only happen in S35mountall.sh # for this reason we can not build swapfile until after S35mountall.sh # so we also need to use init.d start|stop to swapon|off our file # and sensibly before the lots of stuff which may happen in S40networking # and may want to use a lot of memory, and so requires swap to be running # so we run it as rcS.d/S37dphys-config # get ready to work # /usr/local added for Slackware, because self installed stuff ends up in there PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin export PATH # what we are NAME=dphys-swapfile PNAME=dphys-swapfile case "$1" in start) echo "Starting ${NAME} swapfile setup ..." # (re-)size/-generate (and also first time install) # this will produce output, so no -n in above echo dphys-swapfile setup # as S35mountall.sh has already run, do this from here # as there can be no swapon in /etc/fstab dphys-swapfile swapon echo "done." ;; stop) echo -n "Stopping ${NAME} swapfile setup ..." # as no swapon or swapoff in /etc/fstab, do this from here dphys-swapfile swapoff echo ", done." ;; restart|reset|reload|force-reload) echo "No daemon to (force-)re[start|set|load] in ${NAME}" ;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac exit 0