• Zur Hauptnavigation springen
  • Skip to main content
  • Zur Fußzeile springen

Sebastian Mogilowski's Blog

Just another blog about administration, linux and other stuff

  • Home
  • Contact
  • Imprint
  • Projects & HOWTOs
  • Publications

Add swap file to a linux server (Debian or Ubuntu)

20. August 2009 by sebastian 2 Kommentare

This article describes how you can add a swap file on Debian or Ubuntu. You can use this to add additional swap space or to add swap to a server without any swap space. (You can use this as temporary swap space, too)

1. Create the swap file:

Use „dd“ to create the swap file. The following command creates a 1024MB swap file (1024 * 1024MB = 1048576).

dd if=/dev/zero of=/swapfile bs=1024 count=1048576
root@server:~# dd if=/dev/zero of=/swapfile bs=1024 count=1048576
1048576+0 records in
1048576+0 records out
1073741824 bytes (1.1 GB) copied, 16.8866 s, 63.6 MB/s

2. Set up a Linux swap area:

mkswap /swapfile
root@server:~# mkswap /swapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=9748279e-3efa-4e33-a305-3c14527cfb30

3. Activate swap space:

swapon /swapfile

4. Add swap file to fstab (optional)

To activate the swap file on system start, add entry the following line to „/etc/fstab„.

/swapfile swap swap defaults 0 0

5. Check swap

Execute „free -m“ or use „top“ to check the swap space of your system:

root@server:~# free -m
             total       used       free     shared    buffers     cached
Mem:          3529       3427        102          0         21       3198
-/+ buffers/cache:        208       3321
Swap:         1535          0       1535

Here you see the server with the 1024MB Swap file and a prior existing 512MB swap partition.

Kategorie: Linux Stichworte: debian, Swap, ubuntu

Leser-Interaktionen

Kommentare

  1. Eistiger meint

    6. Juni 2011 um 04:36

    Sehr schön gemacht 🙂 hilft mir immer wieder. Vielen dank! 😛

    Antworten
  2. Jürgen meint

    23. Mai 2013 um 17:10

    Hi,

    statt „Swapdatei (1024 * 1024MB = 1048576).“

    muss es

    Swapdatei (1024 * 1024kb = 1048576 kb).

    heißen was dann 1024 MB oder 1 GB sind.

    Gruß

    Antworten

Schreibe einen Kommentar Antwort abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

eMail-Benachrichtigung bei weiteren Kommentaren.
Auch möglich: Abo ohne Kommentar.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre, wie deine Kommentardaten verarbeitet werden.

Footer

Kategorien

  • Allgemein
  • Coldfusion
  • Development
  • Fun
  • General
  • Home automation
  • Homematic
  • Linux
  • Mobile
  • PHP
  • Privat
  • Systemadministration
  • Virtualization
  • Windows
  • Zaurus

© 2026 · Sebastian Mogilowski's Blog · Powered by Imagely