---
title: "Linux下Swap空间的添加"
author: "8366"
date: "2012-08-30T10:04:35Z"
tags: []
categories: ["操作系统"]
slug: "linux-swap"
draft: false
lastmod: "2012-08-30T10:04:35Z"
id: 1667436
url: "https://8366.iteye.com/blog/1667436"
---

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Linux下Swap空间的添加  
环境：CentOS 6.2

author:  youseesan  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

mkdir /var/swap

---创建指定大小的文件file.swp  1024字节 65536/1024=64M  
\[root@localhost ~]# dd if=/dev/zero of=/var/swap/file.swp bs=1024 count=65536  
记录了65536+0 的读入  
记录了65536+0 的写出  
67108864字节(67 MB)已复制，1.05399 秒，63.7 MB/秒  
\[root@localhost ~]#

----UUID=7b2d46b8-6448-43d5-86e0-fffa0c798965作为卷标  
\[root@localhost ~]# mkswap /var/swap/file.swp  
mkswap: /var/swap/file.swp: warning: don't erase bootbits sectors  
        on whole disk. Use -f to force.  
Setting up swapspace version 1, size = 65532 KiB  
no label, UUID=7b2d46b8-6448-43d5-86e0-fffa0c798965

vi /etc/fstab --添加下面一行,系统启动后自动加载  
\---------------------------------------------------------------------------------  
/var/swap/file.swp         swap         swap    defaults        0 0  
\---------------------------------------------------------------------------------

\[root@localhost ~]# free -m  
             total       used       free     shared    buffers     cached  
Mem:          1266        364        901          0         17        181  
\-/+ buffers/cache:        165       1100  
Swap:         2918          0       2918  
\[root@localhost ~]#

---开启swap添加  
\[root@localhost ~]# swapon /var/swap/file.swp  
\[root@localhost ~]# free -m  
             total       used       free     shared    buffers     cached  
Mem:          1266        364        901          0         17        181  
\-/+ buffers/cache:        165       1100  
Swap:         2982          0       2982  
\[root@localhost ~]#

---关闭swap添加  
\[root@localhost ~]# swapoff /var/swap/file.swp  
\[root@localhost ~]# free -m  
             total       used       free     shared    buffers     cached  
Mem:          1266        364        901          0         17        181  
\-/+ buffers/cache:        165       1100  
Swap:         2918          0       2918  
\[root@localhost ~]#