lvm

简介: 逻辑卷管理LVM是一个多才多艺的硬盘系统工具。无论在Linux或者其他类似的系统,都是非常的好用。传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。

逻辑卷管理LVM是一个多才多艺的硬盘系统工具。无论在Linux或者其他类似的系统,都是非常的好用。传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。可以让管理员弹性的管理逻辑卷的扩大缩小,操作简单,而不损坏已存储的数据。可以随意将新的硬盘添加到LVM,以直接扩展已经存在的逻辑卷。LVM并不需要重启就可以让内核知道分区的存在。


lvm架构

概念

DM:Device Mapper
逻辑设备
MD:multip Device
/dev/md#
meta device

linux系统一切皆文件,所有的设备都映射成文件在 /dev/目录下。

DM:逻辑设备
lvm2

DM:LVM2

   快照
   lincar
   mirror
   多路径(线路管理)实现数据的寻路多路径。
   动态增减(逻辑设备)


   多个物理磁盘组织成一个逻辑设备,可以中间增添。
   物理设备  --->  物理卷  physical volume PV
                  卷组    volume Group   VG(取决于物理设备)
                  逻辑卷     logical volume  LV 
                  逻辑卷可以有多个,可以动态增减。(逻辑卷之和不能超过物理容量)
物理边界,逻辑边界(文件系统边界)
逻辑卷相当于文件系统,对逻辑卷创建快照。快照卷必须和逻辑卷在同一个卷组。要预留空间。

快照:

访问同一数据的另一个路径(如软链接)(小于原数据)
恢复原来的数据,快照区是有数据备份的(发生修改的数据)
实现数据备份:线上的数据
RAID 1 RAID5 已经备份(硬件上备份防止硬件的损坏)
   数据访问  --->进程  磁盘  数据在线数据实时(备份耗时)
   快照瞬间完成
   zfs

chunk 和pe相同

  • PE:physical extend 物理盘区 加入卷组之后才有PE的概念,pe大小由卷组决定。
    逻辑存储单元

  • 逻辑卷:LE :logiacal Extend 逻辑盘区(角度不同)
    扩展空间边界:增加pe 减小空间边界:减少pe
    逻辑卷也可以创建成镜像的形式。

包含逻辑关系

pv ---> vg ---> lv 
pv即可以示磁盘,分区,raid

创建,删除,查看

  • pv
   pvcreate,pvremove(删除数据),pvscan,pvdisplay,pvmove(磁盘上数据移动到其他磁盘上)
   pvs:pvdisplay 
   linux lvm :8e 
   pvmove - move physical extents
  • vg
   vgcreate,vgremove,vgextend,vgreduce  
      vgdisplay,vgscan
      vgcreate -s   
      vgcreatee vg_name  /path/to/pv 
     删除vg  
        vgremove  
        
 vgremove - remove a volume group
 vgreduce  
 vgreduce - reduce a volume group
    pvmove /dev/sdb1
    vgreduce myvg  /dev/sdb1 
    pvremove /dev/sdb1 
    
    vgextend - add physical volumes to a volume group
  • lv
    lvcreate,lvremove,lvextend,lvreduce,lvs,lvdisplay
    创建lv
      lvcreate -n lv_name -L size#G  VG_name
      lvcreate -l 50M -n testlv myvg 
      lvs 
      lvdisplay  
      lvremove 

操作过程

 创建10G的vg
  fdisk 只能创建15个 
 partprobe  
 cat /proc/partions
 pvcreate   /dev/sda{1,2}
 pvs
 pvdisplay 详细显示
 pvdisplay  /dev/sda1
 pvscan  扫描系统上所有的pv
 
 vgcreate  
 vgcreate  myvg /dev/sda{1,2}
  vgs 
  pvdisplay  /dev/sda10 
  
   pvcreate /dev/sdb2
   vgextend myvg /dev/sda2 

   
   创建lv 
     lv 

创建分区:是创建物理边界

文件系统:逻辑边界
lvm:先扩展物理边界,在扩展逻辑边界。 先缩减逻辑边界,再缩减物理边界。

一、扩展逻辑卷
扩展物理边界:
lvextend
      -L [+]# /path/to/lv   扩展到或扩展了。。。 
扩展逻辑边界:
resize2fs   /path/to/lv   大小    设备扩展到多大
resize2fs -p /path/to/lv 

lvcreate -L 2G -n testlv mylv 
mke2fs -j /dev/myvg/testlv 
mkdir /users
mount /dev/myvg/testlv /users
df -lh

lvextend -L 5G /dev/myvg/testlv 
df -lh
resize2fs -p /dev/myvg/testlv
df -lh

二、缩减逻辑卷

先缩减逻辑边界,再缩减物理边界。

   注意:1.不能在线缩减,得先卸载。
          2.确保缩减后的空间大小依然能存储原有的所有数据。
          3.在缩减前应该强行检查文件,以确保文件系统处于一致性状态。
resize2fs 
   ressize2fs /path/to/lv  #G 
lvreduce  -L [-]#  /path/to/lv 

重新挂载。
df -lh 
umount /users 
e2fsck -f /dev/myvg/testlv
resize2fs /dev/myvg/testlv 3G
lvreduce -L 3G /dev/myvg/testlv
mount /dev/myvg/testlv /user
三、快照卷

1.快照卷的生命周期为整个数据时长,在这段时长内,数据的增长量不能超出快照卷大小。
2.快照卷应该为只读。
3.和原卷在同一卷组内。

lvcreate 
   -s 
   -p  r|w
   lvcreate -L # 
lvcreate  -L # -n slv_name -p r /path/to/slv 
lvcreate -L 50M -n testlv-snap -s -p r /dev/myvg/testlv 
lvs 
mount /dev/myvg/testlv-snap  /snap 
cd /snap 
ls
cd /users 


tar -jcf /tmp/users.tar.bz2 /users/inittab
umount /snap 
lvremove /dev/myvg/testlv-snap 
完全备份,增量备份
tar xf /tmp/users.tar.bz2 -C /users 

lvm的配置文件

 ubuntu@youdi > /etc/lvm > vim /etc/lvm/lvm.conf 

lvm相关命令


COMMANDS
       The following commands implement the core LVM functionality.

       pvchange      Change attributes of a Physical Volume.
       pvck          Check Physical Volume metadata.
       pvcreate      Initialize a disk or partition for use by LVM.
       pvdisplay     Display attributes of a Physical Volume.
       pvmove        Move Physical Extents.
       pvremove      Remove a Physical Volume.                                                                                                                                                                    
       pvresize      Resize a disk or partition in use by LVM2.                                                                                                                                                   
       pvs           Report information about Physical Volumes.                                                                                                                                                   
       pvscan        Scan all disks for Physical Volumes.                                                                                                                                                         
       vgcfgbackup   Backup Volume Group descriptor area.                                                                                                                                                         
       vgcfgrestore  Restore Volume Group descriptor area.                                                                                                                                                        
       vgchange      Change attributes of a Volume Group.                                                                                                                                                         
       vgck          Check Volume Group metadata.                                                                                                                                                                 
       vgconvert     Convert Volume Group metadata format.                                                                                                                                                        
       vgcreate      Create a Volume Group.                                                                                                                                                                       
       vgdisplay     Display attributes of Volume Groups.                                                                                                                                                         
       vgexport      Make volume Groups unknown to the system.                                                                                                                                                    
       vgextend      Add Physical Volumes to a Volume Group.                                                                                                                                                      
       vgimport      Make exported Volume Groups known to the system.                                                                                                                                             
       vgimportclone Import and rename duplicated Volume Group (e.g. a hardware snapshot).                                                                                                                        
       vgmerge       Merge two Volume Groups.                                                                                                                                                                     
       vgmknodes     Recreate Volume Group directory and Logical Volume special files                                                                                                                             
       vgreduce      Reduce a Volume Group by removing one or more Physical Volumes.                                                                                                                              
       vgremove      Remove a Volume Group.                                                                                                                                                                       
       vgrename      Rename a Volume Group.                                                                                                                                                                       
       vgs           Report information about Volume Groups.                                                                                                                                                      
       vgscan        Scan all disks for Volume Groups and rebuild caches.                                                                                                                                         
       vgsplit       Split a Volume Group into two, moving any logical volumes from one Volume Group to another by moving entire Physical Volumes.                                                                
       lvchange      Change attributes of a Logical Volume.                                                                                                                                                       
       lvconvert     Convert a Logical Volume from linear to mirror or snapshot.                                                                                                                                  
       lvcreate      Create a Logical Volume in an existing Volume Group.                                                                                                                                         
       lvdisplay     Display attributes of a Logical Volume.                                                                                                                                                      
       lvextend      Extend the size of a Logical Volume.                                                                                                                                                         
       lvmchange     Change attributes of the Logical Volume Manager.                                                                                                                                             
       lvmconfig     Display the configuration information after loading lvm.conf(5) and any other configuration files.                                                                                           
       lvmdiskscan   Scan for all devices visible to LVM2.                                                                                                                                                        
       lvmdump       Create lvm2 information dumps for diagnostic purposes.                                                                                                                                       
       lvreduce      Reduce the size of a Logical Volume.                                                                                                                                                         
       lvremove      Remove a Logical Volume.                                                                                                                                                                     
       lvrename      Rename a Logical Volume.                                                                                                                                                                     
       lvresize      Resize a Logical Volume.                                                                                                                                                                     
       lvs           Report information about Logical Volumes.                                                                                                                                                    
       lvscan        Scan (all disks) for Logical Volumes.    

查看帮助使用 man


man lvm
man vgscan

目录
相关文章
|
5月前
|
存储 Linux
哇~真的是你呀!今天是挂载、LVM逻辑卷。
在 Linux 中,挂载是将一个文件系统连接到文件系统树的某个目录上的过程。它的作用是让用户能够访问文件系统中的文件和目录,使用文件系统中的空间存储数据。当一个磁盘分区或者一个外部存储设备被挂载到一个目录上时,该目录就成为了该分区或者设备的挂载点。
53 0
|
存储 Ubuntu Linux
LVM
LVM
126 0
LVM
|
MySQL 关系型数据库 Linux

热门文章

最新文章