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 ~]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值