Linux 服务器配置LVM(逻辑卷管理)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 服务器配置LVM(逻辑卷管理)相关的知识,希望对你有一定的参考价值。
LVM简介
LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和 分区之上的一个逻辑层,来提高磁盘分区管理的灵活性。LVM将若干个磁盘分区连接为一个整块的卷组 (volumegroup),形成一个存储池。管理员可以在卷组上随意创建逻辑卷组(logicalvolumes),并进一步在逻辑卷组上创建文件系 统。
与传统的磁盘与分区相比,LVM为计算机提供了更高层次的磁盘存储。它使系统管理员可以更方便的为应用与用户分配存储空间。在LVM管理下的存储卷可以按需要随时改变大小与移除(可能需对文件系统工具进行升级)。 LVM是在磁盘分区和文件系统之间添加的一个逻辑层,来为文件系统屏蔽下层磁盘分区布局,提供一个抽象的盘卷,在盘卷上建立文件系统。
基本的逻辑卷管理概念:
物理卷 (physical volume)
物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
卷组 (Volume Group)
LVM卷组类似于非LVM系统中的物理硬盘,其由物理卷组成。可以在卷组上创建一个或多个“LVM分区”(逻辑卷),LVM卷组由一个或多个物理卷组成。
逻辑卷(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三者关系:
系统环境
系统环境: Centos 6.6 最小化安装
LVM管理工具: lvm2-2.02.143-12.el6.
磁盘分区:挂载/dev/sdb 、/dev/sdc 、/dev/sdd、/dev/sde 、/dev/sdf、 /dev/sdg 共6块磁盘
实验目的:
1、通过LVM管理工具,分别创建pv、vg 和lvm。
2、模拟扩展和缩减LVM,模拟扩展或缩减VG
3、卸载LVM,删除LVM
一、设置磁盘(虚拟机中增加6块20G磁盘),安装LVM 管理工具。
在Vmware 虚拟机中,增加8块磁盘 。
[[email protected] /]# fdisk -l #查看磁盘状态 Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000c6c5f Device Boot Start End Blocks Id System /dev/sda1 * 1 256 2048000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 256 511 2048000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 511 3060 20480000 83 Linux Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 ..... Disk /dev/sdf: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/sdg: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [[email protected] ~]# rpm -qa |grep lvm #确认lvm管理工具是否安装 [[email protected] ~]# yum install lvm* -y #安装lvm管理
二、对增加的磁盘进行分区并修改分区类型为8e(Linux LVM)
[[email protected] /]# fdisk /dev/sdb #对硬盘/dev/sdb 进行分区并调整分区类型 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xb9977492. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won‘t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition‘s system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): Using default value 2610 Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xb9977492 Device Boot Start End Blocks Id System /dev/sdb1 1 2610 20964793+ 83 Linux Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xb9977492 Device Boot Start End Blocks Id System /dev/sdb1 1 2610 20964793+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
说明:#fdisk /dev/sdb 对其他磁盘进行分区;
输入"m", 获取帮助;
输入"p", 查看分区前磁盘状态;
输入“n”,新建磁盘分区;
输入“e”,新建逻辑分区;
输入“p”,新建主分区;
输入“t”,修改分区类型;
输入“fd”,调整为linux raid autodetect 类型 ;
输入“p”,显示分区状态表;
输入“w”,保存新建分区。
以同样的方式,对其他磁盘进行分区。磁盘分区完成后结果如下:
[[email protected] /]# fdisk -l Disk /dev/sdb: 21.5 GB, 21474836480 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 2610 20964793+ 8e Linux LVM Disk /dev/sdc: 21.5 GB, 21474836480 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 2610 20964793+ 8e Linux LVM Disk /dev/sdd: 21.5 GB, 21474836480 bytes Device Boot Start End Blocks Id System /dev/sdd1 1 2610 20964793+ 8e Linux LVM Disk /dev/sde: 21.5 GB, 21474836480 bytes Device Boot Start End Blocks Id System /dev/sde1 1 2610 20964793+ 8e Linux LVM Disk /dev/sdf: 21.5 GB, 21474836480 bytes Device Boot Start End Blocks Id System /dev/sdf1 1 2610 20964793+ 8e Linux LVM Disk /dev/sdg: 21.5 GB, 21474836480 bytes Device Boot Start End Blocks Id System /dev/sdg1 1 2610 20964793+ 8e Linux LVM
三、创建PV 物理卷
[[email protected] /]# pvcreate /dev/sd{b..g}1 #对磁盘分区分别创建PV Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdc1" successfully created Physical volume "/dev/sdd1" successfully created Physical volume "/dev/sde1" successfully created Physical volume "/dev/sdf1" successfully created Physical volume "/dev/sdg1" successfully created [[email protected] dev]# pvdisplay --- Physical volume --- PV Name /dev/sdd1 VG Name myvg2 PV Size 19.99 GiB / not usable 1.43 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 5118 Free PE 0 Allocated PE 5118 PV UUID PJp0SF-3H2d-zfXe-fAve-1JmW-FsSm-itsC2q --- Physical volume --- PV Name /dev/sde1 VG Name myvg2 PV Size 19.99 GiB / not usable 1.43 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 5118 Free PE 0 Allocated PE 5118 PV UUID qbLHW1-NNam-qCPS-zphy-tEzx-Cb39-j2u4Uf --- Physical volume --- PV Name /dev/sdf1 VG Name myvg2 PV Size 19.99 GiB / not usable 1.43 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 5118 Free PE 0 Allocated PE 5118 PV UUID xooWla-DpOK-Jca8-2QKF-j29H-Tsgc-5Lamtv --- Physical volume --- PV Name /dev/sdg1 VG Name myvg2 PV Size 19.99 GiB / not usable 1.43 MiB Allocatable yes PE Size 4.00 MiB Total PE 5118 Free PE 5112 Allocated PE 6 PV UUID OHvLBz-c3Kw-Gq0H-48ty-5Zyg-B1nC-U0b0dg --- Physical volume --- PV Name /dev/sdc1 VG Name myvg1 PV Size 19.99 GiB / not usable 1.43 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 5118 Free PE 0 Allocated PE 5118 PV UUID LxdE2p-ER9f-TZyQ-Kcf3-6pEr-zA3r-HKHgSG --- Physical volume --- PV Name /dev/sdb1 VG Name myvg1 PV Size 19.99 GiB / not usable 1.43 MiB Allocatable yes PE Size 4.00 MiB Total PE 5118 Free PE 2556 Allocated PE 2562 PV UUID 5T4fjJ-lSWx-jny5-chTp-w7Wk-3bTC-iJ6sIt [[email protected] ~]# pvscan #查看PV简要信息 PV /dev/sdb1 lvm2 [19.99 GiB] PV /dev/sdc1 lvm2 [19.99 GiB] PV /dev/sdd1 lvm2 [19.99 GiB] PV /dev/sde1 lvm2 [19.99 GiB] PV /dev/sdf1 lvm2 [19.99 GiB] PV /dev/sdg1 lvm2 [19.99 GiB] Total: 6 [119.96 GiB] / in use: 0 [0 ] / in no VG: 6 [119.96 GiB] [[email protected] ~]# pvs #查看PV简要信息 PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 ---- 19.99g 19.99g /dev/sdc1 lvm2 ---- 19.99g 19.99g /dev/sdd1 lvm2 ---- 19.99g 19.99g /dev/sde1 lvm2 ---- 19.99g 19.99g /dev/sdf1 lvm2 ---- 19.99g 19.99g /dev/sdg1 lvm2 ---- 19.99g 19.99g
说明:#pvcreate /dev/sd{b..g}1 创建pv物理卷;
# pvdisplay | pvs |pvscan 查看pv状态信息
PV Name, 物理卷名;
VG Name, 所属卷组名;
PV Size,物理卷大小;
PV UUID ,PV UUID 号
四、创建myvg1、myvg2 卷组
[[email protected] ~]# vgcreate myvg1 /dev/sdb1 /dev/sdc1 #创建vg卷组myvg1 ,使用物理卷/dev/sdb1 和 /dev/sdc1 Volume group "myvg1" successfully created [[email protected] ~]# vgcreate myvg2 /dev/sd{d..g}1 #创建vg卷组myvg2,使用物理卷/dev/sdd1、/dev/sde1、/dev/sdf1 、/dev/sdg1 Volume group "myvg2" successfully created [[email protected] dev]# vgdisplay --- Volume group --- VG Name myvg2 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 1 Max PV 0 Cur PV 4 Act PV 4 VG Size 79.97 GiB PE Size 4.00 MiB Total PE 20472 Alloc PE / Size 15360 / 60.00 GiB Free PE / Size 5112 / 19.97 GiB VG UUID xcT3bS-xjke-tGEI-GL0p-hRe4-3WAs-72355D --- Volume group --- VG Name myvg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 8 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 39.98 GiB PE Size 4.00 MiB Total PE 10236 Alloc PE / Size 7680 / 30.00 GiB Free PE / Size 2556 / 9.98 GiB VG UUID rASgft-0OPt-5blH-BACG-oR4b-glCX-7OJZcF [[email protected] ~]# vgscan #查看vg简要信息 Reading all physical volumes. This may take a while... Found volume group "myvg2" using metadata type lvm2 Found volume group "myvg1" using metadata type lvm2 [[email protected] ~]# vgs VG #PV #LV #SN Attr VSize VFree myvg1 2 0 0 wz--n- 39.98g 39.98g myvg2 4 0 0 wz--n- 79.97g 79.97g
说明:#vgcreate myvg1 /dev/sd{b..c}1 创建myvg1卷组;
# vgdisplay | vgs |vgscan 查看vg状态信息
VG Name, 卷组名;
VG Size,卷组Size大小;
PE Size ,PE的大小,默认为4MB
Total PE,PE的总数量
Free PE / Size ,空闲PE的数量及大小
VG UUID ,VG UUID 号
五、创建mylv1、mylv2 逻辑卷, 格式化并挂载
[[email protected] ~]# lvcreate -n mylv1 -L 30G myvg1 Logical volume "mylv1" created. [[email protected] ~]# lvcreate -n mylv2 -L 60G myvg2 Logical volume "mylv2" created. [[email protected] ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv1 myvg1 -wi-a----- 30.00g mylv2 myvg2 -wi-a----- 60.00g [[email protected] ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv1 myvg1 -wi-a----- 30.00g mylv2 myvg2 -wi-a----- 60.00g [[email protected] dev]# lvdisplay --- Logical volume --- LV Path /dev/myvg2/mylv2 LV Name mylv2 VG Name myvg2 LV UUID pKGpwi-1aN4-jrcR-uGcj-D9ZN-7AcV-PN0yue LV Write Access read/write LV Creation host, time study, 2017-09-22 23:10:03 +0800 LV Status available # open 1 LV Size 60.00 GiB Current LE 15360 Segments 4 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/myvg1/mylv1 LV Name mylv1 VG Name myvg1 LV UUID uiX2dG-crHV-lO83-qqUq-fBqj-mov6-2KQefT LV Write Access read/write LV Creation host, time study, 2017-09-22 23:09:05 +0800 LV Status available # open 1 LV Size 30.00 GiB Current LE 7680 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [[email protected] ~]# fdisk -l #查看myvg1-mylv1 、myvg2-mylv2 逻辑卷状态。 ... Disk /dev/mapper/myvg1-mylv1: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/myvg2-mylv2: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [[email protected] dev]# vgs # 查看分配完LVM后剩余VG容量 VG #PV #LV #SN Attr VSize VFree myvg1 2 1 0 wz--n- 39.98g 9.98g myvg2 4 1 0 wz--n- 79.97g 19.97g [[email protected] dev]# pvs # 查看分配完LVM后剩余PV容量 PV VG Fmt Attr PSize PFree /dev/sdb1 myvg1 lvm2 a--u 19.99g 9.98g /dev/sdc1 myvg1 lvm2 a--u 19.99g 0 /dev/sdd1 myvg2 lvm2 a--u 19.99g 0 /dev/sde1 myvg2 lvm2 a--u 19.99g 0 /dev/sdf1 myvg2 lvm2 a--u 19.99g 0 /dev/sdg1 myvg2 lvm2 a--u 19.99g 19.97g [[email protected] ~]# cd /dev/mapper/ #逻辑卷磁盘存放于/dev/mapper目录中 [[email protected] mapper]# ls control myvg1-mylv1 myvg2-mylv2 [[email protected] mapper]# mkfs.ext4 myvg1-mylv1 #对LVM卷进行格式化 [[email protected] mapper]# mkfs.ext4 myvg2-mylv2 [[email protected] dev]# mount /dev/mapper/myvg1-mylv1 lvm1 #对LVM卷进行挂载 [[email protected] dev]# mount /dev/mapper/myvg2-mylv2 lvm2 [[email protected] dev]# df -TH #查看磁盘挂载状态 Filesystem Type Size Used Avail Use% Mounted on /dev/sda3 ext4 21G 1.2G 19G 7% / tmpfs tmpfs 1.3G 0 1.3G 0% /dev/shm /dev/mapper/myvg1-mylv1 ext4 32G 47M 30G 1% /dev/lvm1 /dev/mapper/myvg2-mylv2 ext4 64G 55M 61G 1% /dev/lvm2
说明:#lvcreate -n mylv1 -L 30G myvg1 从myvg1 卷组中分配30G并创建mylv1逻辑卷;-n 指定LVM名字 ,-L 分配容量大小
# lvdisplay | lvs | lvscan 查看lv状态信息
LV Path ,LV的路径
LV Name, LV的名字VG Name 所属的VG
LV Size , LV的大小
六、扩展或缩减mylv1、mylv2 逻辑卷
LVM最大的好处就是可以对磁盘进行动态管理,而且不会丢失现有的数据。
1、扩展LVM的思路:
需要先扩展逻辑卷;然后扩展文件系统
[[email protected] ~]# lvextend -L +5G /dev/mapper/myvg1-mylv1 #扩展5G空间给myvg1-mylv1 Size of logical volume myvg1/mylv1 changed from 30.00 GiB (7680 extents) to 35.00 GiB (8960 extents). Logical volume mylv1 successfully resized. [[email protected] ~]# lvextend -L +10G /dev/mapper/myvg2-mylv2 #扩展10G空间给myvg2-mylv2 Size of logical volume myvg2/mylv2 changed from 60.00 GiB (15360 extents) to 70.00 GiB (17920 extents). Logical volume mylv2 successfully resized. [[email protected] ~]# resize2fs -p /dev/mapper/myvg1-mylv1 #扩展myvg1-mylv1卷下的文件体统,扩展大小与逻辑卷增加的大小一致 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/myvg1-mylv1 is mounted on /dev/lvm1; on-line resizing required old desc_blocks = 2, new_desc_blocks = 3 Performing an on-line resize of /dev/mapper/myvg1-mylv1 to 9175040 (4k) blocks. The filesystem on /dev/mapper/myvg1-mylv1 is now 9175040 blocks long. [[email protected] ~]# resize2fs -p /dev/mapper/myvg2-mylv2 #扩展myvg2-mylv2卷下的文件体统,扩展大小与逻辑卷增加的大小一致 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/myvg2-mylv2 is mounted on /dev/lvm2; on-line resizing required old desc_blocks = 4, new_desc_blocks = 5 Performing an on-line resize of /dev/mapper/myvg2-mylv2 to 18350080 (4k) blocks. The filesystem on /dev/mapper/myvg2-mylv2 is now 18350080 blocks long. [[email protected] ~]# df -TH #查看磁盘空间,mylv1 及mylv2 均已扩展 Filesystem Type Size Used Avail Use% Mounted on /dev/sda3 ext4 21G 1.2G 19G 7% / tmpfs tmpfs 1.3G 0 1.3G 0% /dev/shm /dev/mapper/myvg1-mylv1 ext4 37G 52M 35G 1% /dev/lvm1 /dev/mapper/myvg2-mylv2 ext4 74G 57M 71G 1% /dev/lvm2
说明:#lvextend -L +5G /dev/myvg1-mylv1 扩展5G容量分配到mylv1逻辑卷; -L 分配容量大小 +5G 扩展5G
# resize2fs -p /dev/mapper/myvg1-mylv1 扩展文件系统与逻辑卷大小一致 。-p 表示跟逻辑卷扩展大小保持一致
2、缩减LVM思路:
不能再线缩减,得先卸载;确保缩减后的空间大小依然能存储原有的所有数据;缩减前应该先强行检查文件,以确保文件系统处于一致性状态;缩减文件系统,缩减LVM逻辑卷;重新挂载
[[email protected] ~]# umount /dev/mapper/myvg1-mylv1 #先卸载逻辑卷分区/dev/mapper/mgvg1-mylv1 [[email protected] ~]# umount /dev/mapper/myvg2-mylv2 [[email protected] ~]# e2fsck -f /dev/mapper/myvg1-mylv1 #强行检查文件,以确保文件系统处于一致性状态 e2fsck 1.41.12 (17-May-2010) 第一步: 检查inode,块,和大小 第二步: 检查目录结构 第3步: 检查目录连接性 Pass 4: Checking reference counts 第5步: 检查簇概要信息 /dev/mapper/myvg1-mylv1: 43/2293760 files (0.0% non-contiguous), 189423/9175040 blocks [[email protected] ~]# e2fsck -f /dev/mapper/myvg2-mylv2 e2fsck 1.41.12 (17-May-2010) 第一步: 检查inode,块,和大小 第二步: 检查目录结构 第3步: 检查目录连接性 Pass 4: Checking reference counts 第5步: 检查簇概要信息 /dev/mapper/myvg2-mylv2: 42/4587520 files (0.0% non-contiguous), 334367/18350080 blocks [[email protected] ~]# resize2fs /dev/mapper/myvg1-mylv1 5G #缩减/dev/mapper/myvg1-mylv1 文件系统到5G大小 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/myvg1-mylv1 to 1310720 (4k) blocks. The filesystem on /dev/mapper/myvg1-mylv1 is now 1310720 blocks long. [[email protected] ~]# resize2fs /dev/mapper/myvg2-mylv2 15G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/myvg2-mylv2 to 3932160 (4k) blocks. The filesystem on /dev/mapper/myvg2-mylv2 is now 3932160 blocks long. [[email protected] ~]# lvreduce -L 5G /dev/mapper/myvg1-mylv1 #缩减/dev/mapper/myvg1-mylv1 逻辑卷到5G大小 resize2fs 1.41.12 (17-May-2010) WARNING: Reducing active logical volume to 5.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce myvg1/mylv1? [y/n]: y Size of logical volume myvg1/mylv1 changed from 10.00 GiB (2560 extents) to 5.00 GiB (1280 extents). Logical volume mylv1 successfully resized. [[email protected] ~]# lvreduce /dev/mapper/myvg2-mylv2 -L 15G WARNING: Reducing active logical volume to 15.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce myvg2/mylv2? [y/n]: y Size of logical volume myvg2/mylv2 changed from 70.00 GiB (17920 extents) to 15.00 GiB (3840 extents). Logical volume mylv2 successfully resized. [[email protected] ~]# mount /dev/mapper/myvg1-mylv1 /dev/lvm1 #挂载磁盘 [[email protected] ~]# mount /dev/mapper/myvg2-mylv2 /dev/lvm2 [[email protected] ~]# df -TH #查看磁盘空间 Filesystem Type Size Used Avail Use% Mounted on /dev/sda3 ext4 21G 1.2G 19G 7% / tmpfs tmpfs 1.3G 0 1.3G 0% /dev/shm /dev/mapper/myvg1-mylv1 ext4 5.2G 36M 4.9G 1% /dev/lvm1 /dev/mapper/myvg2-mylv2 ext4 16G 44M 15G 1% /dev/lvm2
说明:# e2fsck -f /dev/mapper/myvg1-mylv1 强制检查文件系统; -f 强制
# resize2fs /dev/mapper/myvg1-mylv1 5G 缩减文件系统为5G 。
#lvextend -L 5G /dev/myvg1-mylv1 分配到mylv1逻辑卷大小为5G; -L 分配容量大小
七、扩展或缩减myvg1、myvg2 卷组
[[email protected] ~]# vgs #查看vg状态 VG #PV #LV #SN Attr VSize VFree myvg1 2 1 0 wz--n- 39.98g 34.98g myvg2 4 1 0 wz--n- 79.97g 64.97g [[email protected] ~]# pvs #查看PV状态 ,可以看出/myvg1-mylv1 中/dev/sdb1 物理卷处于空闲状态,/myvg2-mylv2 中/dev/sd{e..g}1 物理卷处于空闲状态 PV VG Fmt Attr PSize PFree /dev/sdb1 myvg1 lvm2 a--u 19.99g 19.99g /dev/sdc1 myvg1 lvm2 a--u 19.99g 14.99g /dev/sdd1 myvg2 lvm2 a--u 19.99g 4.99g /dev/sde1 myvg2 lvm2 a--u 19.99g 19.99g /dev/sdf1 myvg2 lvm2 a--u 19.99g 19.99g /dev/sdg1 myvg2 lvm2 a--u 19.99g 19.99g [[email protected] ~]# vgreduce myvg1 /dev/sdb1 #删减卷组myvg1 中的/dev/sdb1 物理卷 Removed "/dev/sdb1" from volume group "myvg1" [[email protected] ~]# vgreduce myvg2 /dev/sd{e..g}1 Removed "/dev/sde1" from volume group "myvg2" Removed "/dev/sdf1" from volume group "myvg2" Removed "/dev/sdg1" from volume group "myvg2" [[email protected] ~]# pvs #查看状态 PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 ---- 19.99g 19.99g /dev/sdc1 myvg1 lvm2 a--u 19.99g 14.99g /dev/sdd1 myvg2 lvm2 a--u 19.99g 4.99g /dev/sde1 lvm2 ---- 19.99g 19.99g /dev/sdf1 lvm2 ---- 19.99g 19.99g /dev/sdg1 lvm2 ---- 19.99g 19.99g [[email protected] ~]# vgextend myvg1 /dev/sdb1 #增添卷组myvg1 中的/dev/sdb1 物理卷 Volume group "myvg1" successfully extended [[email protected] ~]# vgextend myvg2 /dev/sd{e..g}1 Volume group "myvg2" successfully extended [[email protected] ~]# pvs #查看状态 PV VG Fmt Attr PSize PFree /dev/sdb1 myvg1 lvm2 a--u 19.99g 19.99g /dev/sdc1 myvg1 lvm2 a--u 19.99g 14.99g /dev/sdd1 myvg2 lvm2 a--u 19.99g 4.99g /dev/sde1 myvg2 lvm2 a--u 19.99g 19.99g /dev/sdf1 myvg2 lvm2 a--u 19.99g 19.99g /dev/sdg1 myvg2 lvm2 a--u 19.99g 19.99g
八、卸载删除lVM
[[email protected] ~]# umount /dev/mapper/myvg1-mylv1 #卸载逻辑卷 [[email protected] ~]# lvremove /dev/mapper/myvg1-mylv1 #移除LVM Do you really want to remove active logical volume mylv1? [y/n]: y Logical volume "mylv1" successfully removed [[email protected] ~]# vgremove myvg1 #移除VG Volume group "myvg1" successfully removed [[email protected] ~]# pvremove /dev/sd{b,c}1 #移除PV Labels on physical volume "/dev/sdb1" successfully wiped Labels on physical volume "/dev/sdc1" successfully wiped
至此 ,实验完成 。
本文出自 “Wish_亮” 博客,请务必保留此出处http://itwish.blog.51cto.com/11439802/1968271
以上是关于Linux 服务器配置LVM(逻辑卷管理)的主要内容,如果未能解决你的问题,请参考以下文章