centos7上修改lv逻辑卷的大小

小虾米 阅读:975 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,查看

[root@localhost 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

[root@localhost 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 分区

[root@localhost mnt]# umount /home

删除home的lv分区

[root@localhost 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所在的 / 分区并更新文件系统

[root@localhost 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.

[root@localhost ~]# 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

[root@localhost mnt]# lvcreate -L 5G -n home cl 
  Logical volume "home" created. 
 
[root@localhost 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

挂载并查看

[root@localhost mnt]# mount /dev/mapper/cl-home /home 
[root@localhost 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% /sys/fs/cgroup 
/dev/sda1           1014M  139M  876M  14% /boot 
tmpfs                378M     0  378M   0% /run/user/0 
/dev/mapper/cl-home  5.0G   33M  5.0G   1% /home
标签:linux
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号