How to add swap space in Linux

.!.

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

1) 首先确定你要添加的swap的大小,比如是2G,那么就是2048000k
2)以root用户登录到终端,dd一个文件,大小就是你期望的swap文件大小,比如:

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

这样就创建了一个大小是2G的文件

3)创建这个swap file

mkswap /swapfile

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

5)为了在系统重启后依然生效,还需要一个步骤,在/etc/fstab中添加:

/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:

    在Solaris上,用下面的方法:

    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.

    1.

    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).
    2.

    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 *