码迷,mamicode.com
首页 > 其他好文 > 详细

逻辑卷LVM

时间:2020-01-20 00:21:48      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:pvcreate   nod   wfs   cts   change   ping   磁盘   hang   简单   

当我们创建好raid组并分区以后,分区的大小是固定不变的,那么我们怎么可以更改分区的大小呢,这就需要使用到逻辑卷LVM了
使用LVM可以在不关机的情况下,简单的改变各分区的大小
技术图片
1.创建物理卷PV(多个物理卷可以组成一个卷组,也叫资源池)

[root@dinghuachong-98 ~]# yum install lvm2 -y
[root@dinghuachong-98 ~]# pvcreate /dev/md1 #将磁盘(raid组)转换成pv物理卷
#将上面添加的3个raid组都转变成物理卷
[root@dinghuachong-98 ~]# pvcreate /dev/md/raid0
WARNING: xfs signature detected on /dev/md/raid0 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/md/raid0.
  Physical volume "/dev/md/raid0" successfully created.
     
[root@dinghuachong-98 ~]# pvcreate /dev/md1
WARNING: xfs signature detected on /dev/md1 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/md1.
  Physical volume "/dev/md1" successfully created.
{1}
[root@dinghuachong-98 ~]# pvcreate /dev/md5
WARNING: xfs signature detected on /dev/md5 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/md5.
  Physical volume "/dev/md5" successfully created.

查看物理卷

[root@dinghuachong-98 ~]# pvs
  PV         VG Fmt  Attr PSize   PFree  
  /dev/md1      lvm2 ---   19.98g  19.98g
  /dev/md127    lvm2 ---  <39.97g <39.97g
  /dev/md5      lvm2 ---  <39.97g <39.97g

生成卷组lvm_raid

[root@dinghuachong-98 ~]# vgcreate lvm_raid /dev/md127 /dev/md1 /dev/md5
  Volume group "lvm_raid" successfully created
[root@dinghuachong-98 ~]# vgs    #查看卷组信息
  VG       #PV #LV #SN Attr   VSize  VFree 
  lvm_raid   3   0   0 wz--n- 99.91g 99.91g
#######################如果需要将卷组加大
 
[root@dinghuachong-98 ~]vgextend /dev/sdk #增加新物理卷到卷组

进行逻辑卷分区

##选项 -L 指定大小 -n指定名称,要以lv开头
[root@dinghuachong-98 ~]# lvcreate -L 5G lvm_raid 
  Logical volume "lvol0" created.
[root@dinghuachong-98 ~]# lvcreate -L 5G lvm_raid 
  Logical volume "lvol1" created.
[root@dinghuachong-98 ~]# lvcreate -L 5G -n lv1 lvm_raid 
  Logical volume "lv1" created.

可以对逻辑卷进行格式化,并且挂载

[root@dinghuachong-98 ~]# mkfs.xfs /dev/lvm_raid/lv1
 
[root@dinghuachong-98 ~]# mkfs.xfs /dev/lvm_raid/lvol0
meta-data=/dev/lvm_raid/lvol0    isize=512    agcount=8, agsize=163712 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1309696, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
 
[root@dinghuachong-98 ~]# mkdir /lvm{1..5} 
[root@dinghuachong-98 ~]# mount /dev/lvm_raid/lv1 /lvm1
[root@dinghuachong-98 ~]# mount /dev/lvm_raid/lvol0 /lvm2
[root@dinghuachong-98 ~]# df -h   #查询成功,挂载成功,lvm逻辑卷创建成功
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sda2                    48G  1.5G   47G   4% /
devtmpfs                    476M     0  476M   0% /dev
tmpfs                       487M     0  487M   0% /dev/shm
tmpfs                       487M  7.6M  479M   2% /run
tmpfs                       487M     0  487M   0% /sys/fs/cgroup
/dev/sda1                  1014M  127M  888M  13% /boot
tmpfs                        98M     0   98M   0% /run/user/0
/dev/mapper/lvm_raid-lv1    5.0G   33M  5.0G   1% /lvm1
/dev/mapper/lvm_raid-lvol0  5.0G   33M  5.0G   1% /lvm2

对逻辑卷进行扩大

[root@dinghuachong-98 ~]# lvextend -L +5G /dev/lvm_raid/lv1 #增加空间
  Size of logical volume lvm_raid/lv1 changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents).
  Logical volume lvm_raid/lv1 successfully resized.
[root@dinghuachong-98 ~]# df -h  #发现逻辑卷没有增加容量
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sda2                    48G  1.5G   47G   4% /
devtmpfs                    476M     0  476M   0% /dev
tmpfs                       487M     0  487M   0% /dev/shm
tmpfs                       487M  7.6M  479M   2% /run
tmpfs                       487M     0  487M   0% /sys/fs/cgroup
/dev/sda1                  1014M  127M  888M  13% /boot
tmpfs                        98M     0   98M   0% /run/user/0
/dev/mapper/lvm_raid-lv1    5.0G   33M  5.0G   1% /lvm1
/dev/mapper/lvm_raid-lvol0  5.0G   33M  5.0G   1% /lvm2
  
 
[root@dinghuachong-98 ~]# xfs_growfs /dev/lvm_raid/lv1  #对逻辑卷激活
meta-data=/dev/mapper/lvm_raid-lv1 isize=512    agcount=8, agsize=163712 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1309696, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1309696 to 2621440
[root@dinghuachong-98 ~]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sda2                    48G  1.5G   47G   4% /
devtmpfs                    476M     0  476M   0% /dev
tmpfs                       487M     0  487M   0% /dev/shm
tmpfs                       487M  7.6M  479M   2% /run
tmpfs                       487M     0  487M   0% /sys/fs/cgroup
/dev/sda1                  1014M  127M  888M  13% /boot
tmpfs                        98M     0   98M   0% /run/user/0
/dev/mapper/lvm_raid-lv1     10G   33M   10G   1% /lvm1
/dev/mapper/lvm_raid-lvol0  5.0G   33M  5.0G   1% /lvm2

逻辑卷扩大成功,至于缩小逻辑卷,在工作场景中,很危险,轻易不要操作!

逻辑卷LVM

标签:pvcreate   nod   wfs   cts   change   ping   磁盘   hang   简单   

原文地址:https://www.cnblogs.com/dinghc/p/12215842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!