分类: LINUX
2013-08-09 13:23:25
Form:baustem
The:
Date:2011-12-06
一、 添加lvm根分区添加空间
1.1 查看目前系统中存在的lvm组
[root@localhost ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup" using metadata type lvm2
1.2 查看新添加硬盘
[root@localhost ~]# fdisk –l
这里新添加的硬盘为 /dev/sdb
1.3 新建分区(可不建立,将整块硬盘添加)
[root@localhost ~]# fdisk /dev/sdb
n: 建立分区
p:建立主分区
w:保存
1.4 进入lvm分区模式
[root@localhost ~]# lvm
lvm>
1.5 将新硬盘创建为虚拟卷
lvm> pvcreate /dev/sdb1
1.6 将虚拟卷加入lvm卷组
1.6.1查看虚拟卷,可以看到,/dev/sda2在VolGroup组下,新建立的卷没有卷组
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID RodAAP-XHJC-mV6r-KLwW-i31Q-ND7q-QW12q5
--- Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 8.00 GiB / not usable 1.35 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2047
Free PE 55
Allocated PE 1992
PV UUID WYRYIi-YOWs-HO1A-Cr5S-BDuH-wAGc-AveLYY
1.6.2将新建立的虚拟卷加入VolGroup卷组
lvm> vgextend VolGroup /dev/sdb1
1.6.3查看加入后的空间变化
lvm> vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAXLV 0
CurLV 2
OpenLV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 19.50 GiB
PE Size 4.00 MiB
Total PE 7041
AllocPE/ Size 6986 / 19.29 GiB
Free PE / Size 55 / 8 GiB
VG UUID bfLDgX-U1wP-JUj4-R5I1-BGFn-G4Ju-97gq6M
可以看到VolGroup 卷组有空闲的空间8G
Free PE / Size 55 / 8 GiB
1.7 将新添加的空闲空间加入根分区
1.7.1产看目前lvm卷组的分区情况,可以看到lvm卷组里面有两个分区,一个为根分区,一个为swap分区。
lvm> lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup/lv_root
VG Name VolGroup
LV UUID rFdSRh-NqPQ-N2D5-QKXn-Mc7n-FpNj-OY6mnH
LV Write Access read/write
LV Status available
# open 1
LVSize 19.50 GiB
Current LE 6290
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup/lv_swap
VG Name VolGroup
LV UUID 8ZmrKe-gumz-zTID-2Kf5-TZ3f-jNer-At1510
LV Write Access read/write
LV Status available
# open 1
LVSize 2 GiB
Current LE 696
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
1.7.2将7G空间加入到根分区中,查看空间变化
lvm> lvextend -L +7G/dev/VolGroup/lv_root
lvm> vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAXLV 0
CurLV 2
OpenLV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 27.50 GiB
PE Size 4.00 MiB
Total PE 7041
AllocPE/ Size 6986 / 27.29 GiB
Free PE / Size 55 / 1 GiB
VG UUID bfLDgX-U1wP-JUj4-R5I1-BGFn-G4Ju-97gq6M
1.8 使分区变化生效
[root@localhost ~]# resize2fs /dev/VolGroup/lv_root
二、 添加lvm swap分区空间
2.1 首先卸载目前正在使用的swap分区
[root@localhost ~]# swapoff /dev/VolGroup/lv_swap
2.2 进入lvm分区模式,前面还剩余1G空间
2.3 将1.7步剩余的空间加入swap卷组(自行定义大小)
lvm> lvextend -L +800M/dev/VolGroup/lv_swap
2.4 格式化swap分区
[root@localhost ~]# mkswap /dev/VolGroup/lv_swap
2.5 挂载新的swap分区
[root@localhost ~]# swapon –va
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2850808 0 -1
(这里的/dev/dm-1 是/dev/VoGroup/lvm_swap )