Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two Linux boxes, one of which doesn't have much RAM or disk space. How would I go about setting up a swap file on the second machine for the first to use?

share|improve this question
4  
I do suspect an off board swap file is going to be really slow. – Journeyman Geek Sep 29 '12 at 12:21
    
@JourneymanGeek: Not necessarily... ordinary Ethernet can sometimes be faster than an old hard disk [or 1.1 USB stick]. (Trivia: Windows 3.11 had built-in support for swap over NetBIOS.) – grawity Sep 29 '12 at 12:37
1  
If you have an option to swap to a pen drive or a SDcard (preferably a SDcard with SLC memory) then this might be much faster. – Hennes Sep 29 '12 at 12:38
up vote 4 down vote accepted

You have lots of choices. You can use NBD a network block device. You can set up an NFS mount and swap over it. You can swap over CIFS.

Basically:

  1. Mount a network drive.

  2. Create a file on it of the appropriate size. (You can use dd if=/dev/zero of=/path/to/swapfile bs=xxx count=xxx)

  3. Make that file a swap device. (Use mkswap.)

  4. Mount it (Use swapon.)

  5. Configure it for permanent use. (Depends on your distribution. Check /etc/fstab.)

share|improve this answer
    
Note that swap over NFS was disabled for a long time, although it's working again in kernel 3.6. (The page you linked to, however, has very outdated instructions, including patching a 2.2 kernel...) – grawity Sep 29 '12 at 12:32
1  
one more option - ATAoE :) – Serge Sep 29 '12 at 12:33
    
Unfortunately, the OP didn't specify hardware/software. It works on the Raspberry Pi and modern desktops. I believe swap over CIFS works on OpenWRT and most router firmwares. – David Schwartz Sep 29 '12 at 12:33
    
hmm, or maybe iscsi swap – Journeyman Geek Sep 29 '12 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .