How to add swap space in Linux


d tox movie download 如何在Linux下面添加swap file,记录之。

1) 首先确定你要添加的swap的大小,比如是2G,那么就是2048000k

dd if=/dev/zero of=/swapfile bs=1024000k count=2


3)创建这个swap file

mkswap /swapfile

4)激活当前的swap file,这样在swapon -s就可以看到当前swap已经生效了
swapon /swapfile


/swapfile swap swap defaults 0 0

为了验证swap已经生效,有下面的几种方法,/proc/swaps or use free command or swapon -s command:

This entry was posted in 主机 and tagged , . Bookmark the permalink.

One Response to How to add swap space in Linux

  1. ricky says:


    This is straight out of the man pages, but I had a hard time finding it the first time that I needed it. If you have a Solaris system that badly needs more swap but you don’t have a free swap device available, you can create a file in the file system and add it as additional swap.


    Use mkfile to create a file suitable for a local swap area. For example, to create a 1GB swap file:

    /usr/sbin/mkfile 1024m /swap

    where /swap is the name of the file to be used as swap space. Units for the size can be kilobytes (k), blocks (b), or megabytes (m).

    Tell the system to start using the file as swap:

    /usr/sbin/swap -a /swap

    Use swap -l to verify that the swap file has been activated.

Leave a Reply

Your email address will not be published. Required fields are marked *