LVM———Logical Volume Manager(逻辑卷管理器)的简写。LVM可以帮助我们为应用与用户方便地分配存储空间。在LVM管理下的逻辑卷可以按需改变大小或添加移除。LVM也允许按用户组对存储卷进行管理,允许管理员用更直观的名称("sales','development')代替物理磁盘('sda','sdb')来标识存储卷。
 
传统分区概念
LVM逻辑卷管理
磁盘空间独立性 不能充分利用,尤其是一个FS只能对应一个分区 多磁盘PV组成存储池VG,再根据应用细分逻辑卷LV,空间利用率提高
空间扩展性 重新分区 采取静态或动态在线扩展卷组容量
数据备份 业务繁忙时,I/O接口读写频繁 可采取快照方式捕捉某一逻辑卷的瞬间精确拷贝已完成在线备份工作
用户使用性 分区标识无法满足大量用户要求 可根据用户需求定义lv逻辑卷的卷标
 
一、创建LVM的准备工作
    1.搭建环境:OS:RHEL5.3
               LVM包
               IDE磁盘/dev/hdb(1024MB),/dev/hdd(1024MB)
    2.转换磁盘分区——>lvm卷分区
      最终方案:/dev/hdb ——> 创建  /dev/hdb1(Id:5,System:Extended)
                                 /dev/hdb5(Id:8e,System:Linux LVM)
               /dev/hdd ——> 创建  /dev/hdd1(Id:5,System:Extended)
                                 /dev/hdd5(Id:8e,System:Linux LVM)
    操作:(仅以/dev/hdb为例)

    #fdisk /dev/hdb    
    #p(显示分区情况)——>#n(新建分区)——>#e(创建扩展分区)——>#l(创建逻辑分区)
    #此处为实验环境方便后面的增减操作,所以我们将/dev/hdb全部划分为一个分区
    #t(设置磁盘Hex code)——>#8e(LinuxLVM)——>#w(保存操作)
    #p
    Disk /dev/hdb: 1073 MB, 1073741824 bytes
    16 heads, 63 sectors/track, 2080 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    Device Boot      Start     End      Blocks      Id     System
    /dev/hdb1          1       2080     1048288+     5     Extended
    /dev/hdb5          1       2080     1048257      8e    Linux LVM
    #partprobe (此命令让kernel会重新读取磁盘分区表,修改生效)
   
二、创建LVM
    1.创建PV盘
    方案:   /dev/hdb ——> lvm2[1024MB]
            /dev/hdd ——> lvm2[1024MB]
    操作:
    #pvcreate /dev/hdb5 /dev/hdd5
    #pvscan
    #pvdisplay
  "/dev/hdb5" is a new physical volume of "1023.69 MB"
  --- NEW Physical volume ---
  PV Name               /dev/hdb5
  VG Name              
  PV Size               1023.69 MB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               zM7103-SJg4-ZjOb-BeL0-dlR1-HHh6-HCG8kG
  "/dev/hdd5" is a new physical volume of "1023.69 MB"
  --- NEW Physical volume ---
  PV Name               /dev/hdd5
  VG Name              
  PV Size               1023.69 MB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               hAk1Dx-QulA-YV4G-p8wa-7sWw-FiaC-10GorS
  
2.创建VG存储池
    方案:   lvm2(/dev/hdb)——> vg1
            lvm2(/dev/hdd)——> vg2
    操作:
    #vgcreate vg1 /dev/hdb5
    #vgcreate vg2 /dev/hdd5
    #vgscan
    #vgdisplay
    --- Volume group ---
  VG Name               vg2
  System ID            
  Format                lvm2
  Metadata Areas        1
  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                1
  Act PV                1
  VG Size           1020.00 MB
  PE Size           4.00 MB
  Total PE          255

  Alloc PE / Size       0 / 0  
  Free  PE / Size       255 / 1020.00 MB
  VG UUID               Wa4Jo8-k3xY-BTng-uV6j-0Ee1-Vp8b-fNVrhQ
  --- Volume group ---
  VG Name               vg1
  System ID            
  Format                lvm2
  Metadata Areas        1
  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                1
  Act PV                1
  VG Size           1020.00 MB
  PE Size           4.00 MB
  Total PE          255

  Alloc PE / Size       0 / 0  
  Free  PE / Size       255 / 1020.00 MB
  VG UUID               UGjfZd-shth-ZRTU-sVVm-MD0s-wzVB-zd7Uwt
 
3.分配LV逻辑卷
    方案:   work(/dev/hdb5)——> vg1
            Study(/dev/hdd5)——> vg2
    操作:
    #lvcreate –L 500M –n work vg1
    #lvcreate –L 500M –n study vg2
    #lvscan
    #lvdisplay
 
--- Logical volume ---
  LV Name                /dev/vg2/study
  VG Name                vg2
  LV UUID                53VT9v-dyp0-lSST-eDFz-w2Ns-Os0Z-ERnqVU
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size            500.00 MB
  Current LE         125

  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  --- Logical volume ---
  LV Name                /dev/vg1/work
  VG Name                vg1
  LV UUID                lhgKVg-hi95-W9gw-wOkZ-uyuy-BgZp-RrsCcA
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size            500.00 MB
  Current LE         125

  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
 
4.分区格式化
    #mkfs.ext3 /dev/vg1/work         //或 #mkfs -j /dev/vg1/work
    #mkfs.ext3 /dev/vg2/study        //...
    #df –l

Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
  Device Boot Start End  Blocks   Id System
/dev/hda1 *    1    32   257008+  83  Linux
/dev/hda2     33    97   522112+  83  Linux
/dev/hda3     98    358  2096482+ 83  Linux
/dev/hda4     359   1044 5510295  5  Extended
/dev/hda5     359   549  1534176  83  Linux
/dev/hda6     550   848  2401686  83  Linux
/dev/hda7     849   913  522081   82  Linux swap / Solaris
/dev/hda8     914   978  522081   83  Linux
/dev/hda9     979   1043 522081   83  Linux

Disk /dev/hdb: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
 
   Device Boot Start End   Blocks Id System
/dev/hdb1       1    2080 1048288+ 5 Extended
/dev/hdb5     1    2080 1048257 8e Linux LVM

Disk /dev/hdd: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

Device   Boot Start End   Blocks  Id  System
/dev/hdd1       1   2080 1048288+  5   Extended
/dev/hdd5     1   2080 1048257   8e  Linux LVM
   
5.挂载新分区

 #mkdir ../home/work ../home/study
 #mount ../dev/vg1/work ../home/work
 #mount ../dev/vg2/study ../home/study
 #df –Th

Filesystem  Type  Size Used Avail Use% Mounted on
/dev/hda2   ext3 494M 212M 257M  46%   /
/dev/hda9   ext3 494M 45M 425M   10%   /var
/dev/hda8   ext3 494M 11M 458M   3%    /opt
/dev/hda6   ext3 2.3G 68M 2.1G   4%    /home
/dev/hda3   ext3 2.0G 1.7G 182M  91%   /usr
/dev/hda5   ext3 1.5G 35M 1.4G   3%    /usr/local
/dev/hda1   ext3 244M 12M 219M   6%    /boot
tmpfs       tmpfs 125M 0  125M   0%    /dev/shm

/dev/mapper/vg1-work
            ext3  485M 11M 449M  3%    /home/work
/dev/mapper/vg2-study
            ext3  485M 11M 449M  3%    /home/study

2

收藏

allen7111382

10篇文章,5W+人气,0粉丝