一.拉伸

*用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拉伸与快照的更多相关文章

  1. GNU/Linux下LVM配置管理以及快照卷、物理卷、卷组、逻辑卷的创建和删除

    LVM是Linux环境中对磁盘分区进行管理的一种机制,是建立在硬盘和分区之上.文件系统之下的一个逻辑层,可提高磁盘分区管理的灵活性.最大的优点是在不损伤数据的前提下调整存储空间的大小. 本篇主要讲述L ...

  2. lvm拉伸逻辑卷分区小总结

    文件系统                                      容量     已用      可用     已用% 挂载点 /dev/mapper/vg_znl-lv_root   ...

  3. Linux磁盘管理之LVM逻辑卷快照

    一.快照的工作原理 所谓快照就是将当时的系统数据记录下来,在未来若有数据变动,则会将变更前的数据放入快照区进行保存.我们可理解为快照就是给系统拍了一张照片,记录当时系统在拍快照的状态.只不过现实生活中 ...

  4. lvm创建和快照

    查看磁盘 创建分区 新建1G的1分区 新建1G的2分区 新建1G的3分区 查看新建的分区 因标准分区是83交换分区是82做lv是8e所以要改变类型 查看: 保存退出: 创建物理卷pv 将物理卷pv创建 ...

  5. lvm之创建/扩容/缩容/快照及关闭的全部流程操作记录

    基本介绍Linux用户安装Linux 操作系统时遇到的一个最常见的难以决定的问题就是如何正确地给评估各分区大小,以分配合适的硬盘空间.随着 Linux的逻辑盘卷管理功能的出现,这些问题都迎刃而解, l ...

  6. LVM常规操作记录梳理(扩容/缩容/快照等)

    基本介绍Linux用户安装Linux 操作系统时遇到的一个最常见的难以决定的问题就是如何正确地给评估各分区大小,以分配合适的硬盘空间.随着 Linux的逻辑盘卷管理功能的出现,这些问题都迎刃而解, l ...

  7. 基于LVM卷的MYSQL快照恢复

    在mysql数据库环境中,如果数据库数据很重要,可以使用LVM卷管理的方式,通过对数据卷进行快照,得到快速备份的目的, 首先回顾一下LVM卷管理的几个概念: 物理磁盘PD,physical disk, ...

  8. LVM : 快照

    LVM 机制还提供了对 LV 做快照的功能,也就是说可以给文件系统做一个备份,这也是设计 LVM 快照的主要目的.LVM 的快照功能采用写时复制技术(Copy-On-Write,COW),这比传统的备 ...

  9. 使用LVM快照进行数据库备份

    使用mysqldump备份时,如果存储引擎为MyISAM,则只能实现温备份,并需使用选项--lock-all-tables锁定所有表.如果存储引擎为InnoDB,则加上--single-transac ...

随机推荐

  1. NPOI读写Excel sheet操作

    QueryInfo dataInfo = new QueryInfo(); dataInfo.CustomSQL = $@" select t1.name name,t1.url url f ...

  2. 基于redis实现分布式Session

    学习到好的知识还是需要记录下来的. 开发环境 asp.net mvc4,iis.asp.net 自带的session机制存在诸多不好的地方.先只要列出几点. asp.net mvc 默认的sessio ...

  3. 并发编程CAS操作

    并发编程CAS操作 简介 CAS即compare and swap,中文就是比较并交换 CAS是Java并发包的基石 原理 其实CAS的原理相对来说比较简单.将要被改变的数据和期望的值作比较,当两个值 ...

  4. Perl 学习笔记-输入输出

    1.读取标准输入<STDIN>(行输入操作=> 读取一行直到换行符) chomp($line = <STDIN>); # 读取一行并去掉最后的换行符(不会自动去掉) pr ...

  5. java操作ceph之rbd基本操作

    一.安装librados和librbd Ceph存储集群提供了基本的存储服务,允许Ceph在一个统一的系统中唯一地传送对象,块和文件存储. 但是,不限于使用RESTful,块或POSIX接口. 基于R ...

  6. eclipse查看jar包中的class文件出现乱码

    参考:http://blog.csdn.net/bell2008/article/details/40978959 1,问题来源是在eclipse中直接查看springside的class(由ecli ...

  7. Android--iOS抓取崩溃日志

    android闪退获取日志方法: 1.下载adb工具包 2.注意事项 请确保电脑上只连接了一台手机设备(最好只连接一条USB线),同时确保手机已开启USB调试模式(可通过手机助手查看连接状态) 3.A ...

  8. 深入理解java虚拟机(四)垃圾收集算法及HotSpot实现

    垃圾收集算法 一般来说,垃圾收集算法分为四类: 标记-清除算法 最基础的算法便是标记-清除算法(Mark-Sweep).算法分为“标记”和“清除”两个阶段:首先标记处需要收集的对象,在标记完成之后,再 ...

  9. Linux route命令 显示getnameinfo failed [UNKNOWN]

    Redhat配置IPv6以后,执行route显示getnameinfo failed [UNKNOWN] 修改/etc/hosts,增加主机名后,重启服务器,问题解决

  10. android 中 dp和px转换

    DisplayUtils代码: public class DisplayUtil { public static int px2dip(Context context, float px) { flo ...