一、使用物理分区构建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分区就不用手动挂载了。

内存交换空间(swap)的构建的更多相关文章

  1. Linux命令 swap:内存交换空间

    swap 内存交换空间的概念 swap使用上的限制

  2. Linux学习之CentOS(十六)-----内存置换空间(swap)之建置(转)

    内存置换空间(swap)之建置 安装时一定需要的两个 partition 啰! 一个是根目录,另外一个就是 swap(内存置换空间), swap 的功能就是在应付物理内存不足的情况下所造成的内存延伸记 ...

  3. 如何增加Ubuntu交换空间swap

    如何增加Ubuntu交换空间swap 1  使用命令查看系统内swap分区大小 green@green:~$ free -m total used free shared buff/cache ava ...

  4. 攻城狮在路上(叁)Linux(二十五)--- linux内存交换空间(swap)的构建

    swap的功能是应付物理内存不足的状况,用硬盘来暂时放置内存中的信息. 对于一般主机,物理内存都差不多够用,所以也就不会用到swap,但是对于服务器而言,当遇到大量网络请求时或许就会用到. 当swap ...

  5. 安装Ubuntu时,遇到自定义交换空间swap大小设置问题

    【整理】Ubuntu自定义分区设置 在安装Ubuntu时,如果使用的是一个新硬盘那么安装向导会建议你使用整个硬盘,如果硬盘上已经有数据了,向导会建议使用剩余的空间。不管怎样,是由向导自动划分的分区。 ...

  6. 如何在Linux上使用文件作为内存交换区(Swap Area)

    交换区域(Swap Area)有什么作用? 交换分区是操作系统在内存不足(或内存较低)时的一种补充.通俗的说,如果说内存是汽油,内存条就相当于油箱,交换区域则相当于备用油箱. Ubuntu Linux ...

  7. iOS中的交换空间(swap space)

    看来是没有交换空间,原因是闪存和SSD硬盘相比,速度很慢,也有电源管理的原因. the NAND flash is not designed to be used as swap. It is dam ...

  8. Linux 磁盘管理篇, 内存交换空间

    swap是在系统内存不足的情况下,以硬盘暂时来储存内存中的一些数据来继续程序的执行 查看内存使用情况            free 格式化为swap格式            mkswap 启动sw ...

  9. Linux交换空间和内存不足

    交换空间 交换技术就是将一页内存复制到预先设定的硬盘上的交换空间,来释放该页占用内存.物理内存和交换空间的和就是可提供的虚拟内存的总量.Linux有两种形式的交换方式,分别是交换分区,交换文件. 优点 ...

随机推荐

  1. JZ2440开发板:用按键点亮LED灯(学习笔记)

    本文是对韦东山嵌入式第一期学习的记录之一,如有您需要查找的信息,可以继续往下阅读. 想要用按键点亮LED灯,就需要知道按键和LED灯的相关信息,这样才可以进行之后的操作.阅读JZ2440的原理图,可以 ...

  2. SpaceVim 语言模块 elixir

    原文连接: https://spacevim.org/cn/layers/lang/elixir/ 模块简介 功能特性 启用模块 快捷键 语言专属快捷键 交互式编程 运行当前脚本 模块简介 这一模块为 ...

  3. BZOJ4300_绝世好题_KEY

    题目传送门 刚开始是看到这道题目还以为是序列连续的. 当然了,序列可以不连续. 设f[i]表示到第i位时的序列的最长长度. 取cnt=Max f[j]+1,然后转移回去使f[j]=cnt. 这是为了让 ...

  4. PHP中array_reduce()使用

    array_reduce — 用回调函数迭代地将数组简化为单一的值 给定一个数组: $ar = array(1,2,3,4,5); 如果要求得这个数组中各个元素之和. 方法一. 很自然的用foreac ...

  5. iOS应用App Store发布流程

    iOS应用App Store发布流程 要发布iOS应用到App Store首先得有一个开发者账号,且不能是企业版(企业版只能部署inhouse,不能部署到App Store). 应用发布到App St ...

  6. R语言使用过程中出现的问题--attach()函数的使用

    使用attach(file)时,一定要配合使用detach(file),否则再此运行程序时极易出现问题,The following objects are masked ... 此外工作空间中不能有与 ...

  7. Android性能优化来龙去脉总结

    WeTest 导读 一款app除了要有令人惊叹的功能和令人发指交互之外,在性能上也应该追求丝滑的要求,这样才能更好地提高用户体验. 以下是本人在工作中对经历过的性能优化的一些总结,依据故事的发展路线, ...

  8. WPF & EF & Prism useful links

    Prism Attributes for MEF https://msdn.microsoft.com/en-us/library/ee155691%28v=vs.110%29.aspx Generi ...

  9. ortp打印日志

    //向字符串中打印数据 static char* ms_strdup_vprintf(const char *fmt, va_list ap) { ; char *p,*np; #ifndef WIN ...

  10. Unity 特殊目录

    其他目录 Application.persistentDataPath:webGL平台只能使用这个