LVM———Logical Volume Manager(邏輯卷管理器)的簡寫。LVM可以幫助我們?yōu)閼?yīng)用與用戶方便地分配存儲空間。在LVM管理下的邏輯卷可以按需改變大小或添加移除。LVM也允許按用戶組對存儲卷進行管理,允許管理員用更直觀的名稱(如"sales','development')代替物理磁盤(如'sda','sdb')來標識存儲卷。
|
傳統(tǒng)分區(qū)概念
|
LVM邏輯卷管理
|
磁盤空間獨立性
|
不能充分利用,尤其是一個FS只能對應(yīng)一個分區(qū)
|
多磁盤PV組成存儲池VG,再根據(jù)應(yīng)用細分邏輯卷LV,空間利用率提高
|
空間擴展性
|
重新分區(qū)
|
采取靜態(tài)或動態(tài)在線擴展卷組容量
|
數(shù)據(jù)備份
|
業(yè)務(wù)繁忙時,I/O接口讀寫頻繁
|
可采取快照方式捕捉某一邏輯卷的瞬間精確拷貝已完成在線備份工作
|
用戶使用性
|
分區(qū)標識無法滿足大量用戶要求
|
可根據(jù)用戶需求定義lv邏輯卷的卷標
|
一、創(chuàng)建LVM的準備工作
1.搭建環(huán)境:OS:RHEL5.3
LVM包
IDE磁盤/dev/hdb(1024MB),/dev/hdd(1024MB)
2.轉(zhuǎn)換磁盤分區(qū)——>lvm卷分區(qū)
最終方案:/dev/hdb ——> 創(chuàng)建 /dev/hdb1(Id:5,System:Extended)
/dev/hdb5(Id:8e,System:Linux LVM)
/dev/hdd ——> 創(chuàng)建 /dev/hdd1(Id:5,System:Extended)
/dev/hdd5(Id:8e,System:Linux LVM)
操作:(僅以/dev/hdb為例)
#fdisk /dev/hdb #p(顯示分區(qū)情況)——>#n(新建分區(qū))——>#e(創(chuàng)建擴展分區(qū))——>#l(創(chuàng)建邏輯分區(qū)) #此處為實驗環(huán)境方便后面的增減操作,所以我們將/dev/hdb全部劃分為一個分區(qū) #t(設(shè)置磁盤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會重新讀取磁盤分區(qū)表,修改生效)
|
二、創(chuàng)建LVM
1.創(chuàng)建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.創(chuàng)建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.分區(qū)格式化
#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.掛載新分區(qū)
#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
|