LVM、物理卷、逻辑卷、卷组、快照

3

LVM是什么

图片描述

关于LVM简单的理解【百度百科很详细】,现在php开发的一个项目,涉及到拍高清照片,项目盘20G很快被占满了,目前我想到的解决方式可能有 (1).虚拟目录指定到其他盘符或分区,但是还要修改项目中图片存放路径,很麻烦 (2).找一个分区mount到图片目录 (3).用fdisk 先删除原有分区, 再重建分区, 起始cylinder 绝对不可以改,这样会破坏原分区的数据 (4).再就是今天要学习的LVM,它把最下面的物理盘【物理卷】/dev/sda1,/dev/sdb1...逻辑成一个大磁盘【卷组】,然后分配给逻辑分区【逻辑卷】

这样不管是扩容还是减容,都只是逻辑上的变化,而最下层的物理卷根本没有变化,所以不会影响数据的毁坏【文件系统层次看见的是逻辑分区】,当数据存入取出的时候,比如逻辑分区1到逻辑集合(大磁盘)之间的最小数据块或者说是基本单位【类比raid中的CHUNK】叫做LE逻辑快,而逻辑集合(大磁盘)到物理卷的基本单位是PE物理块,在同一个卷组中,LE的大小和PE是相同的,并且一一对应。下面的物理卷坏了任意一块上面的逻辑卷也不能使用,因为LE在下面的每个磁盘都有【可以使用前面说的raid技术】

要想扩大上面逻辑分区的最大容量【逻辑边界】,就必须扩大中间的卷组,最终还是要扩大底层的磁盘组【物理边界】,当要去掉底层的一块盘时,它会先把该盘数据转移到其他的盘,然后才拆卸

创建物理卷【pv】

停止阵列

停止raid占用的分区【上一章raid遗留问题】,否则可能出现资源繁忙或资源被占用

[root@localhost ~]# mdadm -S /dev/md126
mdadm: stopped /dev/md126
[root@localhost ~]# mdadm -S /dev/md127
mdadm: stopped /dev/md127

更改分区类型

用fdisk把分区类型改为8e

[root@localhost ~]# fdisk /dev/sdb

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): t
Partition number (1-6): 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): t   
Partition number (1-6): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xd25c91c2

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  8e  Linux LVM【改成LVM分区类型】
/dev/sdb2             133         264     1060290   8e  Linux LVM
/dev/sdb3             265         396     1060290   8e  Linux LVM
/dev/sdb4             397        1305     7301542+   5  Extended
/dev/sdb5             397         528     1060258+  8e  Linux LVM
/dev/sdb6             529         660     1060258+  8e  Linux LVM
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

pvcreate创建pv

现在把sdb3和sdb5做成pv【物理卷】

[root@localhost ~]# pvcreate /dev/sdb{3,5}
  Physical volume "/dev/sdb3" successfully created
  Physical volume "/dev/sdb5" successfully created

pvscan查看pv

[root@localhost ~]# pvscan
  PV /dev/sdb3         lvm2 [1.01 GiB]
  PV /dev/sdb5         lvm2 [1.01 GiB]
  Total: 2 [2.02 GiB] / in use: 0 [0   ] / in no VG: 2 [2.02 GiB]

pvdisplay查看详细信息

[root@localhost ~]# pvdisplay
  "/dev/sdb3" is a new physical volume of "1.01 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb3
  VG Name               
  PV Size               1.01 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0【当pv加入到卷组以后PE才的个数才知道有多少】
  Allocated PE          0
  PV UUID               U1ndh1-u5pu-v0WF-PrWg-fwuO-1Blw-4Wbz0f
   
  "/dev/sdb5" is a new physical volume of "1.01 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb5
  VG Name               
  PV Size               1.01 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               79gSEo-q0xS-M7Q5-Wlmc-qbCz-tH2Z-ZPMf57

pvmove移动pv数据

现在要移除一个pv,首先要不数据转移到其他的pv上,然后使用vgreduce去掉该pv

[root@localhost ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb3  myvg lvm2 a--  1.01g 1.01g
  /dev/sdb5  myvg lvm2 a--  1.01g 1.01g【还没有移除】
[root@localhost ~]# pvmove /dev/sdb5
  No data to move for myvg【我的/dev/sdb5还没数据】
[root@localhost ~]# vgreduce myvg /dev/sdb5
  Removed "/dev/sdb5" from volume group "myvg"
[root@localhost ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb3  myvg lvm2 a--  1.01g 1.01g
  /dev/sdb5       lvm2 ---  1.01g 1.01g【已经移除】

pvremove删除pv数据

[root@localhost ~]# pvremove /dev/sdb5
  Labels on physical volume "/dev/sdb5" successfully wiped

创建卷组【vg】

vgcreate创建vg

用法:vgcreate 卷组名 物理卷名

  • -s #:指定PE大小,默认是4M

[root@localhost ~]# vgcreate myvg /dev/sdb{3,5}
  Volume group "myvg" successfully created

vgs查看vg

[root@localhost ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   2   0   0 wz--n- 2.02g 2.02g

vgdisplay 查看vg

查看vg详细信息查看PE大小,pvdisplay查看PE的个数

[root@localhost ~]# vgdisplay myvg
  --- Volume group ---
  VG Name               myvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               2.02 GiB
  PE Size               4.00 MiB【PE大小】
  Total PE              516
  Alloc PE / Size       0 / 0   
  Free  PE / Size       516 / 2.02 GiB
  VG UUID               87U1HI-Nr3b-ytsO-iw3K-lFG6-yVy9-uoZlXM

[root@localhost ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sdb3
  VG Name               myvg
  PV Size               1.01 GiB / not usable 3.44 MiB
  Allocatable           yes 
  PE Size               4.00 MiB【PE大小】
  Total PE              258
  Free PE               258【PE个数】
  Allocated PE          0
  PV UUID               U1ndh1-u5pu-v0WF-PrWg-fwuO-1Blw-4Wbz0f
   
  --- Physical volume ---
  PV Name               /dev/sdb5
  VG Name               myvg
  PV Size               1.01 GiB / not usable 3.41 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              258
  Free PE               258
  Allocated PE          0
  PV UUID               79gSEo-q0xS-M7Q5-Wlmc-qbCz-tH2Z-ZPMf57

vgremove删除vg

在还没有创建lg的时候可以删除vg,创建了lg有了数据就不能再删除了

[root@localhost ~]# vgremove myvg
  Volume group "myvg" successfully removed

vgreduce移除pv

[root@localhost ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb3  myvg lvm2 a--  1.01g 1.01g
  /dev/sdb5  myvg lvm2 a--  1.01g 1.01g【还没有移除】
[root@localhost ~]# pvmove /dev/sdb5
  No data to move for myvg【我的/dev/sdb5还没数据】
[root@localhost ~]# vgreduce myvg /dev/sdb5
  Removed "/dev/sdb5" from volume group "myvg"
[root@localhost ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb3  myvg lvm2 a--  1.01g 1.01g
  /dev/sdb5       lvm2 ---  1.01g 1.01g【已经移除】

vgextend扩展vg

扩展vg就要增加pv

[root@localhost ~]# vgextend myvg /dev/sdb5
  Physical volume "/dev/sdb5" successfully created
  Volume group "myvg" successfully extended
[root@localhost ~]# pvcreate /dev/sdb6
  Can't open /dev/sdb6 exclusively.  Mounted filesystem?
[root@localhost ~]# cat /proc/mdstat【怎么自动被raid占用了???】
Personalities : [raid1] [raid0] 
md1 : inactive sdb6[2](S)
      1059234 blocks super 1.2
       
md0 : active raid0 sdb2[1] sdb1[0]
      2117632 blocks super 1.2 512k chunks
      
unused devices: <none>
[root@localhost ~]# mdadm -S /dev/md0【停止阵列】
mdadm: stopped /dev/md0
[root@localhost ~]# mdadm -S /dev/md1
mdadm: stopped /dev/md1


[root@localhost ~]# pvcreate /dev/sdb6【创建pv】
WARNING: software RAID md superblock detected on /dev/sdb6. Wipe it? [y/n]: y
  Wiping software RAID md superblock on /dev/sdb6.
  Physical volume "/dev/sdb6" successfully created
[root@localhost ~]# vgextend myvg /dev/sdb6【添加到myvg卷组】
  Volume group "myvg" successfully extended
[root@localhost ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   3   0   0 wz--n- 3.02g 3.02g
[root@localhost ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb3  myvg lvm2 a--  1.01g 1.01g
  /dev/sdb5  myvg lvm2 a--  1.01g 1.01g
  /dev/sdb6  myvg lvm2 a--  1.01g 1.01g

创建逻辑卷【LV】

lvcreate

用法:lvcreate -n LV_NAME -L #G VG_NAME

[root@localhost ~]# lvcreate -L 100M -n mylv myvg
  Rounding up size to full physical extent 104.00 MiB
  Logical volume "mylv" created

lvdisplay

[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/myvg/mylv【可以lvdisplay /dev/myvg/mylv】
  LV Name                mylv
  VG Name                myvg
  LV UUID                8AbwtV-ZJ3c-MbnS-AjUz-3n1A-xRUX-5S2TBr
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-04-30 15:55:25 +0800
  LV Status              available
  # open                 0
  LV Size                104.00 MiB
  Current LE             13
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

创建文件系统并挂载

创建文件系统

[root@localhost ~]# mke2fs -j /dev/myvg/mylv
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
26624 inodes, 106496 blocks
5324 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729

正在写入inode表: 完成                            
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

挂载

[root@localhost ~]# mount /dev/myvg/mylv /mnt/test
[root@localhost ~]# ls -l /mnt/test
总用量 12
drwx------. 2 root root 12288 4月  30 16:00 lost+found
[root@localhost ~]# mount【查看挂载的设备记录】
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda5 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mylv on /mnt/test type ext3 (rw)【在这发现一个myvg-mylv挂载了,并没有我们的设备mylv的挂载记录】

查看/dev/mapper/myvg-mylv和/dev/myvg/mylv,发现都指向了同一个设备/dev/dm-0,这说明真正的物理空间,也就是物理卷分配给了dm-0,mylv和myvg-mylv都是逻辑卷,仅仅是个软链接【自己的猜想,望大神指正】

[root@localhost ~]# ls -lh /dev/myvg/mylv
lrwxrwxrwx. 1 root root 7 4月  30 16:00 /dev/myvg/mylv -> ../dm-0
[root@localhost ~]# ls -lh /dev/mapper/myvg-mylv 
lrwxrwxrwx. 1 root root 7 4月  30 16:00 /dev/mapper/myvg-mylv -> ../dm-0

[root@localhost ~]# ls -lh /dev/dm-0             
brw-rw----. 1 root disk 253, 0 4月  30 16:00 /dev/dm-0

lvremove

证明一下上面的结论,我们卸载mylv和myvg-mylv;结果说明逻辑卷有两个名字,都是软链接

[root@localhost test]# lvremove /dev/mapper/myvg-mylv
  Logical volume myvg/mylv contains a filesystem in use.
[root@localhost test]# lvremove /dev/myvg/mylv       
  Logical volume myvg/mylv contains a filesystem in use.

[root@localhost mnt]# umount /dev/myvg/mylv【软链接】        
[root@localhost mnt]# lvremove /dev/mapper/myvg-mylv【软链接】
Do you really want to remove active logical volume mylv? [y/n]: y
  Logical volume "mylv" successfully removed
[root@localhost mnt]# ls -l /dev/md-0【真正的逻辑设备md-0被移除】
ls: 无法访问/dev/md-0: 没有那个文件或目录
[root@localhost mnt]# lvs【真正的逻辑设备md-0被移除】
[root@localhost mnt]# 

lvextend扩展逻辑卷

用法:-L [+]# /PATH/LV,"[+]"代表有"+"号时,代表加多少G【容量】,没有+号代表扩展到多少G

[root@localhost mnt]# lvcreate -L 1G -n mylv myvg【创建一个逻辑卷】
  Logical volume "mylv" created
[root@localhost mnt]# mke2fs -j /dev/myvg/mylv【创建文件系统】
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

正在写入inode表: 完成                            
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost mnt]# mount /mnt/test
mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

[root@localhost mnt]# mount /dev/myvg/mylv /mnt/test【挂载】
[root@localhost mnt]# vgs【查看vg】
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   3   1   0 wz--n- 3.02g 2.02g


[root@localhost mnt]# lvextend -L 2G /dev/myvg/mylv【扩容】
  Size of logical volume myvg/mylv changed from 1.00 GiB (128 extents) to 2.00 GiB (256 extents).
  Logical volume mylv successfully resized
[root@localhost mnt]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.9G  3.2G  463M  88% /
tmpfs                 504M   72K  504M   1% /dev/shm
/dev/sda1             190M   26M  155M  15% /boot
/dev/sda5             3.7G   34M  3.5G   1% /home
/dev/mapper/myvg-mylv
                     1008M   34M  924M   4% /mnt/test【扩容后发现大小没变】

resize2fs重新加载逻辑卷

resize2fs命令被用来增大或者收缩未加载的“ext2/ext3”文件系统的大小。如果文件系统是处于mount状态下,那么它只能做到扩容,前提条件是内核支持在线resize。,linux kernel 2.6支持在mount状态下扩容但仅限于ext3文件系统。来自: http://man.linuxde.net/resize2fs

  • -d:打开调试特性;

  • -p:打印已完成的百分比进度条;

  • -f:强制执行调整大小操作,覆盖掉安全检查操作;

  • -F:开始执行调整大小前,刷新文件系统设备的缓冲区。

[root@localhost mnt]# resize2fs /dev/myvg/mylv 【重新加载逻辑卷】
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/mylv is mounted on /mnt/test; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/myvg/mylv to 524288 (4k) blocks.
The filesystem on /dev/myvg/mylv is now 524288 blocks long.

[root@localhost mnt]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.9G  3.2G  463M  88% /
tmpfs                 504M   72K  504M   1% /dev/shm
/dev/sda1             190M   26M  155M  15% /boot
/dev/sda5             3.7G   34M  3.5G   1% /home
/dev/mapper/myvg-mylv
                      2.0G   34M  1.9G   2% /mnt/test【扩容成功】
[root@localhost mnt]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-ao---- 2.00g       

lvreduce缩减逻辑卷

注意:

  1. 不能在线缩减,先卸载

  2. 确保缩减后的空间大小依然能存储原有的数据

  3. 在缩减之前应该先强行检查文件系统,以确保文件系统处于一致性状态【e2fsck -f】

缩减逻辑卷刚好和上面相反,先resize2fs再lvreduce

[root@localhost mnt]# df -lh【确保缩减后的空间大小依然能存储原有的数据,df只能查看挂载的分区】
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.9G  3.2G  463M  88% /
tmpfs                 504M   72K  504M   1% /dev/shm
/dev/sda1             190M   26M  155M  15% /boot
/dev/sda5             3.7G   34M  3.5G   1% /home
/dev/mapper/myvg-mylv
                      2.0G   34M  1.9G   2% /mnt/test
[root@localhost mnt]# umount /mnt/test【不能在线缩减,先卸载】
[root@localhost mnt]# mount【确保已经卸载】
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda5 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@localhost mnt]# e2fsck -f /dev/myvg/mylv【确保文件系统处于一致性状态】
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/myvg/mylv: 11/131072 files (0.0% non-contiguous), 16821/524288 blocks

[root@localhost mnt]# resize2fs /dev/myvg/mylv 1G【调整文件系统大小为1G】
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/mylv to 262144 (4k) blocks.
The filesystem on /dev/myvg/mylv is now 262144 blocks long.

[root@localhost mnt]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a----- 2.00g【逻辑卷还没调整】

[root@localhost mnt]# lvreduce -L 1G /dev/myvg/mylv【缩减逻辑卷】
  WARNING: Reducing active logical volume to 1.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
  Size of logical volume myvg/mylv changed from 2.00 GiB (256 extents) to 1.00 GiB (128 extents).
  Logical volume mylv successfully resized
[root@localhost mnt]# mount /dev/myvg/mylv /mnt/test【挂载】
[root@localhost mnt]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda5 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mylv on /mnt/test type ext3 (rw)
[root@localhost mnt]# df -lh【查看已挂载磁盘分区的使用信息】
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.9G  3.2G  463M  88% /
tmpfs                 504M   72K  504M   1% /dev/shm
/dev/sda1             190M   26M  155M  15% /boot
/dev/sda5             3.7G   34M  3.5G   1% /home
/dev/mapper/myvg-mylv
                     1008M   34M  924M   4% /mnt/test

快照卷

快照一般都很小,它存的是原系统上要发生变化的文件,比如我要修改一个文件,快照会首先把文件存起来,然后修改过后的文件在原系统,未修改的文件存进了快照。这样就实现了数据备份,这样快照卷刚开始很小,时间长了就大了。它这个备份存的是软件资料的备份。而我们的raid1和raid10存的备份是磁盘的备份。我的磁盘直接坏掉了,快照肯定没有备份下来,还原也是没用的【快照也是存在磁盘上的】。

快照卷的好多文件其实都是和原文件系统共用的,所以快照卷相当于一个分区的另一个入口,这样快照卷肯定在该分区上,对LVM而言就是在一个卷组上【因为PE在vg下面的每个PV上都有】

要求:

  1. 生命周期为整个快照的文件系统的生命周期,并且在该周期内原文件系统变化的文件大小不能超过快照卷,因为每有文件变化就会备份一份该文件变化之前的快照,最大不会超过快照的原文件系统大小

  2. 快照应该是只读

  3. 跟原卷在同一卷组

使用方法:lvcreate -L # -n SLV_NAME -s -p r /PATH/LV 【指定为那个逻辑卷创建的】

  • -s:表示快照卷

  • -p:指定权限r|w

  • -L:快照卷大小

#test是逻辑卷mylv挂载目录
#test1是快照卷挂载目录
[root@localhost test]# ls
lost+found
[root@localhost test]# touch b.txt【创建快照前先在原文件系统创建一个b.txt】
[root@localhost test]# lvcreate -L 100M -n mylv-snap -s -p r /dev/myvg/mylv 【为mylv创建快照】
  Rounding up size to full physical extent 104.00 MiB
  Logical volume "mylv-snap" created
[root@localhost test]# mount /dev/myvg/mylv-snap /mnt/test1【挂载】
mount: block device /dev/mapper/myvg-mylv--snap is write-protected, mounting read-only
[root@localhost test]# ls /mnt/test1【创建当前快照,这个b.txt其实也是/mnt/test的b.txt,快照只是入口】
b.txt  lost+found
[root@localhost test]# vi b.txt【编辑test下的b.txt,快照这个时候才备份,备份原来的空文件b.txt】
[root@localhost test]# cat b.txt
dsadsaaaaa
[root@localhost test]# cat /mnt/test1/b.txt【发现还是空,已经快照备份了】
[root@localhost test]# 
#删除快照
[root@localhost test]# umount /mnt/test1
[root@localhost test]# lvremove /dev/myvg/mylv-snap
Do you really want to remove active logical volume mylv-snap? [y/n]: y
  Logical volume "mylv-snap" successfully removed

如果觉得我的文章对你有用,请随意赞赏

你可能感兴趣的

mambo · 2018年12月08日

学到了

回复

载入中...