CentOS 7:“free”命令未显示 LVM 交换扩展

问题描述

我在 Windows 上的 VirtualBox 6 上运行 CentOS 7 客户机。 free命令的结果如下:

$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        2.4G         11G        162M        1.5G         12G
Swap:          1.2G          0B        1.2G

显示交换分区有 1.2 GB。我需要将它扩展到至少 2GB。因此,在来宾停止后,我添加了 1.2 GB 的新卷,并在重新启动后执行以下操作:

$ sudo pvcreate /dev/sdb
$ sudo vgextend centos /dev/sdb
$ sudo lvextend -L+1G /dev/centos/swap

现在,lvdisplay 命令显示新创建的卷,如下所示:

$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                1OT4R8-69eL-vczL-zydM-XrwS-jA47-YfikMS
  LV Write Access        read/write
  LV Creation host,time localhost,2019-12-30 22:01:35 +0100
  LV Status              available
  # open                 2
  LV Size                <2.20 GiB
  Current LE             563
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                hGDGPf-iPMB-TUtM-nqRv-aDNd-D3mw-W15H8Z
  LV Write Access        read/write
  LV Creation host,2019-12-30 22:01:35 +0100
  LV Status              available
  # open                 1
  LV Size                <76.43 GiB
  Current LE             19565
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

fstab 文件如下所示:

dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=4ef0416f-1617-40da-99d2-83896d808eed /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0

显示交换被分配在 /dev/mapper/centos-swap 分区上。下面是 fstab 命令的输出:

Disk /dev/mapper/centos-root: 82.1 GB,82061557760 bytes,160276480 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2361 MB,2361393152 bytes,4612096 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

但重启后 swapon 命令似乎没有反映扩展名:

$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1257468 0       -2

出于某种原因,交换似乎不在 /dev/mapper/centos-swap 分区上,而是在 /dev/dm-1 上,而 /dev/dm-1 甚至不存在。而且 free 命令仍然显示与开始时相同的结果:

$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        2.4G         11G        155M        1.5G         12G
Swap:          1.2G          0B        1.2G

和 /proc/swaps:

$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1257468 0       -2

我在这里遗漏了什么?

西摩

解决方法

我正在回答我自己的问题。只需运行以下命令即可解决该问题:

sudo mkswap /dev/mapper/centos-swap

之后,free 命令显示新增加的交换空间,/proc/swaps 文件也反映了这一点。

我在浏览另一个主题时偶然找到了解决方案。看起来,事实上,在创建了物理卷并扩展了虚拟组和逻辑卷之后,仅用 swapon 命令声明新的交换区是不够的,还需要有效地“制作”使用 mkswap 命令交换。

不要问我为什么,这就是它的工作方式:-)。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...