歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux的LVM(Logical Volume Manager) 學習筆記

Linux的LVM(Logical Volume Manager) 學習筆記

日期:2017/2/28 14:31:52   编辑:Linux教程

在Linux系統規劃管理中,存儲管理是一個非常重要的方面。日常運維過程中,兩個方面的現實要求經常圍繞這一個過程:動態空間管理和零散的存儲硬件資源。

和Windows不同,Linux存儲目錄結構和磁盤結構是分離的。各個磁盤設備是被“裝載mount”到指定的mount point上,我們經常可以看到一個“目錄”的空間是多大。但是,存儲是動態變化的過程。一個目錄現在留足1G空間就夠了,但是日後難保不會有2G的需要。如果使用傳統的一些方法,變化過程就是比較復雜的。

另一方面,多年的信息化給企業信息中心遺留下存儲設備通常是零散、大小不一的。往往需要一個目錄空間很大,但是只有一些零散的小存儲盤。如何整合這些零散存儲資源,對操作系統管理而言是一個問題。

在Linux環境中,一種存儲池“Storage Pool”機制的技術,就可以幫助我們進行存儲資源的管理和調整。LVM(Logical Volume Manager)邏輯卷管理器是Linux提供的邏輯存儲池。

RHCE125_135之LVM http://www.linuxidc.com/Linux/2014-05/101050.htm

Ubuntu 12.04 KVM之VM動態遷移-基於LVM http://www.linuxidc.com/Linux/2014-04/99894.htm

RHCE認證筆記:LVM實驗 http://www.linuxidc.com/Linux/2014-04/99685.htm

MySQL管理之基於LVM實現幾乎熱備 http://www.linuxidc.com/Linux/2014-04/99672.htm

Linux系統管理之LVM案例 http://www.linuxidc.com/Linux/2014-02/96987.htm

Linux系統中對邏輯卷(LVM)的實現 http://www.linuxidc.com/Linux/2014-01/95004.htm

1、LVM概述

在LVM中,有幾個概念需要了解熟悉。

PV(Physical Volume)物理卷就是實際對應的物理存儲設備。我們最常見的就是磁盤分區等存儲設備。傳統的存儲管理方式是將物理設備格式化後,就直接mount到一個目錄上。在LVM中,PV是一個基礎物理單位,也是存儲池的基本組成部分。存儲分區要成為PV,需要調用LVM命令方法,在分區中記錄相應的元數據信息。

LVG(Logical Volume Group)邏輯卷組是LVM的重要組成部分。從結構上看,LVG位於PV和LV(Logical Volume)的中間,也是Linux存儲池的核心。若干個PV可以組成一個LVG。在分配LV(Logical Volume)的時候,也是在一個特定的LVG上進行分配,和PV的對應關系是通過LVM進行自動的管理對應。

LV(Logical Volume)邏輯卷是建立在LVG基礎上的分配空間。LV是從LVG的基礎上進行分配的,本質上是通過軟件方法進行管理的空間組。正是由於通過LVM控制,我們可以實現動態的LV大小調整,從存儲池中進行空間補充、回收。注意:LV適合LVG對應的,一個LV對操作系統和我們而言,是一個獨立的存儲空間。但是實質上,一個LV可能是一個PV的部分空間,也可能是跨多個PV。

下圖摘自Red Hat的網站資料(http://www.RedHat.com/magazine/009jul05/features/lvm2/),詳細說明了LVM幾個核心概念的關系。

下面介紹一下PE和LE。PE(Physical Extents)是PV的基本組成。每一個PV都是通過多個固定大小尺寸的PE組成。而LE(Logical Extent)與LV的關系類似,一個LV由多個固定大小的LE組成。目前LVM版本下,PE和LE的大小是相同的(注意!),默認都是4M。

PE和LE的機制就解決了LV橫跨多個PV的對應問題。LVG解決的就是LE和PE對應問題。

在Linux中管理LVM主要通過LVM管理工具和Linux內核支持。目前我們常見的Linux版本中,邏輯卷功能已經非常成熟。下面我們通過實驗介紹一下最基本的LVM使用。

2、環境准備和配置

我們選擇Linux 2.6內核版本進行試驗,也就是redhat 5.3。

[root@SimpleLinux ~]# uname -r

2.6.18-128.el5

使用LVM,要求內核中支持LVM,並且安裝了LVM管理相關的rpm包。我們可以使用rpm –qa進行驗證。

[root@SimpleLinux ~]# rpm -qa | grep lvm

system-config-lvm-1.1.5-1.0.el5

lvm2-2.02.40-6.el5

此時系統中,存儲環境如下:

[root@SimpleLinux ~]# df -h

FilesystemSizeUsed Avail Use% Mounted on

/dev/sda148G11G35G23% /

tmpfs449M0449M0% /dev/shm

[root@SimpleLinux ~]# fdisk -l

Disk /dev/sda: 54.3 GB, 54390718464 bytes

255 heads, 63 sectors/track, 6612 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device BootStartEndBlocksIdSystem

/dev/sda1*1642051568618+83Linux

/dev/sda2642166111534207+82Linux swap / Solaris

Disk /dev/sdb: 8589 MB, 8589934592 bytes

255 heads, 63 sectors/track, 1044 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device BootStartEndBlocksIdSystem

/dev/sdb1110458388607+8eLinux LVM

Disk /dev/sdc: 11.3 GB, 11331395584 bytes

255 heads, 63 sectors/track, 1377 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table

當前系統中包括三個盤,sda-c。其中sda已經被使用,我們在sdb和sdc上進行試驗。為了便於樣式,我們將sdc進行進一步格式化,分割為五個分區。

[root@SimpleLinux ~]# fdisk /dev/sdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

The number of cylinders for this disk is set to 1377.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n

Command action

eextended

pprimary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-1377, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-1377, default 1377): +2000M

(篇幅原因,省略部分……)

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@SimpleLinux ~]# fdisk -l

Disk /dev/sda: 54.3 GB, 54390718464 bytes

255 heads, 63 sectors/track, 6612 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device BootStartEndBlocksIdSystem

/dev/sda1*1642051568618+83Linux

/dev/sda2642166111534207+82Linux swap / Solaris

Disk /dev/sdb: 8589 MB, 8589934592 bytes

255 heads, 63 sectors/track, 1044 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device BootStartEndBlocksIdSystem

/dev/sdb1110458388607+8eLinux LVM

Disk /dev/sdc: 11.3 GB, 11331395584 bytes

255 heads, 63 sectors/track, 1377 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device BootStartEndBlocksIdSystem

/dev/sdc112441959898+83Linux

/dev/sdc2245488195993083Linux

/dev/sdc3489732195993083Linux

/dev/sdc473313775180962+5Extended

/dev/sdc57339761959898+83Linux

/dev/sdc69771377322100183Linux

下面就可以進行邏輯卷實驗。

更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2014-05/101880p2.htm

Copyright © Linux教程網 All Rights Reserved