标签:tle val creating require 12px title 抽象 环境 set
本章Blog相关知识点:
LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和 分区之上的一个逻辑层,来提高磁盘分区管理的灵活性。LVM将若干个磁盘分区连接为一个整块的卷组 (volumegroup),形成一个存储池。管理员可以在卷组上随意创建逻辑卷组(logicalvolumes),并进一步在逻辑卷组上创建文件系 统。
与传统的磁盘与分区相比,LVM为计算机提供了更高层次的磁盘存储。它使系统管理员可以更方便的为应用与用户分配存储空间。在LVM管理下的存储卷可以按需要随时改变大小与移除(可能需对文件系统工具进行升级)。 LVM是在磁盘分区和文件系统之间添加的一个逻辑层,来为文件系统屏蔽下层磁盘分区布局,提供一个抽象的盘卷,在盘卷上建立文件系统。
逻辑卷管理概念:
物理卷(physical volume)——物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块。但和基本的物理存储介质(如分区,磁盘等)比较, 却包含有与LVM相关的管理参数。
卷组(Volume Group)——LVM卷组类似于非LVM系统中的物理硬盘,其由物理卷PV组成。可以在卷组上创建一个或多个"LV分区"(逻辑卷),VG卷组由一个或多个物理卷PV组成。
逻辑卷(logical volume)——LVM的逻辑卷类似于非LVM系统中的硬盘分区,在逻辑卷之上可以建立文件系统(比如/home或者/usr等)。
PE(physical extent)——每一个物理卷被划分为称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。
LE(logical extent)——逻辑卷也被划分为被称为LE(Logical Extents) 的可被寻址的基本单位。在同一个卷组中,LE的大小和PE是相同的,并且一一对应。
如下图所示PV、VG、LV三者关系:
设备文件名: /dev/卷组名/逻辑卷名 或 /dev/mapper/卷组名-逻辑卷名
物理卷管理命令:pv
pvcreate(创建pv), pvremove(移除pv), pvmove(移除卷内数据), pvscan(显示所有的pv卷), pvs(查看pv卷简要信息), pvdisplay (看pv卷详细信息)
卷组管理命令:vg
vgcreate(创建vg), vgremove(移除vg), vgs(查看vg卷简要信息), vgdisplay (查看vg卷详细信息), vgextend(扩展vg卷组), vgreduce(缩减vg卷组), vgrename (改名)
# vgcreate -s PE_size 指定PE的大小 ,默认是4M
逻辑卷的管理命令:lv
lvcreate, lvremove, lvs, lvdisplay , lvextend(扩展lv卷组) , lvreduce(缩减lv卷组)
# lvcreate 创建lv逻辑卷
-n 指定lv名称
-L 逻辑卷大小
-s 创建快照
-p 指定模式
# lvextend 扩展lv大小
-L [+] 5G 扩展[了]到5G
获取以上命令帮助方法: # command -h ,例: #lvcreate -h
配置管理LVM实验(逻辑卷管理)
系统环境:
系统:Centos 7.4 最小化安装
LVM管理工具:lvm2-2.02.171-8.el7.x86_64
磁盘分区:挂载/dev/sdb 、/dev/sdc 、/dev/sdd、/dev/sde 、/dev/sdf、 /dev/sdg 共6块磁盘
实验目的:
1、通过LVM管理工具,分别创建pv、vg 和lvm。
2、模拟扩展和缩减LV,模拟扩展或缩减VG
3、创建lv快照
4、卸载LVM,删除LVM
实验步骤:
一、设置磁盘(虚拟机中增加6块10G磁盘),安装LVM 管理工具。
1、在Vmware 虚拟机中,增加6块磁盘 。
2、查看系统版本,验证lvm*管理工具是否安装 并查看磁盘信息
[root@study ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@study ~]# rpm -qa |grep lvm* lvm2-libs-2.02.171-8.el7.x86_64 lvm2-2.02.171-8.el7.x86_64 [root@study ~]# fdisk -l | grep "^Disk./dev" Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectors Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors Disk /dev/sde: 10.7 GB, 10737418240 bytes, 20971520 sectors Disk /dev/sdf: 10.7 GB, 10737418240 bytes, 20971520 sectors Disk /dev/sdg: 10.7 GB, 10737418240 bytes, 20971520 sectors Disk /dev/mapper/VG-root: 16.1 GB, 16106127360 bytes, 31457280 sectors Disk /dev/mapper/VG-home: 21.5 GB, 21474836480 bytes, 41943040 sectors Disk /dev/mapper/VG-var: 10.7 GB, 10737418240 bytes, 20971520 sectors
二、对增加的磁盘进行分区并修改分区类型为8e(Linux LVM),并验证分区结果
[root@study ~]# echo 'n > p > 1 > > > t > 8e > w '|fdisk /dev/sdb ## 为/dev/sdb磁盘创建分区1 ,分配分区大小为磁盘总空间。并调整类型为8e(LVM) 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 0x3bb09eb9. Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Partition number (1-4, default 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): Selected partition 1 Hex code (type L to list all codes): Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@study ~]... ## 以同样的命令方式对其他5块磁盘进行操作 [root@study ~]# fdisk -l | grep "LVM$" ## 验证磁盘分区结果 /dev/sda3 12584960 251658239 119536640 8e Linux LVM /dev/sdb1 2048 20971519 10484736 8e Linux LVM /dev/sdc1 2048 20971519 10484736 8e Linux LVM /dev/sdd1 2048 20971519 10484736 8e Linux LVM /dev/sde1 2048 20971519 10484736 8e Linux LVM /dev/sdf1 2048 20971519 10484736 8e Linux LVM /dev/sdg1 2048 20971519 10484736 8e Linux LVM [root@study ~]# reboot ## 内核重读磁盘分区 [root@study ~]# cat /proc/partitions | grep "1$" ##验证内核是否加载了磁盘分区 8 1 2097152 sda1 8 17 10484736 sdb1 8 33 10484736 sdc1 8 49 10484736 sdd1 8 65 10484736 sde1 8 81 10484736 sdf1 8 97 10484736 sdg1
三、创建PV 物理卷
[root@study ~]# pvcreate /dev/sd{b..e}1 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created. Physical volume "/dev/sdd1" successfully created. Physical volume "/dev/sde1" successfully created. [root@study ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda3 VG lvm2 a-- <114.00g <69.00g /dev/sdb1 lvm2 --- <10.00g <10.00g /dev/sdc1 lvm2 --- <10.00g <10.00g /dev/sdd1 lvm2 --- <10.00g <10.00g /dev/sde1 lvm2 --- <10.00g <10.00g [root@study ~]# pvscan PV /dev/sda3 VG VG lvm2 [<114.00 GiB / <69.00 GiB free] PV /dev/sdd1 lvm2 [<10.00 GiB] PV /dev/sde1 lvm2 [<10.00 GiB] PV /dev/sdc1 lvm2 [<10.00 GiB] PV /dev/sdb1 lvm2 [<10.00 GiB] Total: 5 [153.99 GiB] / in use: 1 [<114.00 GiB] / in no VG: 4 [<40.00 GiB] [root@study ~]# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name VG PV Size <114.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 29183 Free PE 17663 Allocated PE 11520 PV UUID 2Ksdp4-23Ia-jnvA-BeO4-31O2-chlO-I2CQTc "/dev/sdd1" is a new physical volume of "<10.00 GiB" --- NEW Physical volume --- PV Name /dev/sdd1 VG Name PV Size <10.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID MjYIgP-smsp-E72x-4eOQ-kQpG-vIAA-axaKXp ...
说明:#pvcreate /dev/sd{b..g}1 创建pv物理卷;
# pvdisplay | pvs | pvscan 查看pv状态信息
PV Name, 物理卷名;
VG Name, 所属卷组名;
PV Size,物理卷大小;
PV UUID ,PV UUID 号
四、创建myvg 卷组 ,指定PE大小为16M
[root@study ~]# vgcreate /dev/myvg -s 16M /dev/sd{b..e}1 Volume group "myvg" successfully created [root@study dev]# vgs VG #PV #LV #SN Attr VSize VFree VG 1 3 0 wz--n- <114.00g <69.00g myvg 4 0 0 wz--n- <39.94g <39.94g [root@study dev]# vgscan Reading volume groups from cache. Found volume group "VG" using metadata type lvm2 Found volume group "myvg" using metadata type lvm2 [root@study dev]# pvs PV VG Fmt Attr PSize PFree /dev/sda3 VG lvm2 a-- <114.00g <69.00g /dev/sdb1 myvg lvm2 a-- 9.98g 9.98g /dev/sdc1 myvg lvm2 a-- 9.98g 9.98g /dev/sdd1 myvg lvm2 a-- 9.98g 9.98g /dev/sde1 myvg lvm2 a-- 9.98g 9.98g [root@study dev]# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name myvg PV Size <10.00 GiB / not usable 15.00 MiB Allocatable yes PE Size 16.00 MiB Total PE 639 Free PE 639 Allocated PE 0 PV UUID ZbZyCp-MiC8-Nnha-npKK-aVsr-ahTB-CIs2ok ... [root@study dev]# vgdisplay --- Volume group --- VG Name myvg System ID Format lvm2 Metadata Areas 4 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 4 Act PV 4 VG Size <39.94 GiB PE Size 16.00 MiB Total PE 2556 Alloc PE / Size 0 / 0 Free PE / Size 2556 / <39.94 GiB VG UUID hgiXN3-e8Z1-NLL2-tJ2q-hVtD-t2BO-i7uafQ
说明:#vgcreate myvg -s 16M /dev/sd{b..e}1 创建myvg1卷组,并指定PE大小为16M;
# pvdisplay | pvs | pvscan 查看pv状态信息
PE Size ,PE的大小16M,默认为4MB
Total PE,PE的总数量
Free PE / Size ,空闲PE的数量及大小
# vgdisplay | vgs |vgscan 查看vg状态信息
VG name,VG名字
VG Size ,VG容量
五、创建mylv 逻辑卷并查看pv,vg及lv状态, 格式化lv逻辑卷并实现开机挂载
[root@study dev]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home VG -wi-ao---- 20.00g root VG -wi-ao---- 15.00g var VG -wi-ao---- 10.00g mylv myvg -wi-a----- 20.00g [root@study dev]# lvscan ACTIVE '/dev/VG/root' [15.00 GiB] inherit ACTIVE '/dev/VG/home' [20.00 GiB] inherit ACTIVE '/dev/VG/var' [10.00 GiB] inherit ACTIVE '/dev/myvg/mylv' [20.00 GiB] inherit [root@study dev]# lvdisplay ... --- Logical volume --- LV Path /dev/myvg/mylv LV Name mylv VG Name myvg LV UUID 7aaK0H-sUpW-KYBL-awJl-1Jr9-Sewp-trSQi0 LV Write Access read/write LV Creation host, time study.itwish.cn, 2018-02-04 16:33:22 +0800 LV Status available # open 0 LV Size 20.00 GiB Current LE 1280 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 [root@study dev]# pvs PV VG Fmt Attr PSize PFree /dev/sda3 VG lvm2 a-- <114.00g <69.00g /dev/sdb1 myvg lvm2 a-- 9.98g 0 /dev/sdc1 myvg lvm2 a-- 9.98g 0 /dev/sdd1 myvg lvm2 a-- 9.98g 9.95g /dev/sde1 myvg lvm2 a-- 9.98g 9.98g [root@study dev]# pvscan PV /dev/sda3 VG VG lvm2 [<114.00 GiB / <69.00 GiB free] PV /dev/sdb1 VG myvg lvm2 [9.98 GiB / 0 free] PV /dev/sdc1 VG myvg lvm2 [9.98 GiB / 0 free] PV /dev/sdd1 VG myvg lvm2 [9.98 GiB / 9.95 GiB free] PV /dev/sde1 VG myvg lvm2 [9.98 GiB / 9.98 GiB free] Total: 5 [153.93 GiB] / in use: 5 [153.93 GiB] / in no VG: 0 [0 ] [root@study dev]# vgs VG #PV #LV #SN Attr VSize VFree VG 1 3 0 wz--n- <114.00g <69.00g myvg 4 1 0 wz--n- <39.94g <19.94g [root@study dev]# vgscan Reading volume groups from cache. Found volume group "VG" using metadata type lvm2 Found volume group "myvg" using metadata type lvm2 [root@study dev]# vgdisplay ... --- Volume group --- VG Name myvg System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 4 Act PV 4 VG Size <39.94 GiB PE Size 16.00 MiB Total PE 2556 Alloc PE / Size 1280 / 20.00 GiB Free PE / Size 1276 / <19.94 GiB VG UUID hgiXN3-e8Z1-NLL2-tJ2q-hVtD-t2BO-i7uafQ [root@study dev]# ls /dev/mapper/ control myvg-mylv VG-home VG-root VG-var [root@study dev]# ls /dev/myvg/ mylv [root@study dev]# mke2fs -t ext4 -m 2 -L mylvdata /dev/mapper/myvg-mylv ##创建文件系统 mke2fs 1.42.9 (28-Dec-2013) Filesystem label=mylvdata OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1310720 inodes, 5242880 blocks 104857 blocks (2.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2153775104 160 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@study dev]# mount /dev/mapper/myvg-mylv /mylv/ ##挂载 [root@study dev]# ls /mylv/ lost+found [root@study dev]# mount | grep "^/dev" /dev/mapper/VG-root on / type ext4 (rw,relatime,seclabel,data=ordered) /dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered) /dev/mapper/VG-home on /home type ext4 (rw,relatime,seclabel,data=ordered) /dev/mapper/VG-var on /var type ext4 (rw,relatime,seclabel,data=ordered) /dev/mapper/myvg-mylv on /mylv type ext4 (rw,relatime,seclabel,data=ordered) [root@study dev]# df -h | grep "^/dev" /dev/mapper/VG-root 15G 1.2G 13G 9% / /dev/sda1 2.0G 116M 1.7G 7% /boot /dev/mapper/VG-home 20G 45M 19G 1% /home /dev/mapper/VG-var 9.8G 200M 9.1G 3% /var /dev/mapper/myvg-mylv 20G 45M 20G 1% /mylv [root@study dev]# vi /etc/fstab ## 配置开机自动挂载 # # /etc/fstab # Created by anaconda on Sun Jan 28 12:27:18 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/VG-root / ext4 defaults 1 1 UUID=085b953d-5803-45df-b9d9-dc0ff7f92a3d /boot ext4 defa ults 1 2 /dev/mapper/VG-home /home ext4 defaults 1 2 /dev/mapper/VG-var /var ext4 defaults 1 2 UUID=4169cca6-5a09-46fe-a2a7-64eba563b00a swap swap defa ults 0 0 /dev/myvg/mylv /mylv ext4 defaults 0 2
说明:#lvcreate -n mylv -L 20G myvg 从myvg 卷组中分配20G并创建mylv逻辑卷;-n 指定LVM名字 ,-L 分配容量大小
# lvdisplay | lvs | lvscan 查看lv状态信息
LV Path ,LV的路径
LV Name, LV的名字VG Name所属的VG
LV Size , LV的大小
六、扩展或缩减mylv 逻辑卷
LVM最大的优势是可以对磁盘进行动态管理,而且不会丢失现有的数据。
1、扩展LVM的思路:
先确定扩展的大小,并确保所属的卷组有足够的剩余空间
扩展物理边界 ,
卸载逻辑卷umount ;
通过命令e2fsck检查lv逻辑卷 ;
# lvextend -L 【+】Size /path/to/lv_device
扩展逻辑边界
# resize2fs /path/to/lv_device Size
[root@study ~]# cp -af /boot/ /mylv/ [root@study ~]# ls /mylv/ boot lost+found [root@study ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ... mylv myvg -wi-a----- 20.00g [root@study ~]# df -lh .. /dev/mapper/myvg-mylv 20G 154M 19G 1% /mylv ... [root@study ~]# vgs ##确保剩余空间 ,扩展的大小必须小于卷组剩余空间大小,myvg剩余vg大小为19.94G VG #PV #LV #SN Attr VSize VFree VG 1 3 0 wz--n- <114.00g <69.00g myvg 4 1 0 wz--n- <39.94g <19.94g [root@study ~]# umount /mylv/ ##卸载磁盘分区/mylv/ [root@study ~]# e2fsck -fy /dev/mapper/myvg-mylv ##检查并修复磁盘 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 mylvdata: 338/1310720 files (0.3% non-contiguous), 154377/5242880 blocks [root@study ~]# lvextend -L +5G /dev/mapper/myvg-mylv ##为LV逻辑卷扩展增加5G空间 Size of logical volume myvg/mylv changed from 20.00 GiB (1280 extents) to 25.00 GiB (1600 extents). Logical volume myvg/mylv successfully resized. [root@study ~]# lvs ##lv卷增加到25G空间 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ... mylv myvg -wi-ao---- 25.00g [root@study ~]# resize2fs /dev/mapper/myvg-mylv ##为/dev/mapper/myvg-mylv扩展逻辑边界 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/mapper/myvg-mylv is mounted on /mylv; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 4 The filesystem on /dev/mapper/myvg-mylv is now 6553600 blocks long. [root@study ~]# df -lh ##查看磁盘大小 Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/myvg-mylv 25G 154M 24G 1% /mylv [root@study ~]# ls /mylv/ ##确认磁盘数据存在 boot lost+found
2、缩减LVM思路:
卸载逻辑卷umount ;
通过命令e2fsck检查lv逻辑卷 ;
缩减LVM逻辑卷逻辑边界(确保缩减后的空间大小依然能存储原有的所有数据);
# resize2fs /path/to/lv_device Size
缩减物理边界
# lvreduce -L [-] size /path/to/lv_devcie
重新挂载
[root@study ~]# lvs ##确认lv卷空间大小 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ... mylv myvg -wi-ao---- 25.00g [root@study ~]# df -lh ##查看磁盘大小 Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/myvg-mylv 25G 154M 24G 1% /mylv [root@study ~]# umount /dev/myvg/mylv [root@study ~]# e2fsck -fy /dev/mapper/myvg-mylv 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 mylvdata: 338/1638400 files (0.3% non-contiguous), 174937/6553600 blocks [root@study ~]# resize2fs /dev/mapper/myvg-mylv 15G ##缩减逻辑边界空间大小为15G resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/mapper/myvg-mylv to 3932160 (4k) blocks. The filesystem on /dev/mapper/myvg-mylv is now 3932160 blocks long. [root@study ~]# lvreduce -L 15G /dev/mapper/myvg-mylv ##缩减lv卷大小为15G WARNING: Reducing active logical volume to 15.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce myvg/mylv? [y/n]: y Size of logical volume myvg/mylv changed from 25.00 GiB (1600 extents) to 15.00 GiB (960 extents). Logical volume myvg/mylv successfully resized. [root@study ~]# mount /dev/mapper/myvg-mylv /mylv/ [root@study ~]# df -lh Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/myvg-mylv 15G 150M 15G 2% /mylv [root@study ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ... mylv myvg -wi-ao---- 15.00g
说明:# e2fsck -fy /dev/mapper/myvg-mylv 强制检查文件系统; -f 强制
#lvreduce -L 15G /dev/myvg-mylv 分配到mylv逻辑卷大小为5G; -L 分配容量大小
# lvextend -L +5G /dev/mapper/myvg-mylv 扩展5G容量分配到mylv1逻辑卷; -L 分配容量大小 +5G 扩展5G
# resize2fs /dev/mapper/myvg-mylv 扩展文件系统与逻辑卷大小一致
# resize2fs /dev/mapper/myvg-mylv 15G 缩减逻辑边界空间大小为15G
七、扩展或缩减myvg 卷组
1、扩展vg卷组思路
准备要添加的物理卷
添加物理卷至卷组中
# vgextend vg_name /path/to/pv_devcie
[root@study ~]# pvcreate /dev/sd{f,g}1 Physical volume "/dev/sdf1" successfully created. Physical volume "/dev/sdg1" successfully created. [root@study ~]# vgs VG #PV #LV #SN Attr VSize VFree VG 1 3 0 wz--n- <114.00g <69.00g myvg 4 1 0 wz--n- <39.94g <24.94g [root@study ~]# vgextend myvg /dev/sd{g,f}1 ##扩展2个磁盘分区到myvg卷组 Volume group "myvg" successfully extended [root@study ~]# vgs ## 卷组大小增加20G空间 VG #PV #LV #SN Attr VSize VFree VG 1 3 0 wz--n- <114.00g <69.00g myvg 6 1 0 wz--n- <59.91g <44.91g
2、缩减vg卷组思路
去顶要移除的物理卷的总空间大小,要小于vg当前的空闲空间大小
将要移除的物理卷上的数据移动至其他PV
# pvmove /path/to/pv_device
缩减vg
# vgremove vg_name /path/to/pv_device
[root@study ~]# vgs ##磁盘卷组空闲free空间为44.91G VG #PV #LV #SN Attr VSize VFree VG 1 3 0 wz--n- <114.00g <69.00g myvg 6 1 0 wz--n- <59.91g <44.91g [root@study ~]# pvs ## 确认分区/dev/sdb1 和分区/dev/sdc1分区被使用,存有数据 PV VG Fmt Attr PSize PFree /dev/sda3 VG lvm2 a-- <114.00g <69.00g /dev/sdb1 myvg lvm2 a-- 9.98g 0 /dev/sdc1 myvg lvm2 a-- 9.98g <4.97g /dev/sdd1 myvg lvm2 a-- 9.98g 9.98g /dev/sde1 myvg lvm2 a-- 9.98g 9.98g /dev/sdf1 myvg lvm2 a-- 9.98g 9.98g /dev/sdg1 myvg lvm2 a-- 9.98g 9.98g [root@study ~]# pvmove /dev/sdf1 ##转移数据 No data to move for myvg [root@study ~]# pvmove /dev/sdg1 No data to move for myvg [root@study ~]# vgreduce myvg /dev/sd{f,g}1 ##缩减vg卷组,删除分区/dev/sdf1 和分区/dev/sdg1 Removed "/dev/sdg1" from volume group "myvg" Removed "/dev/sdf1" from volume group "myvg" [root@study ~]# pvremove /dev/sd{g,f}1 ##删除pv卷 Labels on physical volume "/dev/sdg1" successfully wiped. Labels on physical volume "/dev/sdf1" successfully wiped.
说明:#vgextend myvg /dev/sd{f,g}1 扩展分区/dev/sdf1和分区/dev/sdg1到vg卷组
#pvmove /dev/sdg1 将分区/dev/sdg1中的数据转移到其他分区
# vgreduce myvg /dev/sd{f,g}1 在myvg卷组中缩减删除pv分区/dev/sdg1,/dev/sdf1
# pvremove /dev/sd{g,f}1 删除pv卷
八、创建LVM快照卷,完成数据备份及还原
1、实现思路
创建快照
# lvcreate -s -L size -n Name -p r /path/to/original_lv_device
挂载
# mount /dev/mapper/myvg_name /media 例 # mount /dev/mapper/myvg-test--snap /media/
把挂载数据备份
tar -zcf /root/media.tar.gz /media/*
卸载快照卷 ,移除快照卷
lvremove /dev/myvg/test-snap
模拟删除lv数据,通过快照数据进行还原
[root@study ~]# lvcreate -s -L 10G -n mylvspare -p r /dev/mapper/myvg-mylv Using default stripesize 64.00 KiB. Logical volume "mylvspare" created. [root@study ~]# mount /dev/mapper/myvg-mylvspare /media/ mount: /dev/mapper/myvg-mylvspare is write-protected, mounting read-only [root@study ~]# ls /media/ boot lost+found [root@study ~]# tar -zcf /root/spare.tar.gz /media/* tar: Removing leading `/' from member names [root@study ~]# ls -lh total 102M -rw-------. 1 root root 1.8K Jan 28 12:33 anaconda-ks.cfg drwxrwxr-x. 2 root root 36K Sep 5 21:38 Packages -rw-r--r--. 1 root root 102M Feb 4 18:11 spare.tar.gz [root@study ~]# umount /dev/mapper/myvg-mylvspare [root@study ~]# lvremove /dev/mapper/myvg-mylvspare Do you really want to remove active logical volume myvg/mylvspare? [y/n]: y Logical volume "mylvspare" successfully removed [root@study ~]# rm -rf /mylv/boot/ ##模拟删除LV卷中数据,通过备份的快照数据进行还原 [root@study mylv]# cd /root/ [root@study ~]# ls anaconda-ks.cfg Packages spare.tar.gz [root@study ~]# tar -zxf spare.tar.gz [root@study ~]# ls anaconda-ks.cfg media Packages spare.tar.gz [root@study mylv]# cp -af /root/media/* /mylv/ [root@study mylv]# ls ## 通过快照数据进行数据还原 config-3.10.0-693.el7.x86_64 efi grub grub2 initramfs-0-rescue-aa42d80ce1774acf8f5de007d85e5ef1.img initramfs-3.10.0-693.el7.x86_64.img initramfs-3.10.0-693.el7.x86_64kdump.img initrd-plymouth.img lost+found mylv symvers-3.10.0-693.el7.x86_64.gz System.map-3.10.0-693.el7.x86_64 vmlinuz-0-rescue-aa42d80ce1774acf8f5de007d85e5ef1 vmlinuz-3.10.0-693.el7.x86_64
九、卸载删除lVM
[root@study media]# umount /dev/mapper/myvg-mylv [root@study media]# lvremove /dev/mapper/myvg-mylv Do you really want to remove active logical volume myvg/mylv? [y/n]: y Logical volume "mylv" successfully removed [root@study media]# vgremove myvg Volume group "myvg" successfully removed [root@study media]# pvremove /dev/sd{b..e}1 Labels on physical volume "/dev/sdb1" successfully wiped. Labels on physical volume "/dev/sdc1" successfully wiped. Labels on physical volume "/dev/sdd1" successfully wiped. Labels on physical volume "/dev/sde1" successfully wiped.
至此 ,整体部署配置LVM实验完成 。
标签:tle val creating require 12px title 抽象 环境 set
原文地址:http://blog.51cto.com/itwish/2068732