Linux LVM逻辑卷管理

LVM简介:
LVM(Logic Volume Manager)是Linux系统下一款逻辑卷管理软件,这是Linux环境下对磁盘分区管理的一种机制,传统Linux分区是固定大小的分区,LVM可以创建和管理逻辑卷,而且还可以动态扩容逻辑卷容量大小,实现分区动态扩容,类似IBM服务器独有的GPFS文件系统。

PV、VG、LV简介:
1、PV(Physical Volume):物理卷,处于LVM最底层,可以理解是物理硬盘。
2、VG(Volume Group):卷组,把多个PV组合成一个大容量的硬盘池子。
3、LV(Logical Volume):逻辑卷,相当于系统分区的概念。

LVM使用分层结构,如下图所示:

image.png

LVM版本说明:
LVM1 最初的LVM与1998年发布,只在Linux内核2.4版本上可用,它提供最基本的逻辑卷管理。
LVM2是LVM2的更新版本,在Linux内核2.6中才可用,它在标准的LVM-1功能外还提供了额外的功能。

模拟实验步骤:
1、CentOS 7.5系统添加两块硬盘,第一块diskA硬盘100GB,第二块diskB硬盘50GB
2、把diskA硬盘创建PV、VG、LV形成一个100GB逻辑卷
3、把diskB硬盘动态扩容到diskA 100GB逻辑卷中组合成150GB的逻辑卷

**提示:**本教程适用文件格式(ext2/ext3/ext4),不适用xfs文件格式
CentOS系统环境:

[root@client01 ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core) 
[root@client01 ~]# uname -a
Linux client01 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@client01 ~]# cat /etc/locale.conf 
LANG="en_US.UTF-8"

一、安装LVM软件(默认CentOS 7.5没有安装)

1、配置阿里yum源和epel源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

2、关闭防火墙和SElinux(防火墙和SElinux可以不关闭)

###关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

###关闭SElinux
sed -i "s/^SELINUX = .*/SELINUX = disabled/g" /etc/selinux/config
setenforce 0
getenforce

3、yum安装LVM软件

[root@client01 ~]# yum -y install lvm2
[root@client01 ~]# rpm -qa | grep lvm
lvm2-libs-2.02.185-2.el7_7.2.x86_64
lvm2-2.02.185-2.el7_7.2.x86_64

二、diskA 100GB硬盘创建PV、VG、LV

1、添加两块硬盘 diskA硬盘/dev/sdb diskB硬盘/deb/sdc

[root@client01 ~]# fdisk -l
Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000a6d40

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    17410047     8192000   82  Linux swap / Solaris
/dev/sda3        17410048   167772159    75181056   83  Linux

Disk /dev/sdb: 108.4 GB, 108447924224 bytes, 211812352 sectors    ##diskA 100GB硬盘
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/sdc: 54.8 GB, 54760833024 bytes, 106954752 sectors       ##diskB 50GB硬盘
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、diskA 100GB硬盘/dev/sdb创建分区并设置成LVM分区类型

[root@client01 ~]# 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 0x3523df03.

Command (m for help): p        ##输入p打印当前磁盘上的分区信息

Disk /dev/sdb: 108.4 GB, 108447924224 bytes, 211812352 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: 0x3523df03

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n        ##输入n新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p            ##输入p 选择分区类型为主分区
Partition number (1-4, default 1): 1    ##输入1  选择为第一主分区
First sector (2048-211812351, default 2048):   ##直接回车 选择分区起始块为1
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-211812351, default 211812351): +100G ##为新分区大小设置 100GB
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): p      ##输入p打印当前磁盘上的分区信息

Disk /dev/sdb: 108.4 GB, 108447924224 bytes, 211812352 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: 0x3523df03

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209717247   104857600   83  Linux

Command (m for help): t    ##输入t 改变分区类型
Selected partition 1
Hex code (type L to list all codes): 8e   ##输入8e 改变分区类型为LVM
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p      ##输入p打印当前磁盘上的分区信息

Disk /dev/sdb: 108.4 GB, 108447924224 bytes, 211812352 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: 0x3523df03

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209717247   104857600   8e  Linux LVM

Command (m for help): w         ##输入w 保存磁盘管理分区操作
The partition table has been altered!

Calling ioctl() to re-read partition table.

3、diskA硬盘分区/dev/sdb1创建PV物理卷

[root@client01 ~]# pvcreate /dev/sdb1     ##创建PV物理卷
  Physical volume "/dev/sdb1" successfully created.
[root@client01 ~]# pvs                 ##查看PV物理卷精简信息
  PV         VG       Fmt  Attr PSize    PFree   
  /dev/sdb1  VGdata01 lvm2 a--  <100.00g <100.00g
[root@client01 ~]# pvdisplay             ##查看PV物理卷详细信息
  "/dev/sdb1" is a new physical volume of "100.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               100.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               e2bytS-WWl0-bddQ-MQZZ-gWeL-wVaz-07CAtx

4、将/dev/sdb1物理卷PV创建为卷组VG,名称VGdata01

[root@client01 ~]# vgcreate VGdata01 /dev/sdb1    ##创建VG卷组,卷组名称为VGdata01
  Volume group "VGdata01" successfully created
[root@client01 ~]# vgs                          ##查看VG物理卷精简信息
  VG       #PV #LV #SN Attr   VSize    VFree   
  VGdata01   1   0   0 wz--n- <100.00g <100.00g
[root@client01 ~]# vgdisplay                      ##查看VG物理卷详细信息
  --- Volume group ---
  VG Name               VGdata01
  System ID             
  Format                lvm2
  Metadata Areas        1
  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                1
  Act PV                1
  VG Size               <100.00 GiB
  PE Size               4.00 MiB
  Total PE              25599
  Alloc PE / Size       0 / 0   
  Free  PE / Size       25599 / <100.00 GiB
  VG UUID               RRIAMu-S6IH-lyD0-MCuY-aYHO-Htwg-vhnOhS

5、将/dev/sdb1卷组VG创建逻辑卷LV(名称定义为LVdata01)并格式化、挂载使用

[root@client01 ~]# lvcreate -L 99G -n LVdata01 VGdata01  ##在名为VGdata01的VG上创建一个名为LVdata01逻辑卷
  Logical volume "LVdata01" created.
[root@client01 ~]# lvs           ##查看LV物理卷精简信息
  LV       VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  LVdata01 VGdata01 -wi-a----- 99.00g                                                    
[root@client01 ~]# lvdisplay     ##查看VG物理卷详细信息
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01
  LV Name                LVdata01
  VG Name                VGdata01
  LV UUID                it3Gf2-0fN5-EreM-ko7T-HqFL-1Z6R-ew3wGg
  LV Write Access        read/write
  LV Creation host, time client01, 2020-04-30 08:23:55 +0800
  LV Status              available
  # open                 0
  LV Size                99.00 GiB
  Current LE             25344
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@client01 ~]# mkfs.ext4 /dev/VGdata01/LVdata01   ##格式化LVdata01逻辑卷文件格式为ext4
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6488064 inodes, 25952256 blocks
1297612 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
792 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@client01 ~]# mkdir /LVdata01       ##创建一个挂载目录 LVdata01
[root@client01 ~]# mount /dev/VGdata01/LVdata01 /LVdata01/    ##挂载目录
[root@client01 ~]# df –Th     ##查看磁盘挂载信息
Filesystem                    Type      Size  Used Avail Use% Mounted on
/dev/sda3                     xfs        72G  2.1G   70G   3% /
devtmpfs                      devtmpfs  981M     0  981M   0% /dev
tmpfs                         tmpfs     992M     0  992M   0% /dev/shm
tmpfs                         tmpfs     992M  9.6M  982M   1% /run
tmpfs                         tmpfs     992M     0  992M   0% /sys/fs/cgroup
/dev/sda1                     xfs       497M  117M  380M  24% /boot
tmpfs                         tmpfs     199M     0  199M   0% /run/user/0
/dev/mapper/VGdata01-LVdata01 ext4       98G   61M   93G   1% /LVdata01

6、永久挂载逻辑卷LVdata01

[root@client01 ~]# echo "/dev/mapper/VGdata01-LVdata01             /LVdata01               ext4    defaults        0 0" >> /etc/fstab 
[root@client01 ~]# tail -1 /etc/fstab 
/dev/mapper/VGdata01-LVdata01             /LVdata01               ext4    defaults        0 0

三、diskB 50GB硬盘扩容到diskA 100GB硬盘上形成150GB的LVdata01逻辑卷

1、diskB 50GB硬盘/dev/sdc创建分区并设置成LVM分区类型

[root@client01 ~]# fdisk /dev/sdc              ##磁盘管理分区
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 0x8e2b1298.

Command (m for help): p                ##输入p打印当前磁盘上的分区信息

Disk /dev/sdc: 54.8 GB, 54760833024 bytes, 106954752 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: 0x8e2b1298

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n                    ##输入n新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p                         ##输入p 选择分区类型为主分区
Partition number (1-4, default 1): 1            ##输入1  选择为第一主分区
First sector (2048-106954751, default 2048):    ##直接回车 选择分区起始块为1
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-106954751, default 106954751): +50G  ##为新分区大小设置 50GB
Partition 1 of type Linux and of size 50 GiB is set

Command (m for help): p        ##输入p打印当前磁盘上的分区信息

Disk /dev/sdc: 54.8 GB, 54760833024 bytes, 106954752 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: 0x8e2b1298

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   104859647    52428800   83  Linux

Command (m for help): t               ##输入t 改变分区类型
Selected partition 1
Hex code (type L to list all codes): 8e     ##输入8e 改变分区类型为LVM
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p              ##输入p打印当前磁盘上的分区信息

Disk /dev/sdc: 54.8 GB, 54760833024 bytes, 106954752 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: 0x8e2b1298

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   104859647    52428800   8e  Linux LVM

Command (m for help): w      ##输入w 保存磁盘管理分区操作
The partition table has been altered!

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

2、diskB硬盘分区/dev/sdc1创建PV物理卷

[root@client01 ~]# pvcreate /dev/sdc1    ##创建PV物理卷
  Physical volume "/dev/sdc1" successfully created.
[root@client01 ~]# pvs                 ##查看PV物理卷精简信息
  PV         VG       Fmt  Attr PSize    PFree   
  /dev/sdb1  VGdata01 lvm2 a--  <100.00g 1020.00m
  /dev/sdc1           lvm2 ---    50.00g   50.00g
[root@client01 ~]# pvdisplay             ##查看PV物理卷详细信息
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               VGdata01
  PV Size               100.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25599
  Free PE               255
  Allocated PE          25344
  PV UUID               QJzGP1-qAby-WWgZ-LJJ3-jIsa-anEh-Sr1DJ3
   
  "/dev/sdc1" is a new physical volume of "50.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name               
  PV Size               50.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               zcPqSu-dk4T-Ut2H-rUaQ-oPlM-Hvhu-glFlo6

3、把diskB 50GB物理卷PV扩容到diskA 100GB 卷组VGdata01里面

[root@client01 LVdata01]# vgextend VGdata01 /dev/sdc1   ##将diskB 50GB PV扩容到diskA 100Gb 卷组VGdata01
  Volume group "VGdata01" successfully extended
[root@client01 LVdata01]# vgs                     ##查看VG物理卷精简信息
  VG       #PV #LV #SN Attr   VSize   VFree 
  VGdata01   2   1   0 wz--n- 149.99g 50.99g
[root@client01 LVdata01]# vgdisplay                 ##查看VG物理卷详细信息
  --- Volume group ---
  VG Name               VGdata01
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               149.99 GiB
  PE Size               4.00 MiB
  Total PE              38398
  Alloc PE / Size       25344 / 99.00 GiB
  Free  PE / Size       13054 / 50.99 GiB
  VG UUID               11hnGp-ejdw-LFVQ-TnwN-SJuT-CzLM-OmZxQJ

4、在线把原来/dev/VGdata01/LVdata01逻辑卷100GB扩展到150GB

##在diskA 100GB逻辑卷创建测试文件
[root@client01 ~]# cd /LVdata01/
[root@client01 LVdata01]# touch {1..10}.txt
[root@client01 LVdata01]# ls -l
total 16
-rw-r--r-- 1 root root     0 Apr 30 08:47 10.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 1.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 2.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 3.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 4.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 5.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 6.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 7.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 8.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 9.txt
[root@client01 LVdata01]# echo "This is a test LVM" > 1.txt
[root@client01 LVdata01]# cat 1.txt 
This is a test LVM

[root@client01 LVdata01]# lvdisplay     ##查看原来/dev/VGdata01/LVdata01逻辑卷信息
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01
  LV Name                LVdata01
  VG Name                VGdata01
  LV UUID                it3Gf2-0fN5-EreM-ko7T-HqFL-1Z6R-ew3wGg
  LV Write Access        read/write
  LV Creation host, time client01, 2020-04-30 08:23:55 +0800
  LV Status              available
  # open                 1
  LV Size                99.00 GiB
  Current LE             25344
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@client01 LVdata01]# lvextend -L +49G /dev/VGdata01/LVdata01  ##将LVdata01逻辑卷扩容至150GB
  Size of logical volume VGdata01/LVdata01 changed from 99.00 GiB (25344 extents) to 148.00 GiB (37888 extents).
  Logical volume VGdata01/LVdata01 successfully resized.
[root@client01 LVdata01]# lvs          ##查看LV物理卷精简信息
  LV       VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  LVdata01 VGdata01 -wi-ao---- 148.00g                                                    
[root@client01 LVdata01]# lvdisplay      ##查看LV物理卷详细信息
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01
  LV Name                LVdata01
  VG Name                VGdata01
  LV UUID                it3Gf2-0fN5-EreM-ko7T-HqFL-1Z6R-ew3wGg
  LV Write Access        read/write
  LV Creation host, time client01, 2020-04-30 08:23:55 +0800
  LV Status              available
  # open                 1
  LV Size                148.00 GiB
  Current LE             37888
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@client01 LVdata01]# e2fsck -f /dev/VGdata01/  ##强制检查VGdata01卷组是否正常,如果异常自动修复
e2fsck 1.42.9 (28-Dec-2013)
e2fsck: Is a directory while trying to open /dev/VGdata01/

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>

###注意,如果执行resize2fs命令提示:Couldn't find valid filesystem superblock.需要使用xfs_growfs  /dev/VGdata01/LVdata01命令刷新lv即可正常查看增加的大小。
[root@client01 LVdata01]# resize2fs -p /dev/VGdata01/LVdata01  ##在线调整ext2\ext3\ext4文件系统的大小
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/VGdata01/LVdata01 is mounted on /LVdata01; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 19
The filesystem on /dev/VGdata01/LVdata01 is now 38797312 blocks long.

tmpfs                          199M     0  199M   0% /run/user/0
[root@client01 LVdata01]# df –Th     ##查看磁盘挂载信息
Filesystem                    Type      Size  Used Avail Use% Mounted on
/dev/sda3                     xfs        72G  2.1G   70G   3% /
devtmpfs                      devtmpfs  981M     0  981M   0% /dev
tmpfs                         tmpfs     992M     0  992M   0% /dev/shm
tmpfs                         tmpfs     992M  9.6M  982M   1% /run
tmpfs                         tmpfs     992M     0  992M   0% /sys/fs/cgroup
/dev/sda1                     xfs       497M  117M  380M  24% /boot
/dev/mapper/VGdata01-LVdata01 ext4      146G   60M  139G   1% /LVdata01
tmpfs                         tmpfs     199M     0  199M   0% /run/user/0

##检查LVdata01逻辑卷备份的资料是否异常
[root@client01 LVdata01]# ls –l 
total 20
-rw-r--r-- 1 root root     0 Apr 30 08:47 10.txt
-rw-r--r-- 1 root root    19 Apr 30 08:48 1.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 2.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 3.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 4.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 5.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 6.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 7.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 8.txt
-rw-r--r-- 1 root root     0 Apr 30 08:47 9.txt
drwx------ 2 root root 16384 Apr 30 08:25 lost+found
[root@client01 LVdata01]# cat 1.txt 
This is a test LVM

四、缩减逻辑卷

提示:不能在线缩减逻辑卷,必须先umount卸载

[root@client01 ~]# umount /dev/VGdata01/LVdata01     ##确认卸载挂载
[root@client01 ~]# df –Th                            ##查看磁盘挂载情况
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        72G  2.1G   70G   3% /
devtmpfs       devtmpfs  981M     0  981M   0% /dev
tmpfs          tmpfs     992M  9.6M  982M   1% /run
tmpfs          tmpfs     992M     0  992M   0% /sys/fs/cgroup
[root@client01 ~]# e2fsck -f /dev/VGdata01/LVdata01     ##强制检测文件系统是否损坏,损坏自动修复
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VGdata01/LVdata01: 21/9764864 files (0.0% non-contiguous), 661123/39059456 blocks
[root@client01 ~]# lvdisplay            ##详细查看LV逻辑卷情况
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01
  LV Name                LVdata01
  VG Name                VGdata01
  LV UUID                EOhXzn-nBy9-UxLQ-N8ju-WhJC-11Vz-fZHKVc
  LV Write Access        read/write
  LV Creation host, time client01, 2020-04-30 15:13:28 +0800
  LV Status              available
  # open                 0
  LV Size                149.00 GiB
  Current LE             38144
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@client01 ~]# resize2fs /dev/VGdata01/LVdata01 30G   ##在线调整ext2\ext3\ext4文件系统为30G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/VGdata01/LVdata01 to 7864320 (4k) blocks.
The filesystem on /dev/VGdata01/LVdata01 is now 7864320 blocks long.

[root@client01 ~]# lvreduce -L 30G /dev/VGdata01/LVdata01   ##LV逻辑卷从150GB缩减30GB
  WARNING: Reducing active logical volume to 30.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce VGdata01/LVdata01? [y/n]: y     ##输入y  确认
  Size of logical volume VGdata01/LVdata01 changed from 149.00 GiB (38144 extents) to 30.00 GiB (7680 extents).
  Logical volume VGdata01/LVdata01 successfully resized.
[root@client01 ~]# lvdisplay        ##详细查看LV逻辑卷情况
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01
  LV Name                LVdata01
  VG Name                VGdata01
  LV UUID                EOhXzn-nBy9-UxLQ-N8ju-WhJC-11Vz-fZHKVc
  LV Write Access        read/write
  LV Creation host, time client01, 2020-04-30 15:13:28 +0800
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@client01 ~]# mount /dev/VGdata01/LVdata01 /LVdata01/  ##挂载LV逻辑卷
[root@client01 ~]# ls -l /LVdata01/                          ##查看逻辑卷资料是否完整
total 20
-rw-r--r-- 1 root root     0 Apr 30 15:15 10.txt
-rw-r--r-- 1 root root    19 Apr 30 15:16 1.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 2.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 3.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 4.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 5.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 6.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 7.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 8.txt
-rw-r--r-- 1 root root     0 Apr 30 15:15 9.txt
drwx------ 2 root root 16384 Apr 30 15:14 lost+found
[root@client01 ~]# cat /LVdata01/1.txt 
This is a test LVM

五、备份逻辑卷LVdata01

[root@client01 ~]# lvdisplay    ##详细查看LV逻辑卷LVdata01
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01
  LV Name                LVdata01
  VG Name                VGdata01
  LV UUID                EOhXzn-nBy9-UxLQ-N8ju-WhJC-11Vz-fZHKVc
  LV Write Access        read/write
  LV Creation host, time client01, 2020-04-30 15:13:28 +0800
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@client01 ~]# lvcreate -L 30M -n LVdata01_backup -s -p r /dev/VGdata01/LVdata01 ##创建快照
  Rounding up size to full physical extent 32.00 MiB
  Logical volume "LVdata01_backup" created.
[root@client01 ~]# lvdisplay       ##详细查看LV逻辑卷LVdata01
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01
  LV Name                LVdata01
  VG Name                VGdata01
  LV UUID                EOhXzn-nBy9-UxLQ-N8ju-WhJC-11Vz-fZHKVc
  LV Write Access        read/write
  LV Creation host, time client01, 2020-04-30 15:13:28 +0800
  LV snapshot status     source of
                         LVdata01_backup [active]
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/VGdata01/LVdata01_backup
  LV Name                LVdata01_backup
  VG Name                VGdata01
  LV UUID                kpR2BG-kxQc-D26r-qUWC-j8sx-Kc4O-H3Oesw
  LV Write Access        read only
  LV Creation host, time client01, 2020-04-30 17:42:30 +0800
  LV snapshot status     active destination for LVdata01
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  COW-table size         32.00 MiB
  COW-table LE           8
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

[root@client01 ~]# mount /dev/VGdata01/LVdata01_backup /mnt/
mount: /dev/mapper/VGdata01-LVdata01_backup is write-protected, mounting read-only
[root@client01 ~]# df -Th
Filesystem                           Type      Size  Used Avail Use% Mounted on
/dev/sda3                            xfs        72G  2.1G   70G   3% /
devtmpfs                             devtmpfs  981M     0  981M   0% /dev
tmpfs                                tmpfs     992M  9.6M  982M   1% /run
tmpfs                                tmpfs     992M     0  992M   0% /sys/fs/cgroup
/dev/mapper/VGdata01-LVdata01_backup ext4       30G   45M   28G   1% /mnt
[root@client01 ~]# mount /dev/VGdata01/LVdata01 /LVdata01/
[root@client01 ~]# ls -l /mnt/
total 8
-rw-r--r-- 1 root root    0 Apr 30 15:15 10.txt
-rw-r--r-- 1 root root   19 Apr 30 15:16 1.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 2.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 3.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 4.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 5.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 6.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 7.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 8.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 9.txt
drwx------ 2 root root 4096 Apr 30 15:14 lost+found
[root@client01 ~]# ls -l /LVdata01/
total 8
-rw-r--r-- 1 root root    0 Apr 30 15:15 10.txt
-rw-r--r-- 1 root root   19 Apr 30 15:16 1.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 2.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 3.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 4.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 5.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 6.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 7.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 8.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 9.txt
drwx------ 2 root root 4096 Apr 30 15:14 lost+found
[root@client01 ~]# rm -rf /LVdata01/*
[root@client01 ~]# cp -rp /mnt/* /LVdata01/
[root@client01 ~]# ls -l /LVdata01/
total 8
-rw-r--r-- 1 root root    0 Apr 30 15:15 10.txt
-rw-r--r-- 1 root root   19 Apr 30 15:16 1.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 2.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 3.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 4.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 5.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 6.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 7.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 8.txt
-rw-r--r-- 1 root root    0 Apr 30 15:15 9.txt
drwx------ 2 root root 4096 Apr 30 15:14 lost+found
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,607评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,047评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,496评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,405评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,400评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,479评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,883评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,535评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,743评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,544评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,612评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,309评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,881评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,891评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,136评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,783评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,316评论 2 342