lvm创建流程及扩容

lvm创建常用命令

pv命令

前提是需要安装lvm命令
yum install lvm2 -y
安装该工具后,方可使用lvm的命令
pvcreate
pvs
[root@client-242 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  <19.00g     0 
  /dev/sdb          lvm2 ---   40.00g 40.00g
[root@client-242 ~]# 

pvscan
[root@client-242 ~]# pvscan 
  PV /dev/sda2   VG centos          lvm2 [<19.00 GiB / 0    free]
  PV /dev/sdb                       lvm2 [40.00 GiB]
  Total: 2 [<59.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 1 [40.00 GiB]
[root@client-242 ~]# 

[root@client-242 ~]# pvdisplay 

1.准备好硬盘
/dev/sdb

2.对硬盘进行pv化,然后查看pv的信息

3.删除pv
[root@client-242 ~]# pvremove /dev/sdb
  Labels on physical volume "/dev/sdb" successfully wiped.

vg命令

vgs 查看机器上现有的卷组信息

来自于sda硬盘,创建的pv,加入的卷组,名字是centos

[root@client-242 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <19.00g    0 

1.将2块硬盘 sdb sdc 创建为 vg-0224

第一件事 pv化
[root@client-242 ~]# pvcreate  /dev/sdb /dev/sdc
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdc" successfully created.

2.加入卷组
[root@client-242 ~]# vgcreate vg-02241  /dev/sdb /dev/sdc
  Volume group "vg-0224" successfully created

vgs
vgscan
vgdisplay
删除vg
[root@client-242 ~]# vgremove vg-0224
  Volume group "vg-0224" successfully removed

lv命令

lv的参数选项
lvcreate 
-L 指定逻辑卷的大小,单位为“kKmMgGtT”字节
-l 指定逻辑卷的大小(PE个数)
-n 后面跟逻辑卷名 
-s 创建快照


查看当前机器的逻辑卷信息
lvs

根据卷组,创建逻辑卷
[root@client-242 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  <19.00g     0 
  /dev/sdb          lvm2 ---   40.00g 40.00g
  /dev/sdc          lvm2 ---   20.00g 20.00g
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <19.00g    0 
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# vgcreate vg-0224  /dev/sdb /dev/sdc
  Volume group "vg-0224" successfully created
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree 
  centos    1   2   0 wz--n- <19.00g     0 
  vg-0224   2   0   0 wz--n-  59.99g 59.99g


创建lv,设定为卷组容量的一半
[root@client-242 ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree 
  centos    1   2   0 wz--n- <19.00g     0 
  vg-0224   2   0   0 wz--n-  59.99g 59.99g
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# lvcreate -n 0224lv1 -l 50%VG vg-0224
  Logical volume "0224lv1" created.
[root@client-242 ~]# 
[root@client-242 ~]# lvs
  LV      VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root    centos  -wi-ao---- <17.00g                                                    
  swap    centos  -wi-ao----   2.00g                                                    
  0224lv1 vg-0224 -wi-a----- <30.00g                                                    
[root@client-242 ~]# 
[root@client-242 ~]# 


删除逻辑卷
[root@client-242 ~]# lvremove /dev/vg-0224/0224lv1 
Do you really want to remove active logical volume vg-0224/0224lv1? [y/n]: y
  Logical volume "0224lv1" successfully removed
[root@client-242 ~]# 


指定逻辑卷大小
[root@client-242 ~]# lvcreate -n lv1-0224 -L 20G vg-0224
  Logical volume "lv1-0224" created.
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# lvs
  LV       VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root     centos  -wi-ao---- <17.00g                                                    
  swap     centos  -wi-ao----   2.00g                                                    
  lv1-0224 vg-0224 -wi-a-----  20.00g  

lvm创建流程

要求

  • 使用2块硬盘,容量分别是30G,30G

  • 创建卷组,名字是vg0224

  • 创建3个lv,名字依次是0224-lv1,0224-lv2,0224-lv3,容量分别是10G,15G,25G

  • 3个逻辑卷,挂载点分别是/test1 /test2 /test3,文件系统分别是xfs、xfs、ext4

  • 要求分别查看3个逻辑卷的文件系统信息

  • 要求扩容0224-lv1,扩大到30G容量

 

1.安装lvm

yum install lvm2 -y

2.查看pv

pvs

3.创建pv


[root@client-242 ~]# pvcreate /dev/sdb /dev/sdc

4.查看创建后的pv


[root@client-242 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  <19.00g     0 
  /dev/sdb          lvm2 ---   40.00g 40.00g
  /dev/sdc          lvm2 ---   20.00g 20.00g


5.查看vg


[root@client-242 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <19.00g    0 

6.创建vg sdb sdc创建为卷组,名字是 vg1-0224
注意语法

[root@client-242 ~]# vgcreate vg1-0224  /dev/sdb /dev/sdc
  Volume group "vg1-0224" successfully created
[root@client-242 ~]# 
[root@client-242 ~]# 

7.查看创建后的vg

[root@client-242 ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree 
  centos     1   2   0 wz--n- <19.00g     0 
  vg1-0224   2   0   0 wz--n-  59.99g 59.99g


8.查看lv


lvs


9.创建lv(创建分区)


一个lv1  20G
lv2  15G 

[root@client-242 ~]# lvcreate -n lv1  -L 20G  vg1-0224
  Logical volume "lv1" created.
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# lvcreate -n lv2  -L 10G  vg1-0224
  Logical volume "lv2" created.
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# lvs
  LV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos   -wi-ao---- <17.00g                                                    
  swap centos   -wi-ao----   2.00g                                                    
  lv1  vg1-0224 -wi-a-----  20.00g                                                    
  lv2  vg1-0224 -wi-a-----  10.00g                                                    
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# ls /dev/vg1-0224/
lv1  lv2


10.查看lv


lvs

11.查看磁盘设备信息


通过如下命令,查看lvm设备的信息

[root@client-242 ~]# blkid |grep 'sd[bc]'
/dev/sdb: UUID="O5ueJC-Tbd2-qab2-kx6U-Z2dD-y4od-tjosy3" TYPE="LVM2_member" 
/dev/sdc: UUID="uygL2d-owAr-NCoC-j6Ml-dHrT-QbSh-DjABxZ" TYPE="LVM2_member" 


查看/dev/卷组/

ls /dev/vg1-0224/


12.给lv格式化文件系统


lv1  20G ---xfs
lv2  15G  ----ext4

[root@client-242 ~]# mkfs.xfs /dev/vg1-0224/lv1

[root@client-242 ~]# mkfs.ext4 /dev/vg1-0224/lv2


13.挂载lv


mount 设备名   挂载点

[root@client-242 ~]# mount /dev/vg1-0224/lv1 /t1
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# mount /dev/vg1-0224/lv2 /t2


14.查看挂载

[root@client-242 ~]# mount -l |grep t1
/dev/mapper/vg1--0224-lv1 on /t1 type xfs (rw,relatime,attr2,inode64,noquota)
[root@client-242 ~]# mount -l |grep t2
/dev/mapper/vg1--0224-lv2 on /t2 type ext4 (rw,relatime,data=ordered)

[root@client-242 ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/centos-root     17G  1.5G   16G   9% /
devtmpfs                   899M     0  899M   0% /dev
tmpfs                      911M     0  911M   0% /dev/shm
tmpfs                      911M  9.6M  902M   2% /run
tmpfs                      911M     0  911M   0% /sys/fs/cgroup
/dev/sda1                 1014M  142M  873M  14% /boot
tmpfs                      183M     0  183M   0% /run/user/0
/dev/mapper/vg1--0224-lv1   20G   33M   20G   1% /t1
/dev/mapper/vg1--0224-lv2  9.8G   37M  9.2G   1% /t2


[root@client-242 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   40G  0 disk 
├─vg1--0224-lv1 253:2    0   20G  0 lvm  /t1
└─vg1--0224-lv2 253:3    0   10G  0 lvm  /t2
sdc               8:32   0   20G  0 disk 
sr0              11:0    1  4.2G  0 rom  

尝试写入数据

[root@client-242 ~]# touch /t1/小明
[root@client-242 ~]# touch /t2/小美
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# ls /t1
小明
[root@client-242 ~]# ls /t2
lost+found  小美

15.开机自动挂载


一定切记,如果你的设备发生了变化,一定要去修改/etc/fstab
否则系统开机,读取该fstab文件,找不到设备,无法正确挂载就会报错
进入紧急模式,直到你再次修复fstab文件
重启即可

把t1 t2设置为开机自动挂载
[root@client-242 ~]# tail -2 /etc/fstab 
UUID="04fda700-511c-43d4-ae9a-d87d72ee7175"  /t1  xfs  defaults 0 0 
/dev/mapper/vg1--0224-lv2 /t2  ext4  defaults 0 0 


16.重启


reboot

lvm扩容

1.确认vg够不够


[root@client-242 ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree 
  centos     1   2   0 wz--n- <19.00g     0 
  vg1-0224   2   2   0 wz--n-  59.99g 29.99g


2.确认够用,直接lvextend扩容lv逻辑卷即可


给lv2增加10G
[root@client-242 ~]# lvextend -L +10G  /dev/vg1-0224/lv2
  Size of logical volume vg1-0224/lv2 changed from 10.00 GiB (2560 extents) to 20.00 GiB (5120 extents).
  Logical volume vg1-0224/lv2 successfully resized.
[root@client-242 ~]# 
[root@client-242 ~]# 
[root@client-242 ~]# lvs
  LV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos   -wi-ao---- <17.00g                                                    
  swap centos   -wi-ao----   2.00g                                                    
  lv1  vg1-0224 -wi-ao----  20.00g                                                    
  lv2  vg1-0224 -wi-ao----  20.00g      
  
  
用法2,直接,调整到25G大小
[root@client-242 ~]# lvextend -L 25G /dev/vg1-0224/lv2
  Size of logical volume vg1-0224/lv2 changed from 20.00 GiB (5120 extents) to 25.00 GiB (6400 extents).
  Logical volume vg1-0224/lv2 successfully resized.
[root@client-242 ~]# 
[root@client-242 ~]# lvs
  LV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos   -wi-ao---- <17.00g                                                    
  swap centos   -wi-ao----   2.00g                                                    
  lv1  vg1-0224 -wi-ao----  20.00g                                                    
  lv2  vg1-0224 -wi-ao----  25.00g      

3.虽然你调整了 lv2逻辑卷的大小,但是文件系统它不知道,你得告诉文件系统,也跟着调整分区的容量,以及重新设置block的数量

ext4文件系统,使用resize2fs命令
xfs文件系统,使用xfs_growfs调整大小


4.调整lv ext4文件系统的大小


[root@client-242 ~]# resize2fs /dev/mapper/vg1--0224-lv2
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg1--0224-lv2 is mounted on /t2; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/mapper/vg1--0224-lv2 is now 6553600 blocks long.

[root@client-242 ~]# df -hT
Filesystem                Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   xfs        17G  1.6G   16G   9% /
devtmpfs                  devtmpfs  899M     0  899M   0% /dev
tmpfs                     tmpfs     911M     0  911M   0% /dev/shm
tmpfs                     tmpfs     911M  9.6M  902M   2% /run
tmpfs                     tmpfs     911M     0  911M   0% /sys/fs/cgroup
/dev/sda1                 xfs      1014M  142M  873M  14% /boot
/dev/mapper/vg1--0224-lv1 xfs        20G   33M   20G   1% /t1
/dev/mapper/vg1--0224-lv2 ext4       25G   44M   24G   1% /t2
tmpfs                     tmpfs     183M     0  183M   0% /run/user/0
[root@client-242 ~]# 


5.调整lv1的文件系统,调整到50G

看看卷组还剩下多少,不够用了,就得扩大卷组了
[root@client-242 ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree 
  centos     1   2   0 wz--n- <19.00g     0 
  vg1-0224   2   2   0 wz--n-  59.99g 14.99g
[root@client-242 ~]# 
[root@client-242 ~]# 
 

以上就是lvm的创建及扩容的所有内容了~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值