一、使用物理分区构建swap

1、先进行分区的行为。

 [root@iZ255cppmtxZ ~]# fdisk /dev/xvdb
Welcome to fdisk (util-linux 2.23.). Changes will remain in memory only, until you decide to write them.
Be careful before using the write command. Command (m for help): n
Partition type:
p primary ( primary, extended, free)
e extended
Select (default p): p
Partition number (,,, default ):
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): +512M Partition of type Linux and of size GiB is set Command (m for help): p Disk /dev/xvdb: 32.2 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x25a2caf5 Device Boot Start End Blocks Id System
/dev/xvdb2 Linux
/dev/xvdb4 Linux Command (m for help): t <==修改系统ID
Partition number (,, default ): 4
Hex code (type L to list all codes): 82 <==改成swap的ID
Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help): p Disk /dev/xvdb: 32.2 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x25a2caf5 Device Boot Start End Blocks Id System
/dev/xvdb2 Linux
/dev/xvdb4 Linux swap / Solaris Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

强制内核更新分区表:

[root@iZ255cppmtxZ ~]# partprobe

2、开始构建swap格式。

[root@iZ255cppmtxZ ~]# mkswap /dev/xvdb4
Setting up swapspace version , size = KiB
no label, UUID=033a1d75-88fd---08d856cb9ad1

3、查实查看与加载。

 [root@iZ255cppmtxZ ~]# swapon /dev/xvdb4
[root@iZ255cppmtxZ ~]# free
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:
[root@iZ255cppmtxZ ~]# swapon -s
Filename Type Size Used Priority
/dev/xvdb4 partition -

二、使用文件系统构建swap

1、使用dd这个命令来新增一个128MB的文件在/data下面:

 [root@iZ255cppmtxZ ~]# dd if=/dev/zero of=/data/swap bs=1M count=
+ records in
+ records out
bytes ( MB) copied, 7.82149 s, 68.6 MB/s

2、使用mkswap将/data/swap这个文件格式化为swap的文件格式:

 [root@iZ255cppmtxZ ~]# mkswap /data/swap
Setting up swapspace version , size = KiB
no label, UUID=ede63d44-cf78-4d08-92ca-15fb38a625f4

3、使用swapon来将/data/swap启动

 [root@iZ255cppmtxZ ~]# swapon /data/swap
swapon: /data/swap: insecure permissions , suggested.
[root@iZ255cppmtxZ ~]# free -m
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:
[root@iZ255cppmtxZ ~]# swapon -s
Filename Type Size Used Priority
/data/swap file -

使用swapoff关掉swapfile

 [root@iZ255cppmtxZ ~]# swapoff /dev/xvdb4
[root@iZ255cppmtxZ ~]# swapoff /data/swap

为了能够让swap自动挂载,要修改/etc/fstab文件

在文件末尾加上

/data/swap swap swap default 0 0 
这样就算重启系统,swap分区就不用手动挂载了。

最新文章

  1. 基于python的七种经典排序算法
  2. MYSQL常用内置函数详解说明
  3. Android 蓝牙 BLE 开发笔记
  4. AC之路开始了~
  5. 数据库中MyISAM与InnoDB区别
  6. 在windows下创建一个Mongo服务
  7. In Action(SPFA+01背包)
  8. COJ 0342 逆序对(一)
  9. UIPickerView(选择控制器) 自学之初体验
  10. Google的Java经常使用类库 Guava
  11. 基于支持向量机的车牌识别-- opencv2.4.7+vs2012环境搭建
  12. HDU - 1584 IDA*
  13. &quot;元素隐式具有 “any” 类型,因为类型“Shared”没有索引签名&quot;问题解决思路
  14. 微信公众号Java接入demo
  15. shell启动执行cypher语句
  16. Python 带有参数的装饰器
  17. 最受欢迎编程语言又是谁?C语言居首,大数据赢了
  18. 保姆级教程——Ubuntu16.04 Server下深度学习环境搭建:安装CUDA8.0,cuDNN6.0,Bazel0.5.4,源码编译安装TensorFlow1.4.0(GPU版)
  19. Day4 JavaScript(二)dom操作
  20. Inside GDALAllRegister之一: 五大部分

热门文章

  1. GeekOS: 一、构建基于Ubuntu9.04的实验环境
  2. AngularJS-Learning ui-router angular-transitions
  3. 天津Uber优步司机奖励政策(12月28日到12月29日)
  4. 虚拟机ubuntu使用串口
  5. itop4412开发板添加开机启动程序
  6. Maven项目配置tomcat插件实现项目自动部署到远程服务器
  7. xencenter迁移云主机方法
  8. 理解Python的装饰器
  9. Qt 5 最新信号和槽连接方式以及Lambda表达式
  10. Shader-水流效果