如何增加 CentOS 虚拟机中的交换空间

Ser*_*Ten 5 centos swap lvm virtualbox

尝试在 Virtualbox 5.1 内运行的 CentOS 7 VM 中 RPM 安装 Oracle XE 时,我收到以下错误消息:

This system does not meet the minimum requirements for swap space.  Based on
the amount of physical memory available on the system, Oracle Database 11g
Express Edition requires 2048 MB of swap space. This system has 1279 MB
of swap space.  Configure more swap space on the system and retry the 
installation.
Run Code Online (Sandbox Code Playgroud)

如何增加交换空间?

到目前为止,我已尝试lvm按照此处此处的说明进行操作,但均未成功。我必须从一个已经配置的最小 CentOS VM 开始,所以调整原始映像不是一个选项。

一条swapon -s命令通知我:

Filename                Type        Size    Used    Priority
/dev/dm-1               partition   1310716 0       -1
Run Code Online (Sandbox Code Playgroud)

lvdisplay输出是:

  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                rdNgH4-Sili-NpwP-Ny3S-xtU9-MlEC-ttE5JI
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-12-19 22:50:56 +0000
  LV Status              available
  # open                 2
  LV Size                1.25 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                H737Lq-OMhE-F9Lf-BlTg-3PL1-0T7O-1Ciusi
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-12-19 22:50:56 +0000
  LV Status              available
  # open                 1
  LV Size                12.39 GiB
  Current LE             3172
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
Run Code Online (Sandbox Code Playgroud)

df -h

Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   13G  9.4G  3.1G  76% /
devtmpfs             907M     0  907M   0% /dev
tmpfs                920M  4.0K  920M   1% /dev/shm
tmpfs                920M  8.7M  912M   1% /run
tmpfs                920M     0  920M   0% /sys/fs/cgroup
/dev/sda1           1014M  239M  776M  24% /boot
tmpfs                184M     0  184M   0% /run/user/1002
tmpfs                184M     0  184M   0% /run/user/1001
tmpfs                184M   12K  184M   1% /run/user/1000
tmpfs                184M     0  184M   0% /run/user/2
/dev/sr0              57M   57M     0 100% /run/media/vagrant/VBOXADDITIONS_5.1.33_120529
vagrant              102G   77G   26G  76% /vagrant
Run Code Online (Sandbox Code Playgroud)

编辑

内容 /etc/fstab

/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=41388da5-fc65-4a34-a3da-58bb81daf744 /boot                   xfs     defaults        0 0
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
Run Code Online (Sandbox Code Playgroud)

输出 vgs

VG #PV #LV #SN Attr   VSize  VFree
cl   1   2   0 wz--n- 13.64g 4.00m
Run Code Online (Sandbox Code Playgroud)

Emm*_*osa 2

您可以通过首先缩小根逻辑卷以释放空间来增加交换空间,然后将其重新分配给交换逻辑卷。您需要将交换 LV 增加 769 MB 才能达到 2048 MB,并且您的根 LV 有 3.1 GB 可用空间,因此您可以尝试以下操作:

  1. 缩小你的根LV。该-r选项也会导致文件系统调整大小:lvresize -L -769M -r c1/root
  2. 暂时关闭你的交换,因为你将要修改它:swapoff
  3. 调整交换 LV 的大小。或者,删除它并使用连续分配重新创建它,以便物理扩展彼此相邻,以获得更好的性能:lvresize -L +769M c1/swap
  4. 重新打开交换:swapon