centos7上修改lv逻辑卷的大小分析

访客 阅读:232 2020-04-10 13:30:31 评论:0

author:headsen  chen

date: 2019-03-18 15:24:22

自动化修改分区的脚本

umount /home 
# 交互式执行shell命令 
echo 'y' |lvremove /dev/mapper/centos-home 
lvextend -L +140G /dev/mapper/centos-root  
xfs_growfs /dev/mapper/centos-root  
lvcreate -L 1G -n home centos 
mkfs.xfs /dev/mapper/centos-home 
mount /dev/mapper/centos-home /home 
df -h


# 必须是lvs的硬盘分区模式,centos-home 是lv的名称,centos是vg的名称,

 

 

 

 

1,查看

[[email protected] mnt]# df -h 
Filesystem           Size  Used Avail Use% Mounted on 
/dev/mapper/cl-root   50G   12G   39G  23% / 
devtmpfs             1.9G     0  1.9G   0% /dev 
tmpfs                1.9G     0  1.9G   0% /dev/shm 
tmpfs                1.9G  8.6M  1.9G   1% /run 
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup 
/dev/sda1           1014M  139M  876M  14% /boot 
/dev/mapper/cl-home   66G   33M   66G   1% /home 
tmpfs                378M     0  378M   0% /run/user/0

[[email protected] mnt]# lvs
  LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home cl -wi-a----- 65.12g                                                    
  root cl -wi-ao---- 50.00g                                                    
  swap cl -wi-ao----  3.88g      

卸载/home 分区

[[email protected] mnt]# umount /home

删除home的lv分区

[[email protected] mnt]# lvremove /dev/mapper/cl-home 
Do you really want to remove active logical volume cl/home? [y/n]: y 
  Logical volume "home" successfully removed

增加root所在的 / 分区并更新文件系统

[[email protected] mnt]# lvextend -L +60G /dev/mapper/cl-root 
  Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to 110.00 GiB (28160 extents). 
  Logical volume cl/root successfully resized.

[[email protected] ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 28835840

创建/home分区,并设置大小为5G

[[email protected] mnt]# lvcreate -L 5G -n home cl 
  Logical volume "home" created. 
 
[[email protected] mnt]# mkfs.xfs /dev/mapper/cl-home 
meta-data=/dev/mapper/cl-home    isize=512    agcount=4, agsize=327680 blks 
         =                       sectsz=512   attr=2, projid32bit=1 
         =                       crc=1        finobt=0, sparse=0 
data     =                       bsize=4096   blocks=1310720, imaxpct=25 
         =                       sunit=0      swidth=0 blks 
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1 
log      =internal log           bsize=4096   blocks=2560, version=2 
         =                       sectsz=512   sunit=0 blks, lazy-count=1 
realtime =none                   extsz=4096   blocks=0, rtextents=0

挂载并查看

[[email protected] mnt]# mount /dev/mapper/cl-home /home 
[[email protected] mnt]# df -h 
Filesystem           Size  Used Avail Use% Mounted on 
/dev/mapper/cl-root  110G   12G   99G  11% / 
devtmpfs             1.9G     0  1.9G   0% /dev 
tmpfs                1.9G     0  1.9G   0% /dev/shm 
tmpfs                1.9G  8.6M  1.9G   1% /run 
tmpfs                1.9G     0  1.9G   0%