Set up permanent swap space under Ubuntu system (repost)

http://blog.sina.com.cn/s/blog_6e4388910100tsk7.html

 

Swap  is generally in a dedicated swap area, which may be because the system prompts you to create a swap area during installation. But in fact any file can be used as swap ( swap device ) , be it a partition or a simple file. Nevertheless, for better experience and sensing speed, it is recommended to use a large amount of memory instead of relying on swap . Swap can be increased by adding a swap file  

 

four steps

 

    1) Create a file of your preset size.

 

 

    2) Format the file as swap ( swap device ) .

 

 

    3) Add swap to the existing system.

 

 

 

    4) Make a permanent change in the system.

 

  

Example: To add a 512M swap 

 

 Create a 512M file 

 

We will  create a swap file at /mnt/512Mb.swap  .

 

 

sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512

 

 

 The count=512  in the code  means that we want to create a file that contains 512 blocks of bs=1M (bs = block size  ; 1M = 1mebibyte  = 1048576  bytes ) . Be careful not to use  the command dd of=/mnt/512Mb.swap bs=1M seek=512 count=0  . Although the file will immediately grow to 512Mb , this is buggy and may render it unusable.

 

  

Format the file to make it swap ( swap device ):

 

 

 sudo mkswap /mnt/512Mb.swap 

 

Activate swap to an existing system now :

 

 

 

sudo swapon /mnt/512Mb.swap

 

 

Now the new swap can be seen by " cat /proc/meminfo " command.

 

 

Make permanent changes :

 

  

Edit  the /etc/fstab  file :

 

 

gksudo gedit /etc/fstab

 

  

Add the following line to the end of the file : 

 

/mnt/512Mb.swap  none  swap  sw  0 0

 

  

Save and restart.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325022964&siteId=291194637