lvm拉伸与快照
一.拉伸
*用fdisk分区
*构建pv
*将pv加入vg
*将pv内的pe加入lv
*通过resize将文件系统的容量增加
1.分区
[root@server3 ~]# fdisk /dev/vdb
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.
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (8394752-20971519, default 8394752):
Using default value 8394752
Last sector, +sectors or +size{K,M,G} (8394752-20971519, default 20971519): +1G
Partition 6 of type Linux and of size 1 GiB is set
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa859763d
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 8e Linux LVM
/dev/vdb2 2099200 4196351 1048576 8e Linux LVM
/dev/vdb3 4196352 6293503 1048576 8e Linux LVM
/dev/vdb4 6293504 20971519 7339008 5 Extended
/dev/vdb5 6295552 8392703 1048576 8e Linux LVM
/dev/vdb6 8394752 10491903 1048576 83 Linux
Command (m for help): t
Partition number (1-6, default 6): 6
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa859763d
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 8e Linux LVM
/dev/vdb2 2099200 4196351 1048576 8e Linux LVM
/dev/vdb3 4196352 6293503 1048576 8e Linux LVM
/dev/vdb4 6293504 20971519 7339008 5 Extended
/dev/vdb5 6295552 8392703 1048576 8e Linux LVM
/dev/vdb6 8394752 10491903 1048576 8e Linux LVM
2.构建pv
[root@server3 ~]# pvcreate /dev/vdb6
Physical volume "/dev/vdb6" successfully created.
[root@server3 ~]# pvscan
PV /dev/vdb1 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb2 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb3 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb5 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb6 lvm2 [1.00 GiB]
Total: 5 [4.94 GiB] / in use: 4 [3.94 GiB] / in no VG: 1 [1.00 GiB]
3.将pv加入vg
[root@server3 ~]# vgextend vgn /dev/vdb6
Volume group "vgn" successfully extended
[root@server3 ~]# vgdisplay
--- Volume group ---
VG Name vgn
System ID
Format lvm2
Metadata Areas 5
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 5
Act PV 5
VG Size 4.92 GiB
PE Size 16.00 MiB
Total PE 315
Alloc PE / Size 252 / 3.94 GiB
Free PE / Size 63 / 1008.00 MiB **这里显示的时未使用的pe,-l参数可以看这里
VG UUID JjHOlH-RdcV-71dR-4wmK-NQ3N-pnRS-1y5dIV
4.将pv内的pe加入lv
[root@server3 ~]# lvresize -l +63 /dev/vdb
/dev/vdb1 /dev/vdb2 /dev/vdb3 /dev/vdb5 /dev/vdb6
[root@server3 ~]# lvresize -l +63 /dev/vgn/lvn
Size of logical volume vgn/lvn changed from 3.94 GiB (252 extents) to 4.92 GiB (315 extents).
Logical volume vgn/lvn successfully resized.
[root@server3 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgn/lvn
LV Name lvn
VG Name vgn
LV UUID 3cZBXM-Ef2z-wDLR-Fyxx-TmzD-Payq-BJ6eTm
LV Write Access read/write
LV Creation host, time server3, 2019-01-21 20:32:58 +0800
LV Status available
# open 1
LV Size 4.92 GiB
Current LE 315
Segments 5
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
5.文件系统的扩展
[root@server3 ~]# df -h
/dev/mapper/vgn-lvn 3.9G 16M 3.6G 1% /mnt/lvm
[root@server3 ~]# resize2fs /dev/vgn/lvn
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vgn/lvn is mounted on /mnt/lvm; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vgn/lvn is now 1290240 blocks long.
[root@server3 ~]# df -h /dev/vgn/lvn
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgn-lvn 4.8G 16M 4.6G 1% /mnt/lvm
二.缩小LV容量
[root@server3 ~]# pvscan
PV /dev/vdb1 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb2 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb3 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb5 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb6 VG vgn lvm2 [1008.00 MiB / 0 free]
Total: 5 [4.92 GiB] / in use: 5 [4.92 GiB] / in no VG: 0 [0 ]
[root@server3 ~]# umount /dev/vgn/lvn
[root@server3 ~]# resize2fs /dev/vgn/lvn 4032M
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vgn/lvn' first.
[root@server3 ~]# e2fsck -f /dev/vgn/lvn
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/vgn/lvn: 11/322560 files (0.0% non-contiguous), 40670/1290240 blocks
[root@server3 ~]# resize2fs /dev/vgn/lvn 4032M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vgn/lvn to 1032192 (4k) blocks.
The filesystem on /dev/vgn/lvn is now 1032192 blocks long.
[root@server3 ~]# mount /dev/vgn/lvn /mnt/lvm
[root@server3 ~]# df -h /mnt/lvm/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgn-lvn 3.9G 16M 3.6G 1% /mnt/lvm
可以通过pvdisplay查看pe个数
[root@server3 ~]# lvresize -l 63 /dev/vgn/lvn
WARNING: Reducing active and open logical volume to 1008.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgn/lvn? [y/n]: y
Size of logical volume vgn/lvn changed from 4.92 GiB (315 extents) to 1008.00 MiB (63 extents).
Logical volume vgn/lvn successfully resized.
[root@server3 ~]# pvscan
PV /dev/vdb1 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb2 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb3 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb5 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb6 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
Total: 5 [4.92 GiB] / in use: 5 [4.92 GiB] / in no VG: 0 [0 ]
[root@server3 ~]# pvmove /dev/vdb1 /dev/vdb6
/dev/vdb1: Moved: 7.94%
/dev/vdb1: Moved: 100.00%
[root@server3 ~]# vgreduce vgn /dev/vdb1
Removed "/dev/vdb1" from volume group "vgn"
[root@server3 ~]# pvscan
PV /dev/vdb2 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb3 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb5 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb6 VG vgn lvm2 [1008.00 MiB / 0 free]
PV /dev/vdb1 lvm2 [1.00 GiB]
Total: 5 [4.94 GiB] / in use: 4 [3.94 GiB] / in no VG: 1 [1.00 GiB]
[root@server3 ~]# pvremove /dev/vdb1
Labels on physical volume "/dev/vdb1" successfully wiped.
[root@server3 ~]# pvscan
PV /dev/vdb2 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb3 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb5 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdb6 VG vgn lvm2 [1008.00 MiB / 0 free]
Total: 4 [3.94 GiB] / in use: 4 [3.94 GiB] / in no VG: 0 [0 ]
三.lvm系统快照
1.快照区的创建
[root@server3 ~]# vgdisplay
--- Volume group ---
VG Name vgn
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 10
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 3.94 GiB
PE Size 16.00 MiB
Total PE 252
Alloc PE / Size 63 / 1008.00 MiB
Free PE / Size 189 / 2.95 GiB
VG UUID JjHOlH-RdcV-71dR-4wmK-NQ3N-pnRS-1y5dIV
[root@server3 ~]# lvcreate -l 80 -s -n vv /dev/vgn/lvn
Using default stripesize 64.00 KiB.
Reducing COW size 1.25 GiB down to maximum usable size 1.00 GiB.
Logical volume "vv" created.
[root@server3 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgn/lvn
LV Name lvn
VG Name vgn
LV UUID 3cZBXM-Ef2z-wDLR-Fyxx-TmzD-Payq-BJ6eTm
LV Write Access read/write
LV Creation host, time server3, 2019-01-21 20:32:58 +0800
LV snapshot status source of
vv [active]
LV Status available
# open 1
LV Size 1008.00 MiB
Current LE 63
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
--- Logical volume ---
LV Path /dev/vgn/vv
LV Name vv
VG Name vgn
LV UUID az5JDg-Njjn-c51c-qdzc-ItEl-pLme-9RHnA7
LV Write Access read/write
LV Creation host, time server3, 2019-01-22 17:40:43 +0800
LV snapshot status active destination for lvn
LV Status available
# open 0
LV Size 1008.00 MiB
Current LE 63
COW-table size 1.00 GiB **快照区的实际容量
COW-table LE 64 **快照区占用的PE数量
Allocated to snapshot 0.00%
Snapshot chunk size 4.00 KiB
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:3
挂载查看一下,发现数据与原本的lvn相同
[root@server3 ~]# mkfs.ext4 /dev/vgn/vv
[root@server3 ~]# mount /dev/vgn/vv /mnt/ks/
[root@server3 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda3 20243456 3441148 16802308 17% /
devtmpfs 493580 0 493580 0% /dev
tmpfs 508248 84 508164 1% /dev/shm
tmpfs 508248 13568 494680 3% /run
tmpfs 508248 0 508248 0% /sys/fs/cgroup
/dev/vda1 201380 133424 67956 67% /boot
tmpfs 101652 20 101632 1% /run/user/42
tmpfs 101652 0 101652 0% /run/user/0
/dev/mapper/vgn-lvn 3998400 16120 3769816 1% /mnt/lvm
/dev/mapper/vgn-vv 999576 2524 929060 1% /mnt/ks
2.利用快照区复原系统
改变/mnt/lvm中的数据内容,然后再以快照还原
[root@server3 mnt]# df /mnt/lvm/ /mnt/ks/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vgn-lvn 999576 48280 883304 6% /mnt/lvm
/dev/mapper/vgn-vv 999576 2524 929060 1% /mnt/ks
[root@server3 mnt]# lvdisplay
......
--- Logical volume ---
LV Path /dev/vgn/vv
LV Name vv
VG Name vgn
......
Allocated to snapshot 7.56% 快照已被使用了7.56%
Snapshot chunk size 4.00 KiB
......
[root@server3 /]# mkdir /backup **创建一个目录来备份
[root@server3 mnt]# cd /mnt/ks
[root@server3 ks]# tar -jcvf /backup/lvm.tar.bz2 *
[root@server3 backup]# umount /mnt/ks/ **数据已备份,将快照删除
[root@server3 backup]# lvremove /dev/vgn/vv
Do you really want to remove active logical volume vgn/vv? [y/n]: y
Logical volume "vv" successfully removed
[root@server3 backup]# umount /mnt/lvm/
[root@server3 backup]# mkfs.ext4 /dev/vgn/lvn **将原本的lv格式化
[root@server3 backup]# mount /dev/vgn/lvn /mnt/lvm/
[root@server3 backup]# tar -jxvf /backup/lvm.tar.bz2 -C /mnt/lvm/
[root@server3 backup]# ll /mnt/lvm/
total 16
drwx------ 2 root root 16384 Jan 22 17:45 lost+found
[root@server3 backup]# df /mnt/lvm/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vgn-lvn 999576 2524 929060 1% /mnt/lvm
发现数据还原
lvm拉伸与快照的更多相关文章
- GNU/Linux下LVM配置管理以及快照卷、物理卷、卷组、逻辑卷的创建和删除
LVM是Linux环境中对磁盘分区进行管理的一种机制,是建立在硬盘和分区之上.文件系统之下的一个逻辑层,可提高磁盘分区管理的灵活性.最大的优点是在不损伤数据的前提下调整存储空间的大小. 本篇主要讲述L ...
- lvm拉伸逻辑卷分区小总结
文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/vg_znl-lv_root ...
- Linux磁盘管理之LVM逻辑卷快照
一.快照的工作原理 所谓快照就是将当时的系统数据记录下来,在未来若有数据变动,则会将变更前的数据放入快照区进行保存.我们可理解为快照就是给系统拍了一张照片,记录当时系统在拍快照的状态.只不过现实生活中 ...
- lvm创建和快照
查看磁盘 创建分区 新建1G的1分区 新建1G的2分区 新建1G的3分区 查看新建的分区 因标准分区是83交换分区是82做lv是8e所以要改变类型 查看: 保存退出: 创建物理卷pv 将物理卷pv创建 ...
- lvm之创建/扩容/缩容/快照及关闭的全部流程操作记录
基本介绍Linux用户安装Linux 操作系统时遇到的一个最常见的难以决定的问题就是如何正确地给评估各分区大小,以分配合适的硬盘空间.随着 Linux的逻辑盘卷管理功能的出现,这些问题都迎刃而解, l ...
- LVM常规操作记录梳理(扩容/缩容/快照等)
基本介绍Linux用户安装Linux 操作系统时遇到的一个最常见的难以决定的问题就是如何正确地给评估各分区大小,以分配合适的硬盘空间.随着 Linux的逻辑盘卷管理功能的出现,这些问题都迎刃而解, l ...
- 基于LVM卷的MYSQL快照恢复
在mysql数据库环境中,如果数据库数据很重要,可以使用LVM卷管理的方式,通过对数据卷进行快照,得到快速备份的目的, 首先回顾一下LVM卷管理的几个概念: 物理磁盘PD,physical disk, ...
- LVM : 快照
LVM 机制还提供了对 LV 做快照的功能,也就是说可以给文件系统做一个备份,这也是设计 LVM 快照的主要目的.LVM 的快照功能采用写时复制技术(Copy-On-Write,COW),这比传统的备 ...
- 使用LVM快照进行数据库备份
使用mysqldump备份时,如果存储引擎为MyISAM,则只能实现温备份,并需使用选项--lock-all-tables锁定所有表.如果存储引擎为InnoDB,则加上--single-transac ...
随机推荐
- DataTable数据分页
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Refle ...
- VMware联网问题
VMware 服务启动优化当虚拟机连不上网,或不显示ip时,先查看vm服务是否启动.控制台运行:services.msc 以下为改为手工启动:1.VMware 服务自动启动影响计算机启动速度,再此对V ...
- 团体程序设计天梯赛L2-002 链表去重 2017-03-22 18:12 25人阅读 评论(0) 收藏
L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...
- <a>标签的用法以及[@text_cut]
<a href="${a.url}" target="_blank">[@text_cut s=a.title len=titLen append= ...
- Delphi iOS & macOS App 名称支持国际化多语显示
作用:在 OSX 图标下方显示 App 中文繁体或简体的名称(系统自动选取) 适用:XE7, XE8 for OSX 操作: 创建一个新工程. 在工程目录下创建二个文件夹(zh_??.lproj)文件 ...
- [LeetCode 题解]: Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- 解决Struts2拦截器的对于参数传递无效问题
今天做项目时,使用拦截器对用户权限检查.拦截器本身没有问题,可是实现权限拦截,但是传递的参数全部都无效了.搞了很久,由于对拦截器的内部机制不是特别熟悉,所以重新研读了一下Struts2的拦截器.找到了 ...
- ASP.NET MVC中的控制器激活与反射之间的联系(帮助理解)
ASP.NET Mvc是ASP.NET的一个框架,同样也是基于管道的设计结构.HttpModule和HttpHandler是ASP.NET的两个重要组件,同样的在Mvc中也是非常重要的组件.在应用程序 ...
- webservice 创建及调用
1.创建一个空白项目 2.在此项目上新建项--添加一个web服务 (.asmx) 这样就创建好了一个webservice --------------------------------------- ...
- Asp.Net Core下的两种路由配置方式
与Asp.Net Mvc创建区域的时候会自动为你创建区域路由方式不同的是,Asp.Net Core下需要自己手动做一些配置,但更灵活了. 我们先创建一个区域,如下图 然后我们启动访问/Manage/H ...