centos7针对xfs文件系统减小Linux swap分区的方法

  1. 先df -h、lsblk、fdisk - l命令查看一下当前分区情况,并获取swap分区
/dev/mapper/centos-swap: 33.8 GB
  1. 用swapoff命令关闭交换分区:
swapoff /dev/mapper/centos-swap

然后用free命令检查下swap是否变为0了。
用lvreduce命令把swap分区减少至4G:

 lvreduce -L 4G /dev/mapper/centos-swap

输入y,确定,看到提示swap减小至4G。

  1. 重新把/dev/mapper/centos-swap设置为swap分区:
 mkswap  /dev/mapper/centos-swap
  1. swapon开启swap分区:
swapon  /dev/mapper/centos-swap

然后用free命令检查下swap是否变为4G了。

  1. 扩大根目录所在的逻辑卷:
lvextend -l +100%FREE /dev/mapper/centos-root
  1. 扩大根目录文件系统:
xfs_growfs /dev/mapper/centos-root

附录:

[root@40-187 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  2.6T 1008M  2.6T   1% /
devtmpfs                  32G     0   32G   0% /dev
tmpfs                     32G     0   32G   0% /dev/shm
tmpfs                     32G  9.2M   32G   1% /run
tmpfs                     32G     0   32G   0% /sys/fs/cgroup
/dev/sda2               1014M  145M  870M  15% /boot
/dev/mapper/centos-home  100G   33M  100G   1% /home
tmpfs                    6.3G     0  6.3G   0% /run/user/0
[root@40-187 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  2.7T  0 disk 
├─sda1            8:1    0    1M  0 part 
├─sda2            8:2    0    1G  0 part /boot
└─sda3            8:3    0  2.7T  0 part 
  ├─centos-root 253:0    0  2.6T  0 lvm  /
  ├─centos-swap 253:1    0 31.4G  0 lvm  [SWAP]
  └─centos-home 253:2    0  100G  0 lvm  /home
[root@40-187 ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 3000.0 GB, 3000034656256 bytes, 5859442688 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 label type: gpt
Disk identifier: A4ACB23B-6686-4444-8C18-F3B29486B77F


#         Start          End    Size  Type            Name
 1         2048         4095      1M  BIOS boot       
 2         4096      2101247      1G  Microsoft basic 
 3      2101248   5859440639    2.7T  Linux LVM       

Disk /dev/mapper/centos-root: 2857.8 GB, 2857826779136 bytes, 5581692928 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: 33.8 GB, 33755758592 bytes, 65929216 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-home: 107.4 GB, 107374182400 bytes, 209715200 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

[root@40-187 ~]# 

你可能感兴趣的:(centos)