CentOS 6.5 LVM磁碟管理學習筆記
在系統運維和伺服器管理過程中,經常遇到伺服器磁碟容量不足,需要線上擴容的情況。普通磁碟分割槽的管理方式在邏輯分區劃好之後就無法改變其大小。而LVM可以實現Linux伺服器下面磁碟空間的線上擴容和動態管理,相對於普通的磁碟分割槽有很大的靈活性。
一、LVM簡介
LVM是 Logical VolumeManager(邏輯卷管理)的簡寫,它是Linux環境下對磁碟分割槽進行管理的一種機制,它由Heinz Mauelshagen在Linux 2.4核心上實現。LVM將一個或多個硬碟的分割槽在邏輯上進行組合,做為一個大的硬碟空間來使用,當硬碟的剩餘空間不夠的時候,可以將其它的硬碟加入到分割槽當中,這樣可以實現磁碟空間的動態管理。
二、LVM基本術語
物理卷(physical volume,PV):物理卷就是指硬碟分割槽,也可以是整個硬碟或已建立的RAID ,是LVM的基本儲存裝置,與普通物理儲存介質的區別是該裝置包含有LVM相關的管理引數。
卷組(volume group,VG):卷組是由一個或多個物理卷所組成的儲存池,在卷組上能建立一個或多個“LVM分割槽”(邏輯卷)。
邏輯卷(logical volume,LV):LVM的邏輯卷類似於非LVM系統中的硬碟分割槽,它建立在卷組之上,是一個標準的塊裝置,在邏輯卷之上可以建立檔案系統。
物理塊(physical extent,PE):物理卷以大小相等的物理塊為儲存的基本單位,同時也是
邏輯塊(logical extent,LE):邏輯卷以大小相等的邏輯塊為儲存的基本單位,在同一個卷組中,LE的大小和PE是相等的,並且一一對應。
三、通過LVM分割槽方式安裝Centos
1.選擇安裝型別,選擇最後一個複選框,即建立自定義佈局。
2.首先劃分/boot分割槽,/boot分割槽建議使用物理分割槽。
3.將剩餘空間劃分為一個物理卷(PV)。
4.建立一個卷組(VG)。預設卷組名為VolGroup00,修改卷組名為vg51cto_lv。
5.在VG上面建立邏輯卷(LV)。邏輯卷預設為LogVol00,LogVol01……末兩位由00開始依次遞增。
6.LVM分割槽完成。
7.df -h 檢視磁碟空間。
1 2 3 4 5 6 7 8 |
[[email protected] ~] # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg51cto_lv-LogVol01 9.9G 1.2G 8.2G 13% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 194M 29M 155M 16% /boot
/dev/mapper/vg51cto_lv-LogVol03 20G 172M 19G 1% /data
/dev/mapper/vg51cto_lv-LogVol02 5.0G 138M 4.6G 3% /home
/dev/mapper/vg51cto_lv-LogVol04 23G 173M 22G 1% /usr/local
|
四、LVM管理
第一部分:卷組(volume group ,VG)相關的操作。
1.檢視卷組(VG)名,卷組名為vg51cto_lv。
1 2 3 |
[[email protected] ~] # vgscan
Reading allphysical volumes. This may take awhile...
Foundvolume group "vg51cto_lv" using metadata type lvm2
|
2.檢視卷組(VG)包含的PV、LV資訊。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
[[email protected] ~] # vgdisplay -v vg51cto_lv
Usingvolume group(s) on command line
Findingvolume group "vg51cto_lv"
--- Volumegroup ---
VGName vg51cto_lv
SystemID
Format lvm2
MetadataAreas 1
MetadataSequence No 6
VGAccess read /write
VGStatus resizable
MAX LV 0
Cur LV 5
OpenLV 5
Max PV 0
Cur PV 1
Act PV 1
VGSize 59.80 GiB
PESize 4.00 MiB
TotalPE 15309
Alloc PE /Size 15309 / 59.80 GiB
Free PE / Size 0 / 0
VGUUID uF4S1y-21AZ-KOfs-rNIF-lFmN-wQ75-2sX7F1
--- Logicalvolume ---
LVPath /dev/vg51cto_lv/LogVol04
LVName LogVol04
VGName vg51cto_lv
LVUUID rvOZeO-Oz2G-wx7Z-u0b6-CvXj-FKEj-RwCLXO
LV WriteAccess read /write
LV Creationhost, time hadoop01, 2015-11-05 17:30:51 +0800
LVStatus available
# open 1
LVSize 22.80 GiB
CurrentLE 5837
Segments 1
Allocation inherit
Read aheadsectors auto
- currentlyset to 256
Blockdevice 253:2
--- Logicalvolume ---
LVPath /dev/vg51cto_lv/LogVol01
LVName LogVol01
VGName vg51cto_lv
LVUUID d6YKrd-fWMJ-x61I-cfWG-v2me-Hn8V-xdm96L
LV WriteAccess read /write
LV Creationhost, time hadoop01, 2015-11-05 17:30:56 +0800
LVStatus available
# open 1
LVSize 10.00 GiB
CurrentLE 2560
Segments 1
Allocation inherit
Read aheadsectors auto
- currentlyset to 256
Blockdevice 253:0
--- Logicalvolume ---
LVPath /dev/vg51cto_lv/LogVol00
LVName LogVol00
VGName vg51cto_lv
LVUUID hSyH2r-mvMV-th7q-geKg-sVpm-O1zJ-D6DwT8
LV WriteAccess read /write
LV Creationhost, time hadoop01, 2015-11-05 17:30:58 +0800
LVStatus available
# open 1
LVSize 2.00 GiB
CurrentLE 512
Segments 1
Allocation inherit
Read aheadsectors auto
- currentlyset to 256
Blockdevice 253:1
--- Logicalvolume ---
LVPath /dev/vg51cto_lv/LogVol03
LVName LogVol03
VGName vg51cto_lv
LVUUID gKHLfz-O5Lm-TGMq-2LcF-xcH1-ASea-QCVVNc
LV WriteAccess read /write
LV Creationhost, time hadoop01, 2015-11-05 17:30:58 +0800
LVStatus available
# open 1
LVSize 20.00 GiB
CurrentLE 5120
Segments 1
Allocation inherit
Read aheadsectors auto
- currentlyset to 256
Blockdevice 253:3
--- Logicalvolume ---
LVPath /dev/vg51cto_lv/LogVol02
LVName LogVol02
VGName vg51cto_lv
LVUUID lkqKmO-Dt0u-3CnB-UqeD-d6gc-2rmP-gWtKVp
LV WriteAccess read /write
LV Creationhost, time hadoop01, 2015-11-05 17:31:00 +0800
LVStatus available
# open 1
LVSize 5.00 GiB
CurrentLE 1280
Segments 1
Allocation inherit
Read aheadsectors auto
- currentlyset to 256
Blockdevice 253:4
---Physical volumes ---
PV Name /dev/sda2
PVUUID pKC6SA-fkfe-OAl2-scVr-tq0h-EAXD-AWpwgX
PVStatus allocatable
Total PE /Free PE 15309 / 0
|
3.修改卷組名,由vg51cto_lv修改成vg51cto。
1)修改卷組名的命令為vgrename,語法如下:
vgrename OldVolumeGroupNameNew VolumeGroupName
1 2 |
[[email protected] ~] # vgrename vg51cto_lv vg51cto
Volumegroup "vg51cto_lv" successfully renamed to "vg51cto"
|
2)修改/etc/fstab配置檔案,把vg51cto_lv修改成vg51cto。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[[email protected] ~] # vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 5 17:33:46 2015
#
# Accessible filesystems, by reference, aremaintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8)and/or blkid(8) for more info
#
/dev/mapper/vg51cto-LogVol01 / ext4 defaults 1 1
UUID=9c02e519-3b85-4918-b9fd-395535cab496 /boot ext4 defaults 1 2
/dev/mapper/vg51cto-LogVol03 /data ext4 defaults 1 2
/dev/mapper/vg51cto-LogVol02 /home ext4 defaults 1 2
/dev/mapper/vg51cto-LogVol04 /usr/local ext4 defaults 1 2
/dev/mapper/vg51cto-LogVol00 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
|
3)修改grub.conf配置檔案,把vg51cto_lv修改成vg51cto。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[[email protected] ~] # vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub aftermaking changes to this file
# NOTICE: You have a /boot partition. Thismeans that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg51cto_lv-LogVol01
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0) /grub/splash .xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root(hd0,0)
kernel /vmlinuz-2 .6.32-431.el6.x86_64 ro root= /dev/mapper/vg51cto-LogVol01 rd_NO_LUKSrd_LVM_LV=vg51cto /LogVol01 rd_LVM_LV=vg51cto /LogVol00 rd_NO_MD crashkernel=autoLANG=zh_CN.UTF-8 KEYBOARDTYPE=pcKEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2 .6.32-431.el6.x86_64.img
|
4)reboot重啟後用df -h檢視。
1 2 3 4 5 6 7 8 |
[[email protected] ~] # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg51cto-LogVol01 9.9G 1.2G 8.2G 13% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 194M 29M 155M 16% /boot
/dev/mapper/vg51cto-LogVol03 20G 172M 19G 1% /data
/dev/mapper/vg51cto-LogVol02 5.0G 138M 4.6G 3% /home
/dev/mapper/vg51cto-LogVol04 23G 173M 22G 1% /usr/local
|
第二部分:邏輯卷(logical volume,LV)相關的操作。
1.檢視邏輯卷(LV)名。
使用LVM安裝系統時,預設的卷組名為VolGroup00,卷組內的邏輯卷為LogVol00,LogVol01……末兩位由00開始依次遞增。
1 2 3 4 5 6 |
[[email protected] ~] # lvscan
ACTIVE '/dev/vg51cto/LogVol04' [22.80 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol01' [10.00 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol00' [2.00 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol03' [20.00 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol02' [5.00 GiB]inherit
|
2.檢視邏輯卷詳細資訊
lvdisplay 命令檢視所有邏輯卷的詳細資訊
lvdisplay 邏輯卷名稱
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[[email protected] ~] # lvdisplay /dev/vg51cto/LogVol00
--- Logicalvolume ---
LVPath /dev/vg51cto/LogVol00
LVName LogVol00
VGName vg51cto
LVUUID hSyH2r-mvMV-th7q-geKg-sVpm-O1zJ-D6DwT8
LV WriteAccess read /write
LV Creationhost, time hadoop01, 2015-11-05 17:30:58 +0800
LVStatus available
# open 1
LVSize 2.00 GiB
CurrentLE 512
Segments 1
Allocation inherit
Read aheadsectors auto
- currentlyset to 256
Block device 253:1
|
3.修改邏輯卷名
1)修改邏輯卷命令為lvrename,語法如下:
1 2 3 4 5 6 7 8 9 10 11 |
lvrename OldLogicalVolumePath NewLogicalVolumePath
[[email protected] ~] # lvrename /dev/vg51cto/LogVol00 /dev/vg51cto/lv_swap
Renamed "LogVol00" to "lv_swap" in volume group "vg51cto"
[[email protected] ~] # lvrename /dev/vg51cto/LogVol01 /dev/vg51cto/lv_root
Renamed "LogVol01" to "lv_root" in volume group "vg51cto"
[[email protected] ~] # lvrename /dev/vg51cto/LogVol02 /dev/vg51cto/lv_home
Renamed "LogVol02" to "lv_home" in volume group "vg51cto"
[[email protected] ~] # lvrename /dev/vg51cto/LogVol03 /dev/vg51cto/lv_data
Renamed "LogVol03" to "lv_data" in volume group "vg51cto"
[[email protected] ~] # lvrename /dev/vg51cto/LogVol04 /dev/vg51cto/lv_usr
Renamed "LogVol04" to "lv_usr" in volume group "vg51cto"
|
2)修改/etc/fstab配置檔案。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[[email protected] ~] # vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 5 17:33:46 2015
#
# Accessible filesystems, by reference, aremaintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8)and/or blkid(8) for more info
#
/dev/mapper/vg51cto-lv_root / ext4 defaults 1 1
UUID=9c02e519-3b85-4918-b9fd-395535cab496 /boot ext4 defaults 1 2
/dev/mapper/vg51cto-lv_data /data ext4 defaults 1 2
/dev/mapper/vg51cto-lv_home /home ext4 defaults 1 2
/dev/mapper/vg51cto-lv_usr /usr/local ext4 defaults 1 2
/dev/mapper/vg51cto-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
|
3)修改grub.conf配置檔案。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[[email protected] ~] # vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub aftermaking changes to this file
# NOTICE: You have a /boot partition. Thismeans that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg51cto_lv-LogVol01
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0) /grub/splash .xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root(hd0,0)
kernel /vmlinuz-2 .6.32-431.el6.x86_64 ro root= /dev/mapper/vg51cto-lv_root rd_NO_LUKSrd_LVM_LV=vg51cto /lv_root rd_LVM_LV=vg51cto /lv_swap rd_NO_MD crashkernel=autoLANG=zh_CN.UTF-8 KEYBOARDTYPE=pc KEYTABLE=usrd_NO_DM rhgb quiet
initrd /initramfs-2 .6.32-431.el6.x86_64.img
|
第三部分:物理卷(physical volume,PV)相關操作。
1.檢視物理卷(PV)名,這裡為/dev/sda2,linux中SCSI的第1塊硬碟為/dev/sda,第2塊硬碟為/dev/sdb,依此類推。
1 2 3 |
[[email protected] ~] # pvscan
PV /dev/sda2 VG vg51c
|