一、逻辑卷扩展

[root@lxjtest /]# umount /testLVM/
[root@lxjtest /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root .7G 896M .9G % /
devtmpfs 910M 910M % /dev
tmpfs 920M 920M % /dev/shm
tmpfs 920M 8.4M 912M % /run
tmpfs 920M 920M % /sys/fs/cgroup
/dev/sda1 297M 114M 184M % /boot
tmpfs 184M 184M % /run/user/
[root@lxjtest /]#

第1步:把上个试验中的逻辑卷fuck_lv1扩展至300MB

[root@lxjtest /]# lvdisplay testVG
--- Logical volume ---
LV Path /dev/testVG/fuck_lv1
LV Name fuck_lv1
VG Name testVG
LV UUID RKzHdO-NX2i-Za40-kWNg-RIox-yi9j-z9251R
LV Write Access read/write
LV Creation host, time lxjtest.rusky.com, -- :: -
LV Status available
# open
LV Size 200.00 MiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : [root@lxjtest /]# lvs testVG
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
fuck_lv1 testVG -wi-a----- 200.00m
[root@lxjtest /]# lvextend -L 300M /dev/testVG/fuck_lv1
Size of logical volume testVG/fuck_lv1 changed from 200.00 MiB ( extents) to 300.00 MiB ( extents).
Logical volume fuck_lv1 successfully resized.
[root@lxjtest /]# lvs testVG
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
fuck_lv1 testVG -wi-a----- 300.00m
[root@lxjtest /]#

第2步:检查磁盘容量,重置磁盘容量

[root@lxjtest /]# e2fsck -f /dev/testVG/fuck_lv1
e2fsck 1.42. (-Dec-)
Pass : Checking inodes, blocks, and sizes
Pass : Checking directory structure
Pass : Checking directory connectivity
Pass : Checking reference counts
Pass : Checking group summary information
/dev/testVG/fuck_lv1: / files (0.0% non-contiguous), / blocks
[root@lxjtest /]# resize2fs /dev/testVG/fuck_lv1
resize2fs 1.42. (-Dec-)
Resizing the filesystem on /dev/testVG/fuck_lv1 to (1k) blocks.
The filesystem on /dev/testVG/fuck_lv1 is now blocks long.

第3步:重新挂载硬盘设备并查看挂载状态

[root@lxjtest /]# mount -a
[root@lxjtest /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root .7G 897M .9G % /
devtmpfs 910M 910M % /dev
tmpfs 920M 920M % /dev/shm
tmpfs 920M 8.4M 912M % /run
tmpfs 920M 920M % /sys/fs/cgroup
/dev/sda1 297M 114M 184M % /boot
tmpfs 184M 184M % /run/user/
/dev/mapper/testVG-fuck_lv1 287M 2.1M 266M % /testLVM

二、逻辑卷收缩

缩小逻辑卷之前,先备份数据,然后检查文件系统完整性,再卸载文件系统,之后再来压缩。

[root@lxjtest /]# umount /testLVM/
[root@lxjtest /]# e2fsck -f /dev/testVG/fuck_lv1
e2fsck 1.42. (-Dec-)
Pass : Checking inodes, blocks, and sizes
Pass : Checking directory structure
Pass : Checking directory connectivity
Pass : Checking reference counts
Pass : Checking group summary information
/dev/testVG/fuck_lv1: / files (0.0% non-contiguous), / blocks
[root@lxjtest /]# resize2fs /dev/testVG/fuck_lv1 100M
resize2fs 1.42. (-Dec-)
Resizing the filesystem on /dev/testVG/fuck_lv1 to (1k) blocks.
The filesystem on /dev/testVG/fuck_lv1 is now blocks long. [root@lxjtest /]# lvreduce -L 100M /dev/testVG/fuck_lv1
WARNING: Reducing active logical volume to 100.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce fuck_lv1? [y/n]: y
Size of logical volume testVG/fuck_lv1 changed from 300.00 MiB ( extents) to 100.00 MiB ( extents).
Logical volume fuck_lv1 successfully resized.
[root@lxjtest /]# lvs testVG
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
fuck_lv1 testVG -wi-a----- 100.00m
[root@lxjtest /]#

最后,重新挂载并查看文件系统:

[root@lxjtest /]# mount -a
[root@lxjtest /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root .7G 896M .9G % /
devtmpfs 910M 910M % /dev
tmpfs 920M 920M % /dev/shm
tmpfs 920M 8.4M 912M % /run
tmpfs 920M 920M % /sys/fs/cgroup
/dev/sda1 297M 114M 184M % /boot
tmpfs 184M 184M % /run/user/
/dev/mapper/testVG-fuck_lv1 93M 1.6M 85M % /testLVM

三、逻辑卷快照

LVM逻辑卷管理器还具备有“快照卷”的功能,这项功能很类似于虚拟机软件的还原时间点功能。例如可以对某一个LV逻辑卷设备做一次快照,如果今后发现数据被改错了,咱们可以把之前做好的快照卷进行覆盖还原,LVM逻辑卷管理器的快照功能有两项特点,第一是快照卷的大小应该尽量等同于LV逻辑卷的容量,第二是快照功能仅一次有效,一旦被还原后则会被自动立即删除,首先应当查看下卷组的信息:

[root@lxjtest testLVM]# ls -lht
total 46M
drwx------. root root 12K Aug : lost+found
-rw-r--r--. root root 46M Apr firefox-37.0..tar.bz2
[root@lxjtest testLVM]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root .7G 898M .9G % /
devtmpfs 910M 910M % /dev
tmpfs 920M 920M % /dev/shm
tmpfs 920M 8.4M 912M % /run
tmpfs 920M 920M % /sys/fs/cgroup
/dev/sda1 297M 114M 184M % /boot
tmpfs 184M 184M % /run/user/
/dev/mapper/testVG-fuck_lv1 93M 48M 39M % /testLVM
/dev/sr0 .8G .8G % /mnt

在创建快照前,先在/testLVM中放入一些文件,以对比快照还原结果

[root@lxjtest testLVM]# pwd
/testLVM
[root@lxjtest testLVM]# ls -lht
total 46M
drwx------. root root 12K Aug : lost+found
-rw-r--r--. root root 46M Apr firefox-37.0..tar.bz2

第1步:使用-s参数来生成一个快照卷,使用-L参数来指定切割的大小,另外要记得在后面写上这个快照是针对那个LV逻辑卷设备做的。

[root@lxjtest testLVM]# lvcreate -L 100M -s -n SNAP /dev/testVG/fuck_lv1
Logical volume "SNAP" created.
  --- Logical volume ---
LV Path /dev/testVG/fuck_lv1
LV Name fuck_lv1
VG Name testVG
LV UUID RKzHdO-NX2i-Za40-kWNg-RIox-yi9j-z9251R
LV Write Access read/write
LV Creation host, time lxjtest.rusky.com, -- :: -
LV snapshot status source of
SNAP [active]
LV Status available
# open
LV Size 100.00 MiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/testVG/SNAP
LV Name SNAP
VG Name testVG
LV UUID 7eeuaw-FMmH-KA1o-45CG-0x4J-B3tK-AOJqFv
LV Write Access read/write
LV Creation host, time lxjtest.rusky.com, -- :: -
LV snapshot status active destination for fuck_lv1
LV Status available
# open
LV Size 100.00 MiB
Current LE
COW-table size 100.00 MiB
COW-table LE
Allocated to snapshot 0.09%
Snapshot chunk size 4.00 KiB
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :
(略)

快照创建完成之后,删除之前在/testLVM中放入的文件。下面我们使用快照卷SNAP来还原之前的文件。

第2步:为了校验SNAP快照卷的效果,需要对逻辑卷进行快照合并还原操作,在这之前记得先卸载掉逻辑卷设备与目录的挂载~

[root@lxjtest /]# cd testLVM/
[root@lxjtest testLVM]#rm firefox-37.0..tar.bz2 --删除原文件
[root@lxjtest testLVM]#touch testNewFile --创建新文件
[root@lxjtest testLVM]# ls
lost+found tesstNewFile
[root@lxjtest testLVM]# cd /
[root@lxjtest /]# umount /testLVM/ --卸载
[root@lxjtest /]# lvconvert --merge /dev/testVG/SNAP --快照还原
Merging of volume SNAP started.
fuck_lv1: Merged: 99.9%
fuck_lv1: Merged: 100.0%
[root@lxjtest /]# mount -a
[root@lxjtest /]# cd testLVM/
[root@lxjtest testLVM]# ls --原文件已被还原出来。
firefox-37.0..tar.bz2 lost+found

lvconvert之后,快照卷/dev/testVG/SNAP会被自动删除掉,并且刚刚在逻辑卷设备被快照后再创建出来的100M垃圾文件也被清除了。

[root@lxjtest testLVM]# lvdisplay
--- Logical volume ---
LV Path /dev/testVG/fuck_lv1
LV Name fuck_lv1
VG Name testVG
LV UUID RKzHdO-NX2i-Za40-kWNg-RIox-yi9j-z9251R
LV Write Access read/write
LV Creation host, time lxjtest.rusky.com, -- :: -
LV Status available
# open
LV Size 100.00 MiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :
(略)
[root@lxjtest testLVM]#

四、删除逻辑卷

当生产环境中想要重新部署或者不需要再继续使用LVM逻辑卷管理器了,除了提前备份好重要数据信息,还必须依次删除LV逻辑卷、VG卷组后再移除PV物理卷设备,这样的顺序不可颠倒。

第1步:取消逻辑卷与目录的挂载关联,删除配置文件中永久生效的设备参数。

[root@lxjtest ~]# umount /testLVM/
[root@lxjtest ~]# vi /etc/fstab #
# /etc/fstab
# Created by anaconda on Tue Aug ::
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(), findfs(), mount() and/or blkid() for more info
#
/dev/mapper/rhel-root / xfs defaults
UUID=e7987771-c54c-4b36-8a5c-8e71f129c3fe /boot xfs defaults
/dev/mapper/rhel-swap swap swap defaults
#/dev/testVG/fuck_lv1 /testLVM ext4 defaults
#删除或注释该行

第2步:把LV逻辑卷设备删除,需要手工输入y来确认操作

[root@lxjtest ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testVG/fuck_lv1
LV Name fuck_lv1
VG Name testVG
LV UUID RKzHdO-NX2i-Za40-kWNg-RIox-yi9j-z9251R
LV Write Access read/write
LV Creation host, time lxjtest.rusky.com, -- :: -
LV Status available
# open
LV Size 100.00 MiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :
(略)
[root@lxjtest ~]# lvremove /dev/testVG/fuck_lv1
Do you really want to remove active logical volume fuck_lv1? [y/n]: y
Logical volume "fuck_lv1" successfully removed
[root@lxjtest ~]#

第3步:把VG卷组删除,此处只需写卷组名称即可,而无需设备完整绝对路径

[root@lxjtest ~]# vgdisplay
--- Volume group ---
VG Name testVG
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 3.99 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size /
Free PE / Size / 3.99 GiB
VG UUID b3mykq-kcsp-Hdh4-rAos-vutt-ontI-6AWJ5K
(略)
[root@lxjtest ~]#
[root@lxjtest ~]# vgremove testVG
Volume group "testVG" successfully removed
[root@lxjtest ~]#

第4步:把PV物理卷设备移除:

[root@lxjtest ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size 4.71 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE
Free PE
Allocated PE
PV UUID V3kA1X-l7dr-03p4-HZcu-Ebj3-FRvb-r5vGMd "/dev/sdb" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size
Total PE
Free PE
Allocated PE
PV UUID InfACr-fq1t-yi95-K1K3-dOHU-uezl-gfiPVa "/dev/sdc" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size
Total PE
Free PE
Allocated PE
PV UUID aOtJga-uWop-ldnv-xIcj-TcLE-aq18-SrJO3p [root@lxjtest ~]# pvremove /dev/sdb /dev/sdc
Labels on physical volume "/dev/sdb" successfully wiped
Labels on physical volume "/dev/sdc" successfully wiped
[root@lxjtest ~]#

可以再分别执行下lvdisplay、vgdisplay、pvdisplay命令来查看逻辑卷管理器信息,操作正确则会不能再看到我们创建的逻辑卷设备信息了。

LVM逻辑卷管理测试——逻辑卷扩展、收缩、快照及删除的更多相关文章

  1. LVM逻辑卷管理测试——创建逻辑卷

    虚拟机里再添加两块硬盘,如下所示: 启动系统后,我们可以看到新添加的两块硬盘为/dev/sdb和/dev/sdc.每个2GB. [root@lxjtest ~]# fdisk -l Disk /dev ...

  2. LINUX逻辑卷(LVM)管理与逻辑卷分区

    LINUX之逻辑卷管理与逻辑卷扩展 LVM是逻辑卷管理(Logical Volume Manager)的简称,他是建立在物理存储设备之上的一个抽象层,允许你生成逻辑存储卷,和直接使用物理存储在管理上相 ...

  3. linux逻辑卷管理(LVM)

    1. 逻辑卷(LVM)的原理 LVM(Logical Volume Manager)逻辑卷管理 是在物理磁盘和文件系统的之间添加一个逻辑层,通过对底层物理磁盘的封装,以逻辑卷的方式呈现给上层应用,通过 ...

  4. 存储5——逻辑卷管理LVM

    1. LVM概念 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它由Heinz Mauelshagen在Linux 2.4内核上实现.LVM将一个或多个硬盘的分区在逻辑上 ...

  5. 文件系统之LVM 逻辑卷管理

    1. LVM介绍 LVM 是 Logical Volume Manager 的简称,中文就是逻辑卷管理. 物理卷(PV,Physical Volume):就是真正的物理硬盘或分区. 卷组(VG,Vol ...

  6. 逻辑卷管理-LVM(Logical Volume Manager)

    一. 概念与由来 LVM:逻辑卷管理(Logical Volume Manager) 普通的磁盘分区管理方式在逻辑分区划分好之后就无法改变其大小,当一个逻辑分区存放不下某文件时,这个文件因为受上层文件 ...

  7. Linux基础学习-LVM逻辑卷管理遇到的问题

    LVM学习逻辑卷管理创建逻辑卷遇到的问题 1 实验环境 系统 内核 发行版本 CentOS 2.6.32-754.2.1.el6.x86_64 CentOS release 6.10 (Final) ...

  8. lvm - Logical Volume Manager - 逻辑卷管理

    下午突然感觉 lvm 相关的知识忘记了,恰好机房里的fedora服务器上 挂了4个500GB的HDD 硬盘没有使用,就拿来操作了一番: 下面有几篇关于lvm不错的文章,进行了链接,网上也有很多不错的博 ...

  9. 【Linux卷管理】LVM原理

    LVM 简介 每个Linux使用者在安装Linux时 都会遇到这样的困境:在为系统分区时,如何精确评估和分配各个硬盘分区的容量,因为系统管理员不但要考虑到当前某个分区需要的容量,还要预见该分区以后可能 ...

随机推荐

  1. [转]使用互斥对象让程序只运行一次(delphi)

    使用互斥对象让程序只运行一次“怎么让我的程序在运行时不能重复打开?”经常在论坛上看到有朋友问这方面的问题.本文将比较详细的说明这一问题,并给出一个较为完善的解决方案. 尽管这已经不是一个新问题了,但这 ...

  2. 算法:快速排序实现 & 定制比较函数

    1. 快速排序基本算法 #include<stdio.h> ; int quick_sort(int *a, int start, int end){ if (start >= en ...

  3. go语言之进阶篇通过if实现类型断言

    1.通过if实现类型断言 示例: package main import "fmt" type Student struct { name string id int } func ...

  4. 8Manage PMP 项目管理工具

    范围与需求管理 8Manage 项目管理平台提供先进的机制集中管理项目的范围与需求: 提供需求申请功能:获取,过滤,解析和明确项目的需求 提供需求矩阵功能:整理分析需求并跟踪需求从开始到完成的整个过程 ...

  5. [leetcode]Add Binary @ Python

    原题地址:https://oj.leetcode.com/problems/add-binary/ 题意: Given two binary strings, return their sum (al ...

  6. Recover Binary Search Tree leetcode java

    题目: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without chan ...

  7. 二叉树 遍历 先序 中序 后序 深度 广度 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. 别再为了this发愁了:JS中的this机制

    题记:JavaScript中有很多令人困惑的地方,或者叫做机制.但是,就是这些东西让JavaScript显得那么美好而与众不同.比方说函数也是对象.闭包.原型链继承等等,而这其中就包括颇让人费解的th ...

  9. extern外部方法使用C#简单例子

    外部方法使用C#简单例子 1.增加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", ...

  10. 屌丝就爱尝鲜头——java8初体验

    Java8已经推出,让我们看看他的魅力.让我们看看他改变较大的部分. 一.java8概述 Java8是由Oracle(甲骨文)公司与2014年3月27日正式推出的.Java8同时推出有3套语言系统,分 ...