mount swap in /tmp 

*Tags*: dev:swap

Newsgroups: comp.os.linux.misc
>How can I mount swap in /tmp?
>I used to have a linuxswap partition for the swap, but now since I
>noticed that my swap utilization is extremly low, I want to change it for
>/tmp volume. Please also provide some comments or tips on this.

You don't really want to go without swap. Linux without swap will run rather slowly, especially if you don't have much RAM. You don't necessarily need a partition dedicated for swap, however. You can turn your swap partition into an ext2 partition (and keep some swap around) by doing the following things. This assumes your swap partition is /dev/hda6 ; modify for your actual setup:

  1. init S (single-user mode, not essential in Linux but a good idea for the stuff we're about to do. Many Unices have a hard time when swap goes bye-bye, so we minimize the danger here….)
  2. dd if=/dev/zero of=/swapfile bs=1M count=64 && sync && sync (creates a 64M swapfile in / which you'll use later)
  3. mkswap /swapfile (initializes /swapfile)
  4. swapon /swapfile (turn on new swap)
  5. swapoff /dev/hda6 (turn off old swap)
  6. mke2fs /dev/hda6 (create new filesystem on hda6)
  7. mkdir /mnt/other ; mount /dev/hda6 /mnt/other
  8. cp -a /tmp /mnt/other
  9. rm -rf /tmp/*
  10. umount /dev/hda6 && mount /dev/hda6 /tmp
  11. chmod 1777 /tmp
  12. Edit /etc/fstab. Remove the previous entry for swap, and replace it with the following 2 lines:

    /swapfile   swap   swap    defaults    0    0
    /dev/hda6   /tmp   ext2    defaults    1    2
  13. init 3 (or whatever your normal runlevel is)

HTH, good luck.

Matt G

Add swapfile 

dd if=/dev/zero of=/tmp/.todel/swapfile bs=1M count=64 && sync && sync

creates a 64M swapfile in /tmp/.todel

mkswap /tmp/.todel/swapfile    # (initializes /swapfile)
swapon /tmp/.todel/swapfile    # (turn on new swap)

add the following to /etc/fstab:

/tmp/.todel/swapfile   swap                    swap    defaults        0 0

increase swap file space 

swapoff /tmp/.todel/swapfile
dd if=/dev/zero of=/tmp/.todel/swapfile bs=1M count=128 && sync && sync
mkswap /tmp/.todel/swapfile
swapon /tmp/.todel/swapfile

documented on: 2000.10.09 Mon 20:55:24