我在Windows6上运行的是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。我需要将其扩展到至少2 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, time localhost, 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:0fstab文件如下所示:
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这里我漏掉了什么?
西摩
发布于 2021-04-02 16:40:14
我在回答我自己的问题。这个问题只需运行以下命令即可解决:
sudo mkswap /dev/mapper/centos-swap之后,free命令显示新增加的交换空间,/proc/swaps文件也反映了这一点。
我在网上冲浪寻找另一个话题时偶然找到了解决方案。实际上,在创建物理卷和扩展虚拟组和逻辑卷之后,使用swapon命令声明新的交换似乎是不够的,还需要使用mkswap命令有效地“进行”交换。
不要问我为什么,它是这样工作的:-)。
https://stackoverflow.com/questions/66873856
复制相似问题