https://www.2daygeek.com/how-to-create-extend-swap-partition-in-linux-using-lvm/

BY RAMYA NUVVULA · PUBLISHED : MARCH 28, 2018 || LAST UPDATED: MARCH 28, 2018

 

We are using LVM for flexible volume management so, why can’t we use LVM for swap space?

This allow users to increase the swap partition whenever we need.

If you upgraded the RAM in your system, it is necessary to add more swap space.

This help you to manage the system that run applications that require a large amount of memory.

Swap can be created in three ways

  • Create a new swap partition
  • Create a new swap file
  • Extend swap on an existing logical volume (LVM)

It’s recommended to create a dedicated swap partition instead of swap file.

Suggested Read :
(#) 3 Easy Ways To Create Or Extend Swap Space In Linux
(#) Automatically Create/Remove And Mount Swap File In Linux Using Shell Script

What is the recommended swap size in Linux?

What Is Swap Space

Swap space in Linux is used when the amount of physical memory (RAM) is full. When physical RAM is full, inactive pages in memory are moved to the swap space.

This helps system to run the application continuously but it’s not considered a replacement for more RAM.

Swap space is located on hard drives so, it would not processing the request like physical RAM.

How To Create A Swap Partition Using LVM

As we already know how to create logical volume do the same for swap as well. Just follow the below procedure.

Create a logical volume which you required. In my case i’m going to create 5GB of swap partition.

$ sudo lvcreate -L 5G -n LogVol_swap1 vg00
Logical volume "LogVol_swap1" created.

Format the new swap space.

$ sudo mkswap /dev/vg00/LogVol_swap1
Setting up swapspace version 1, size = 5 GiB (5368705024 bytes)
no label, UUID=d278e9d6-4c37-4cb0-83e5-2745ca708582

Add the following entry to the /etc/fstab file.

# vi /etc/fstab
/dev/mapper/vg00-LogVol_swap1 swap swap defaults 0 0

Enable the extended logical volume.

$ sudo swapon -va
swapon: /swapfile: already active -- ignored
swapon: /dev/mapper/vg00-LogVol_swap1: found signature [pagesize=4096, signature=swap]
swapon: /dev/mapper/vg00-LogVol_swap1: pagesize=4096, swapsize=5368709120, devsize=5368709120
swapon /dev/mapper/vg00-LogVol_swap1

Test that the swap space has been added properly.

$ cat /proc/swaps
Filename Type Size Used Priority
/swapfile file 1459804 526336 -1
/dev/dm-0 partition 5242876 0 -2 $ free -g
total used free shared buff/cache available
Mem: 1 1 0 0 0 0
Swap: 6 0 6

How To Expand A Swap Partition Using LVM

Just follow the below procedure to extend an LVM swap logical volume.

Disable swapping for the associated logical volume.

$ sudo swapoff -v /dev/vg00/LogVol_swap1
swapoff /dev/vg00/LogVol_swap1

Resize the logical volume. I’m going to increase the swap volume from 5GB to 11GB.

$ sudo lvresize /dev/vg00/LogVol_swap1 -L +6G
Size of logical volume vg00/LogVol_swap1 changed from 5.00 GiB (1280 extents) to 11.00 GiB (2816 extents).
Logical volume vg00/LogVol_swap1 successfully resized.

Format the new swap space.

$ sudo mkswap /dev/vg00/LogVol_swap1
mkswap: /dev/vg00/LogVol_swap1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 11 GiB (11811155968 bytes)
no label, UUID=2e3b2ee0-ad0b-402c-bd12-5a9431b73623

Enable the extended logical volume.

$ sudo swapon -va
swapon: /swapfile: already active -- ignored
swapon: /dev/mapper/vg00-LogVol_swap1: found signature [pagesize=4096, signature=swap]
swapon: /dev/mapper/vg00-LogVol_swap1: pagesize=4096, swapsize=11811160064, devsize=11811160064
swapon /dev/mapper/vg00-LogVol_swap1

Test that the logical volume has been extended properly.

$ free -g
total used free shared buff/cache available
Mem: 1 1 0 0 0 0
Swap: 12 0 12 $ cat /proc/swaps
Filename Type Size Used Priority
/swapfile file 1459804 237024 -1
/dev/dm-0 partition 11534332 0 -2

How To Create/Extend Swap Partition In Linux Using LVM的更多相关文章

  1. Creating a Swap Partition

    Creating a Swap Partition 1.   Use  fdisk /dev/vda  to open your disk in fdisk. (Use gdisk if you ar ...

  2. #内存不够,swap来凑# Linux上创建SWAP文件/分区

    转自:https://www.vmvps.com/how-to-create-a-swap-file-on-the-linux-os.html 很久很久以前,电脑的内存是个珍贵东西,于是乎就有了swa ...

  3. Linux - 通过LVM对磁盘进行动态扩容

    目录 1 LVM是什么 1.1 概念解释 1.2 为什么用LVM 1.2.1 不使用LVM时的扩容思路 1.2.2 使用LVM时的扩容思路 1.3 名词解释 2 普通的挂载磁盘方法 2.1 创建分区的 ...

  4. Linux系统LVM逻辑卷创建过程以及自动化脚本

    转至:https://cloud.tencent.com/developer/article/1068328 Linux系统LVM逻辑卷创建过程以及自动化脚本 2018-03-21阅读 6300   ...

  5. [Linux 存储管理] LVM结构

    linux的LVM灵活且功能强大,当然越强大的就越难理解.lvm和硬盘大致关系应该如下,如果有误请大家左证. lvm中快照功能强大到,很多db的备份都依赖于这个功能,所以不能不理解和熟悉. <鸟 ...

  6. Linux系统LVM分区减容扩容

    Linux系统LVM分区减容扩容 目标:将VolGroup-lv_home缩小到20G,并将剩余的空间添加给VolGroup-lv_root 1.首先查看磁盘使用情况 [root@localhost ...

  7. Gparted for partition of Linux on graphic interface

    You can change the partition table on Linux by a group of tools, which is tool comprehansive for a n ...

  8. linux添加lvm磁盘大小,命令行创建swap

    添加硬盘 添加一块硬盘. 重新扫描硬盘 echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -&quo ...

  9. 调整swap分区大小-Linux下安装Oracle时报swap不够解决方法

    调整swap分区大小 方法一:如果磁盘有剩余的空间,用分区工具新建一个swap分区.并写到/etc/fstab里面.再 #swapon -a方法二:可以用一个文件做交换分区. su root cd / ...

随机推荐

  1. 软件-工具:Beyond Compare

    ylbtech-软件-工具:Beyond Compare 1.返回顶部 1. Beyond Compare是一套由Scooter Software推出的文件比较工具.主要用途是对比两个文件夹或者文件, ...

  2. django小知识

    def __str__: return self.name 在显示的时候,将原来显示的额object对象,显示成这个类的名字

  3. sorted()与sort()函数

    1 sorted可以对series,ndarry,list类型进行排序 默认会从小到大进行排序 arr1 = np.array([1,2,3,4,44,3243,43,8678]) print(sor ...

  4. jdbcTemplate和namedParameterJdbcTemplate

    jdbcTemplatejdbcTemplate配置<!-- 注入jdbcTemplate 官方工具包 --> <bean id="jdbc" class=&qu ...

  5. 编程语言分类,Python代码执行,应用程序使用文件的三步骤,变量,常量,垃圾回收机制

    编程语言分为 机器语言(直接用二进制01跟计算机直接沟通交流,直接操作硬件) 优点:计算机能够直接读懂,速度快 缺点:开发效率极低 汇编语言(用简单的英文标签来表示二进制数,直接操作硬件) 优点:开发 ...

  6. [19/05/19-星期日] CSS_css的声明和选择器

    一.引言 HTML的作用是负责数据的格式展示,如果使用它来搞数据的样式,则发现样式书写出来太麻烦,不易于维护: HTML可以有效组织数据的展示,但是不同类型数据在浏览器中的分布没有办法展示. HTML ...

  7. Elasticsearch安装及遇到的问题(CentOS 7.3 64位)

    Elasticsearch安装 使用root用户创建一个其他用户,(elasticsearch不能在root账户下安装) # 添加一个名字是es工作组 groupadd es # 添加用户es设置密码 ...

  8. INPUT输入子系统——按键

    一.什么是input输入子系统? 1.1. Linux系统支持的输入设备繁多,例如键盘.鼠标.触摸屏.手柄或者是一些输入设备像体感输入等等,Linux系统是如何管理如此之多的不同类型.不同原理.不同的 ...

  9. luogu 3426题解 (KMP)

    题面 Byteasar 想在墙上涂一段很长的字符,他为了做这件事从字符的前面一段中截取了一段作为模版. 然后将模版重复喷涂到相应的位置后就得到了他想要的字符序列.一个字符可以被喷涂很多次,但是一个位置 ...

  10. HDU 6603 Azshara's deep sea(凸包+区间DP)

    由于题目要求,首先维护出一个凸包,然后在凸包上寻找点对关系,用rel[i][j]表示i点和j点之间是否可以连线,又由于维护出来的凸包上的点的个数不多,可以直接枚举点对并枚举所有圆,判断两点直线和圆是否 ...