LVM管理

PV、VG、LV创建方法

创建PV

1、使用命令fdisk -l查看可用作pv的盘符

[root@localhost ~]# fdisk -l

Disk /dev/nvme0n1: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0xb517108c

Device         Boot   Start      End  Sectors  Size Id Type
/dev/nvme0n1p1 *       2048   616447   614400  300M 83 Linux
/dev/nvme0n1p2       616448  4907007  4290560    2G 82 Linux swap / Solaris
/dev/nvme0n1p3      4907008 62914559 58007552 27.7G 83 Linux


Disk /dev/nvme0n2: 30 GiB, 32212254720 bytes, 62914560 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/nvme0n3: 30 GiB, 32212254720 bytes, 62914560 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

2、创建pv

[root@localhost ~]# pvcreate /dev/nvme0n2 /dev/nvme0n3

  Physical volume "/dev/nvme0n2" successfully created.
  Physical volume "/dev/nvme0n3" successfully created.
[root@localhost ~]# pvdisplay 
  "/dev/nvme0n2" is a new physical volume of "30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/nvme0n2
  VG Name               
  PV Size               30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               QaW0Ds-01F9-bmeR-4wAp-Wo6f-hPs1-CYQoRZ
   
  "/dev/nvme0n3" is a new physical volume of "30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/nvme0n3
  VG Name               
  PV Size               30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               4XxLr4-P5X4-hpGa-cdjv-oZkL-zLlc-03r0zQ

创建VG

1、使用PV的盘创建VG


[root@localhost ~]# vgcreate vg_soft /dev/nvme0n2 /dev/nvme0n3
  Volume group "vg_soft" successfully created
[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg_soft
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               59.99 GiB
  PE Size               4.00 MiB
  Total PE              15358
  Alloc PE / Size       0 / 0   
  Free  PE / Size       15358 / 59.99 GiB
  VG UUID               a3r9NF-p0zP-jAbd-scyU-O3pP-GQ3f-qWBmJ7

创建LV

[root@localhost ~]# lvcreate -L 20G -n lv_dm01 vg_soft
  Logical volume "lv_dm01" created.
[root@localhost ~]# lvcreate -L 40G -n lv_oracle01 vg_soft
  Volume group "vg_soft" has insufficient free space (10238 extents): 10240 required.
[root@localhost ~]# lvcreate -l 10238 -n lv_oracle01 vg_soft
  Logical volume "lv_oracle01" created.
[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg_soft/lv_dm01
  LV Name                lv_dm01
  VG Name                vg_soft
  LV UUID                v0pJpE-XoKJ-2Tgc-xL2c-2kRW-9oLR-TZ76rx
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2022-01-08 23:41:53 -0800
  LV Status              available
  # open                 0
  LV Size                20.00 GiB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg_soft/lv_oracle01
  LV Name                lv_oracle01
  VG Name                vg_soft
  LV UUID                Y3eQ9X-JZp4-k10f-3m0w-XXHj-R3Ge-ZG58Q9
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2022-01-08 23:42:47 -0800
  LV Status              available
  # open                 0
  LV Size                39.99 GiB
  Current LE             10238
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

创建LV后,就可以使用lv路径在挂载点中进行挂载操作。

添加新硬盘并扩展LV

PV、VG、LV扩展

[root@DATABASE ~]# pvs
  PV           VG      Fmt  Attr PSize   PFree
  /dev/nvme0n2 vg_soft lvm2 a--  <50.00g    0 
[root@DATABASE ~]# 
[root@DATABASE ~]# pvcreate /dev/nvme0n3
  Physical volume "/dev/nvme0n3" successfully created.
[root@DATABASE ~]# 
[root@DATABASE ~]# vgextend vg_soft /dev/nvme0n3
  Volume group "vg_soft" successfully extended
[root@DATABASE ~]# 
[root@DATABASE ~]# lvextend -l +100%FREE /dev/vg_soft/lv_soft
  Size of logical volume vg_soft/lv_soft changed from <50.00 GiB (12799 extents) to 99.99 GiB (25598 extents).
  Logical volume vg_soft/lv_soft successfully resized.
[root@DATABASE ~]# xfs_growfs /soft/  ---注意:是挂载点
meta-data=/dev/mapper/vg_soft-lv_soft isize=512    agcount=4, agsize=3276544 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=13106176, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=6399, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13106176 to 26212352
[root@DATABASE ~]# 

文件系统扩展

在lv中扩展后,需要对挂载点进行扩展,这样文件系统才能识别新扩展后的容量。对于ext4和xfs,在扩展lvm后时挂载盘空间调整,需要用不同的命令。

[root@localhost scsi_host]# xfs_growfs /soft/
[root@localhost scsi_host]# resize2fs -f /soft/

对于加盘后不显示盘的情况,参考如下:

--手动刷新scsi
[root@song ~]# cd /sys/class/scsi_host/
[root@song scsi_host]# ls
host0  host1  host2
[root@song scsi_host]#  echo "- - -" > host0/scan
[root@song scsi_host]# fdisk -l没有就继续重复
[root@song scsi_host]#  echo "- - -" > host1/scan
[root@song scsi_host]# fdisk -l
[root@song scsi_host]#  echo "- - -" > host2/scan

原创文章,作者:lzb,如若转载,请注明出处:https://www.wlkjzx.com/2023/06/23/lvm/

(0)
打赏 微信扫一扫 微信扫一扫
lzblzb
上一篇 2023年6月19日
下一篇 2023年6月24日

相关推荐

发表回复

登录后才能评论

评论列表(1条)

  • 3853
    3853 2023年6月23日 下午8:21

    很不错的技术站