一、逻辑卷扩展

[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. Django查询 – id vs pk

    当编写django查询时,可以使用id / pk作为查询参数. Object.objects.get(id=1) Object.objects.get(pk=1) pk代表主键(primary key ...

  2. 【转】Delphi"配置系统未能初始化"

    好久没用DelphiXE8了,最近打开一看,在启动时报错了“配置系统未能初始化”,在网上一搜,有各种种样的说法,大体上是与.net的Framewok相关,照着一个一个地试了下,还是解决不了这个错误.有 ...

  3. 5.数字拆分成4段,怎样使得4段的乘积最小【dp】

    题目是:给出一个数字(10,000-100,000,000),把这个数字拆分成4段,怎样使得4段的乘积最小.比如12345拆分成1*2*3*45=270, 10000=1*00*0*0=0. 解题分析 ...

  4. File targeting 'AMD64' is not compatible with the project's target platform 'x86' 解决方法

     我在使用vs2010制作64位安装包时出现了以下问题: File targeting 'AMD64' is not compatible with the project's target plat ...

  5. 如何解决在Windows Server 2008 R2 上安装证书服务重启后出现 CertificationAuthority 91错误事件

    很久都没写什么博客了,前一段时间学习2008 R2时,在自己的电脑上同时安装AD 和证书 往往会出现一个CertificationAuthority错误,如下: 产生问题的主要原因是: 证书服务器与D ...

  6. 【Scala】Java-Scala-单例模式实现方法

    Java-Scala-单例模式实现方法 scala 单例_百度搜索 scala实现单例模式-博客-云栖社区-阿里云

  7. IE下推断IE版本号的语句

    样例: 1. <!--[if !IE]> 除IE外都可识别 <![endif]--> 2. <!--[if IE]> 全部的IE可识别 <![endif]-- ...

  8. C++ 对象的定义

    1.考虑下面的方法void Print(const Student& s){ printf("Student[%s:%d]\n", s._Name.c_str(), s._ ...

  9. Invalid volume failure config value: 1

    原因: hdfs-site.xml中的配置为: <property> <name>dfs.datanode.failed.volumes.tolerated</name& ...

  10. 【LeetCode】String to Integer (atoi) 解题报告

    这道题在LeetCode OJ上难道属于Easy.可是通过率却比較低,究其原因是须要考虑的情况比較低,非常少有人一遍过吧. [题目] Implement atoi to convert a strin ...