整合小容量磁盤和實作分區的動态伸縮。
boot用來存放引導檔案,不要基于LVM建立,開機的過程中不識别邏輯卷。
PV(Physical Volume,實體卷):實體分區,或整個實體磁盤,由PE(Physical Extent,基本單元)組成。
VG(Volume Group,卷組):一個或多個實體卷組成的整體。
LV(Logical Volume,邏輯卷):從卷組中分割出的一塊邏輯存儲空間,課通過格式化建立檔案系統。
功能
實體卷
卷組
邏輯卷
scan(掃描)
pvscan
vgscan
lvscan
create(建立)
pvcreate
vgcreate
lvcreate
display(顯示)
pvdisplay
vgdisplay
lvdisplay
remove(删除)
pvremove
vgremove
lvremove
extend(擴充)
vgextend
lvextend
reduce(減少)
vgreduce
lvreduce
圖形管理程式:system-config-lvm
LVM建立過程:建立PV-->建立-->VG-->建立LV-->格式化LV-->挂載
LVM删除過程:解除安裝-->删除LV-->删除VG-->删除PV
pvcreate 裝置路徑
vgcreate 卷組名 裝置路徑
lvcreate -L 大小 -n 邏輯卷名 卷組名
建立LVM實驗步驟:
添加一塊硬碟20GB:
[root@node0 ~]# lsblk # 檢視添加的硬碟
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 3.6G 0 rom /dvd
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 1000M 0 part [SWAP]
└─sda3 8:3 0 18.8G 0 part /
sdb 8:16 0 20G 0 disk
[root@node0 ~]# parted /dev/sdb # 對硬碟進行分區
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel # 建立分區表
New disk label type? gpt # 分區表類型為GPT
(parted) mkpart # 建立分區
Partition name? []?
File system type? [ext2]? ext4 # 寫入檔案系統的類型
Start? 0 # 開始位置
End? 50% # 結束位置
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i # 忽略
(parted) p # 顯示分區結果
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.7GB 10.7GB
(parted) mkpart
File system type? [ext2]? ext4
Start? 50%
End? 100%
(parted) p
2 10.7GB 21.5GB 10.7GB
(parted) quit
[root@node0 ~]# pvscan # 掃描現有的PV
No matching physical volumes found
[root@node0 ~]# pvcreate /dev/sdb1 /dev/sdb2 # 建立PV
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
[root@node0 ~]# vgcreate vg01 /dev/sdb1 /dev/sdb2
Volume group "vg01" successfully created
[root@node0 ~]# vgscan # 掃描現有的VG
Reading all physical volumes. This may take a while...
Found volume group "vg01" using metadata type lvm2
[root@node0 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg01 2 0 0 wz--n- 19.99g 19.99g
[root@node0 ~]# lvcreate -L 15GB -n lv01 vg01 # 建立LV
Logical volume "lv01" created.
[root@node0 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv01 vg01 -wi-a----- 15.00g
[root@node0 ~]# lvscan # 掃描現有的LV
ACTIVE '/dev/vg01/lv01' [15.00 GiB] inherit
[root@node0 ~]# mkfs.ext4 /dev/vg01/lv01 # 格式化LV
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983040 inodes, 3932160 blocks
196608 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4026531840
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@node0 ~]# lsblk # 檢視裝置
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 3.6G 0 rom /dvd
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 1000M 0 part [SWAP]
└─sda3 8:3 0 18.8G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 10G 0 part
│ └─vg01-lv01 (dm-0) 253:0 0 15G 0 lvm
└─sdb2 8:18 0 10G 0 part
└─vg01-lv01 (dm-0) 253:0 0 15G 0 lvm
擴充、縮減LV:
[root@node0 ~]# lvextend -L +2GB /dev/vg01/lv01 # 擴充LV
Size of logical volume vg01/lv01 changed from 15.00 GiB (3840 extents) to 17.00 GiB (4352 extents).
Logical volume lv01 successfully resized
[root@node0 ~]# lvs
lv01 vg01 -wi-a----- 17.00g
[root@node0 ~]# lvreduce -L -1GB /dev/vg01/lv01 # 減小LV
WARNING: Reducing active logical volume to 16.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv01? [y/n]: y
Size of logical volume vg01/lv01 changed from 17.00 GiB (4352 extents) to 16.00 GiB (4096 extents).
擴充、縮減VG:
[root@node0 ~]# lsblk # 添加硬碟
sr0 11:0 1 3.6G 0 rom /dvd
sdb 8:16 0 20G 0 disk
│ └─vg01-lv01 (dm-0) 253:0 0 16G 0 lvm
└─vg01-lv01 (dm-0) 253:0 0 16G 0 lvm
sdc 8:32 0 20G 0 disk
[root@node0 ~]# parted /dev/sdc # 為新添加的硬碟分區
Using /dev/sdc
(parted) mkl
New disk label type? Gpt # 建立分區表
(parted) mkpart # 建立分區
Start? 0%
(parted) p # 檢視結果
Disk /dev/sdc: 21.5GB
1 1049kB 21.5GB 21.5GB
(parted) quit # 退出parted分區工具
Information: You may need to update /etc/fstab.
[root@node0 ~]# lsblk # 檢視結果
sdb 8:16 0 20G 0 disk
└─sdc1 8:33 0 20G 0 part
[root@node0 ~]# pvcreate /dev/sdc1 # 建立PV
Physical volume "/dev/sdc1" successfully created
[root@node0 ~]# vgextend vg01 /dev/sdc1 # 擴充VG
Volume group "vg01" successfully extended
[root@node0 ~]# vgs # 檢視擴充結果
vg01 3 1 0 wz--n- 39.99g 23.99g
root@node0 ~]# lvextend -L +10GB -n /dev/vg01/lv01 # 擴充LV
Size of logical volume vg01/lv01 changed from 16.00 GiB (4096 extents) to 26.00 GiB (6656 extents).
[root@node0 ~]# lvs # 檢視擴充結果
lv01 vg01 -wi-a----- 26.00g
挂載LV:
[root@node0 ~]# mkdir /lv01_data # 建立用于挂載的目錄
[root@node0 ~]# ll /dev/vg01/lv01
lrwxrwxrwx. 1 root root 7 Nov 20 16:59 /dev/vg01/lv01 -> ../dm-0
[root@node0 ~]# vim /etc/fstab # 編輯/etc/fstab配置檔案
/dev/vg01/lv01 /lv01_data ext4 defaults 0 0
[root@node0 ~]# mount -a # 重新整理/etc/fstab
[root@node0 ~]# lsblk # 檢視結果
├─sda1 8:1 0 200M 0 part /boot
│ └─vg01-lv01 (dm-0) 253:0 0 26G 0 lvm /lv01_data
└─vg01-lv01 (dm-0) 253:0 0 26G 0 lvm /lv01_data
縮減檔案系統:
[root@node0 ~]# resize2fs /dev/vg01/lv01 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg01/lv01 to 2621440 (4k) blocks.
The filesystem on /dev/vg01/lv01 is now 2621440 blocks long.
删除LVM:
[root@node0 ~]# umount /lv01_data/ # 解除安裝檔案系統
[root@node0 ~]# lvremove /dev/vg01/lv01 # 删除LV
Do you really want to remove active logical volume lv01? [y/n]: y # 确認删除
Logical volume "lv01" successfully removed
[root@node0 ~]# lvs # 檢視結果
[root@node0 ~]# vgremove /dev/vg01 # 删除VG
Volume group "vg01" successfully removed
[root@node0 ~]# vgs # 檢視結果
[root@node0 ~]# lsblk
├─sdb1 8:17 0 10G 0 part
└─sdb2 8:18 0 10G 0 part
sdc 8:32 0 20G 0 disk
└─sdc1 8:33 0 20G 0 part
[root@node0 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 10.00g 10.00g
/dev/sdb2 lvm2 --- 10.00g 10.00g
/dev/sdc1 lvm2 --- 20.00g 20.00g
[root@node0 ~]# pvremove /dev/sdb1 /dev/sdb2 /dev/sdc1 # 删除PV
Labels on physical volume "/dev/sdb1" successfully wiped
Labels on physical volume "/dev/sdb2" successfully wiped
Labels on physical volume "/dev/sdc1" successfully wiped
[root@node0 ~]# pvs # 檢視結果
删除/etc/fstab檔案中的配置條目。
本文轉自 棋帥小七 51CTO部落格,原文連結:http://blog.51cto.com/xvjunjie/2044320