系统相关
首页 > 系统相关> > Linux下使用LVM管理(扩展/缩小/删除)

Linux下使用LVM管理(扩展/缩小/删除)

作者:互联网

LVM的工作原理

LVM常用的术语

最小存储单位总结:

LVM主要元素构成:

LVM优点

RAID+LVM一起用:LVM是软件的卷管理方式,而RAID是磁盘管理的方法。对于重要的数据,使用RAID用来保护物理的磁盘不会因为故障而中断业务,再用LVM用来实现对卷的良性的管理,更好的利用磁盘资源。

创建LVM的基本步骤:

 lvm常用的命令

下面的操作会用的一些查看命令:

准备环境

[root@wencheng ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@wencheng ~]# rpm -qa | grep lvm lvm2-libs-2.02.187-6.el7_9.4.x86_64 lvm2-2.02.187-6.el7_9.4.x86_64

 创建并使用LVM逻辑卷

  VMware Workstation添加硬盘

查看新增的硬盘

创建分区并设置LVM(8e)类型。

[root@wencheng ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x81cc782c.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):    //回车(默认)
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):    ////回车(默认)
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos
Disk identifier: 0x81cc782c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   83  Linux

Command (m for help): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos
Disk identifier: 0x81cc782c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   8e  Linux LVM    //类型修改成功

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

  注: 其他新增硬盘分区类似,不再赘述,如下查看最后分区结果。

[root@wencheng ~]# ls -l /dev/sd*1
brw-rw----. 1 root disk 8,  1 Mar 25 10:54 /dev/sda1    //系统分区
brw-rw----. 1 root disk 8, 17 Apr 19 16:48 /dev/sdb1
brw-rw----. 1 root disk 8, 33 Apr 19 16:53 /dev/sdc1
brw-rw----. 1 root disk 8, 49 Apr 19 16:53 /dev/sdd1
brw-rw----. 1 root disk 8, 65 Apr 19 16:53 /dev/sde1
[root@wencheng ~]#
[root@localhost ~]# fdisk -l | grep -e "/dev/sd[b-e]1"
/dev/sdb1            2048    41943039    20970496   8e  Linux LVM
/dev/sdc1            2048    41943039    20970496   8e  Linux LVM
/dev/sdd1            2048    41943039    20970496   8e  Linux LVM
/dev/sde1            2048    20971519    10484736   83  Linux    //备用磁盘

 创建pv,并查看结果。

[root@wencheng ~]# pvcreate /dev/sd[b,c,d]1
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdc1" successfully created.
  Physical volume "/dev/sdd1" successfully created.
[root@wencheng ~]#
[root@wencheng ~]# pvdisplay /dev/sd[b,c,d]1
  "/dev/sdb1" is a new physical volume of "<10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               <20.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               kZxjyM-Ora3-io5L-J14w-ljlM-TArl-gYQhqm

  "/dev/sdd1" is a new physical volume of "<10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd1
  VG Name
  PV Size               <20.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               NN1HSf-JQAA-PiMm-MEmm-WocM-9QrD-zcStUf

  "/dev/sdc1" is a new physical volume of "<10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name
  PV Size               <20.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               I92jzU-WN1f-zcrW-Mzm7-HuoZ-3hBP-BjJFkG

创建名为'vg01'的卷组,使用/dev/sdb1, /dev/sdc1和/dev/sdb1创建,并查看结果。

[root@wencheng ~]# vgcreate vg01 /dev/sd[b,c,d]1    //指定PE大小用的参数:-s 16M,  如果存储的数据都是大文件,那么PE尽量调大,读取速度快
  Volume group "vg01" successfully created
[root@wencheng ~]#
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               vg01
  System ID
  Format                lvm2
  Metadata Areas        3
  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                3
  Act PV                3
  VG Size               <59.99 GiB    ///dev/sd[b,c]1硬盘总和容量
  PE Size               4.00 MiB     //默认4MB
  Total PE              15357
  Alloc PE / Size       0 / 0
  Free  PE / Size       15357 / <59.99 GiB
  VG UUID               0HRkjd-8ccf-Alpe-vhfJ-eOLi-vtnX-0Vl7sR

创建一个名为'lv01'、大小为30G的逻辑卷。

[root@wencheng ~]# lvcreate -n lv01 -L 30G vg01    //-L指定lv大小的SIZE(M,G) (-l:小l 指定LE的数量)
  Logical volume "lv01" created.
[root@wencheng ~]#
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/lv01
  LV Name                lv01
  VG Name                vg01
  LV UUID                Iwvoxi-Ekrb-8nQ7-QfDt-1jIx-FiXy-srYbbZ
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2021-04-20 11:17:57 +0800
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             4
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

 创建文件系统,并挂载。

[root@wencheng ~]# mkdir /mnt/lv01
[root@wencheng ~]# ls -l /dev/vg01/
total 0
lrwxrwxrwx. 1 root root 7 Apr 20 11:17 lv01 -> ../dm-0

[root@localhost ~]# mkfs.xfs /dev/vg01/lv01
meta-data=/dev/vg01/lv01         isize=512    agcount=1, agsize=4096 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=4096, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@wencheng ~]# mount /dev/vg01/lv01 /mnt/lv01/
[root@wencheng ~]# echo "/dev/vg01/lv01 /mnt/lv01 xfs defaults 0 0" >> /etc/fstab    //添加开机自动挂载
[root@wencheng ~]# df -Th /mnt/lv01/
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 xfs    31G   61M   30G   1% /mnt/lv01

 动态调整逻辑卷大小的功能是LVM最有用的功能。

  扩展LV首先,确定一下是否有可用的扩容空间,因为空间是从VG里面创建的,并且LV不能跨VG扩容。

[root@wencheng ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg01   3   1   0 wz--n- <30.99g 1012.00m

[root@wencheng ~]# pvcreate /dev/sde1
  Physical volume "/dev/sde1" successfully created.
[[root@wencheng ~]# vgextend vg01 /dev/sde1    //新增硬盘/dev/sde1为10G
  Volume group "vg01" successfully extended
[root@wencheng ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   4   1   0 wz--n- 30.99g 10.98g
[root@wencheng ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg01   3   1   0 wz--n- <59.99g 29.97g    //空闲约29G

 扩容逻辑卷,用的如下命令。

[root@wencheng ~]# lvextend -L 59G /dev/vg01/lv01
  Size of logical volume vg01/lv01 changed from <30.02 GiB (7684 extents) to 59.00 GiB (15104 extents).
  Logical volume vg01/lv01 successfully resized.

[root@wencheng ~]# lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01 -wi-ao---- 59.00g    //LV已扩容成功

[root@wencheng ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/lv01
  LV Name                lv01
  VG Name                vg01
  LV UUID                Iwvoxi-Ekrb-8nQ7-QfDt-1jIx-FiXy-srYbbZ
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2021-04-20 11:17:57 +0800
  LV Status              available
  # open                 1
  LV Size                59.00 GiB
  Current LE             15104
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

说明:
  在指定大小的时候,扩容30m和扩容到30m是不一样的写法
  扩容59G ====> -L +59G
  扩容到59G =====> -L 59G

[root@wencheng ~]# df -Th /mnt/lv01/
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 xfs    31G   61M   30G   1% /mnt/lv01    //但仍然看不到扩展的容量

注:可以看到LV虽然扩展了,但是文件系统大小还是原来的,下面开始扩容文件系统
  ext4文件系统扩容使用命令语法: resize2fs  逻辑卷名称
  xfs文件系统扩容使用命令语法:  xfs_growfs  挂载点
  resize2fs和xfs_growfs 两者的区别是传递的参数不一样的,xfs_growfs是采用的挂载点;resize2fs是逻辑卷名称,而且resize2fs命令不能对xfs类型文件系统使用。

[root@wencheng ~]# xfs_growfs /mnt/lv01/
meta-data=/dev/mapper/vg01-lv01  isize=512    agcount=1921, agsize=4096 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=7868416, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7868416 to 15466496
[root@wencheng ~]#
[root@wencheng ~]# df -Th /mnt/lv01/
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 xfs    59G  119M   59G   1% /mnt/lv01    //扩展完成
注:先扩lv逻辑卷,再扩文件系统。 掌握另一方法:使用lvextend命令钟加参数-r,它是支持多种不同的文件系统,比如ext3,ext4,xfs,… [root@wencheng ~]# lvextend -L 59G -r /dev/vg01/lv01 #直接扩容到59G空间,一步到位,不用再扩文件系统了

缩减LVM卷,注意事项

万不得已需要缩减xfs文件系统的lvm分区空间时候,一定要注意顺序。

[root@wencheng ~]# ls -l /mnt/lv01*
/mnt/lv01:
total 1060
-rw-r--r--.  1 root root     16 Apr 21 10:44 adjtime
-rw-r--r--.  1 root root   1518 Apr 21 10:44 aliases
-rw-r--r--.  1 root root  12288 Apr 21 10:44 aliases.db
-rw-------.  1 root root    541 Apr 21 10:44 anacrontab
-rw-r--r--.  1 root root     55 Apr 21 10:44 asound.conf
-rw-r--r--.  1 root root   2853 Apr 21 10:44 bashrc
-rw-r--r--.  1 root root     38 Apr 21 10:44 centos-release

[root@wencheng ~]# df -Th /mnt/lv01
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 xfs        50G  170M   50G   1% /mnt/lv01

[root@wencheng ~]# rpm -qa | grep xfsdump
xfsdump-3.1.7-1.el7.x86_64

[root@wencheng ~]# xfsdump -f /mnt/lv01.xfsdump /mnt/lv01    //xfsdump -f "dump文件存放的绝对路径加文件名" "需要缩减容量的目录"
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control

 ============================= dump label dialog ==============================

please enter label for this dump session (timeout in 300 sec)
 -> lv01
session label entered: "lv01"

 --------------------------------- end dialog ---------------------------------

xfsdump: level 0 dump of wencheng:/mnt/lv01
xfsdump: dump date: Wed Apr 21 10:59:05 2021
xfsdump: session id: 619c7222-752a-44af-8b7f-411d33fbef15
xfsdump: session label: "lv01"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 143172224 bytes
xfsdump: /var/lib/xfsdump/inventory created

 ============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)
 -> lv01
media label entered: "lv01"

 --------------------------------- end dialog ---------------------------------

xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 140934528 bytes
xfsdump: dump size (non-dir files) : 139858712 bytes
xfsdump: dump complete: 32 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /mnt/lv01.xfsdump OK (success)
xfsdump: Dump Status: SUCCESS

[root@wencheng ~]# ls -l /mnt/lv01*
-rw-r--r--. 1 root root 140934528 Apr 21 10:59 /mnt/lv01.xfsdump    //生成备份

/mnt/lv01:
total 1060
-rw-r--r--.  1 root root     16 Apr 21 10:44 adjtime
-rw-r--r--.  1 root root   1518 Apr 21 10:44 aliases
-rw-r--r--.  1 root root  12288 Apr 21 10:44 aliases.db
-rw-------.  1 root root    541 Apr 21 10:44 anacrontab
-rw-r--r--.  1 root root     55 Apr 21 10:44 asound.conf
-rw-r--r--.  1 root root   2853 Apr 21 10:44 bashrc
-rw-r--r--.  1 root root     38 Apr 21 10:44 centos-release
[root@wencheng ~]# umount /mnt/lv01/
[root@wencheng ~]# lvreduce -L 5G /dev/vg01/lv01
  WARNING: Reducing active logical volume to 5.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg01/lv01? [y/n]: y
  Size of logical volume vg01/lv01 changed from 50.00 GiB (12800 extents) to 5.00 GiB (1280 extents).
  Logical volume vg01/lv01 successfully resized.

[root@wencheng ~]# mkfs.xfs -f /dev/vg01/lv01    //格式化以更新到最新大小(清除所有数据)
meta-data=/dev/vg01/lv01         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@wencheng ~]# lvs    //lv缩小成功
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01 -wi-a----- 5.00g
[root@wencheng ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   4   1   0 wz--n- 69.98g 64.98g
[root@wencheng ~]# mount /dev/vg01/lv01 /mnt/lv01
[root@wencheng ~]# df -Th /mnt/lv01
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 xfs       5.0G   33M  5.0G   1% /mnt/lv01

[root@wencheng ~]# ls -l /mnt/lv01
total 0
[root@wencheng ~]# xfsrestore -f /mnt/lv01.xfsdump /mnt/lv01
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: wencheng
xfsrestore: mount point: /mnt/lv01
xfsrestore: volume: /dev/mapper/vg01-lv01
xfsrestore: session time: Wed Apr 21 10:59:05 2021
xfsrestore: level: 0
xfsrestore: session label: "lv01"
xfsrestore: media label: "lv01"
xfsrestore: file system id: ded6656d-b154-4c48-bda8-2935c5fa8dd8
xfsrestore: session id: 619c7222-752a-44af-8b7f-411d33fbef15
xfsrestore: media id: e4f6c078-14b3-43c3-9ff7-5c847977ca32
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 533 directories and 3574 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /mnt/lv01.xfsdump OK (success)
xfsrestore: Restore Status: SUCCESS
[root@wencheng ~]#
[root@wencheng ~]# ls -l /mnt/lv01    //查看数据是否恢复完成
total 1060
-rw-r--r--.  1 root root     16 Apr 21 10:44 adjtime
-rw-r--r--.  1 root root   1518 Apr 21 10:44 aliases
-rw-r--r--.  1 root root  12288 Apr 21 10:44 aliases.db
-rw-------.  1 root root    541 Apr 21 10:44 anacrontab
-rw-r--r--.  1 root root     55 Apr 21 10:44 asound.conf
-rw-r--r--.  1 root root   2853 Apr 21 10:44 bashrc
-rw-r--r--.  1 root root     38 Apr 21 10:44 centos-release

 LVM删除操作

创建LVM流程:pvcreate创建pv -> vgcreate创建卷组 -> lvcreate创建逻辑卷 -> mkfs.xfs lv 格式化-> mount挂载
删除LVM流程:umount卸载 -> lvremove lv移出卷组中所有逻辑卷-> vgremove vg移出卷组-> pvremove 移出pv

[root@wencheng ~]# df -Th /mnt/lv01
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 xfs   5.0G  170M  4.9G   4% /mnt/lv01
[root@wencheng ~]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01 -wi-ao---- 5.00g
[root@wencheng ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   4   1   0 wz--n- 69.98g 64.98g
[root@wencheng ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sdb1  vg01 lvm2 a--  <20.00g <15.00g
  /dev/sdc1  vg01 lvm2 a--  <20.00g <20.00g
  /dev/sdd1  vg01 lvm2 a--  <20.00g <20.00g
  /dev/sde1  vg01 lvm2 a--  <10.00g <10.00g
[root@wencheng ~]# umount /mnt/lv01
[root@wencheng ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs        30G  1.2G   29G   4% /
devtmpfs       devtmpfs  981M     0  981M   0% /dev
tmpfs          tmpfs     992M     0  992M   0% /dev/shm
tmpfs          tmpfs     992M  9.5M  982M   1% /run
tmpfs          tmpfs     992M     0  992M   0% /sys/fs/cgroup
/dev/sda1      xfs       297M  107M  191M  36% /boot
tmpfs          tmpfs     199M     0  199M   0% /run/user/0
[root@wencheng ~]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01 -wi-a----- 5.00g
[root@wencheng ~]#
[root@wencheng ~]# lvremove /dev/vg01/lv01
Do you really want to remove active logical volume vg01/lv01? [y/n]: y
  Logical volume "lv01" successfully removed
[root@wencheng ~]# lvs
[root@wencheng ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   4   0   0 wz--n- 69.98g 69.98g
[root@wencheng ~]#
[root@wencheng ~]# vgremove vg01
  Volume group "vg01" successfully removed
[root@wencheng ~]#
[root@wencheng ~]# vgs
[root@wencheng ~]# pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sdb1     lvm2 ---  <20.00g <20.00g
  /dev/sdc1     lvm2 ---  <20.00g <20.00g
  /dev/sdd1     lvm2 ---  <20.00g <20.00g
  /dev/sde1     lvm2 ---  <10.00g <10.00g
[root@wencheng ~]#
[root@wencheng ~]# pvremove /dev/sde1
  Labels on physical volume "/dev/sde1" successfully wiped.
[root@wencheng ~]# pvremove /dev/sdd1
  Labels on physical volume "/dev/sdd1" successfully wiped.
[root@wencheng ~]#
[root@wencheng ~]# pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sdb1     lvm2 ---  <20.00g <20.00g
  /dev/sdc1     lvm2 ---  <20.00g <20.00g
UUID=57c4afb5-1953-4695-b173-965f1b12500f /                       xfs     defaults        0 0
UUID=a04da5a6-ddd1-41b8-a9d6-ee5f6b62596e /boot                   xfs     defaults        0 0
UUID=77e1f34d-8161-4b9c-ba1f-240898a695ef swap                    swap    defaults        0 0
#/dev/vg01/lv01 /mnt/lv01 xfs defaults 0 0
[root@wencheng ~]# mkfs.xfs /dev/sde1
meta-data=/dev/sde1              isize=512    agcount=4, agsize=655296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621184, 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@wencheng ~]# mkfs.xfs /dev/sdd1
meta-data=/dev/sdd1              isize=512    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5242624, 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

 

标签:wencheng,删除,lv01,vg01,mnt,dev,Linux,LVM,root
来源: https://www.cnblogs.com/zhangwencheng/p/14677427.html