LVM 创建新的逻辑卷
2015-12-24 by dongnan
环境
- XenServer创建的虚拟机
- 虚拟机操作系统 CentOS 6.7
- 虚拟磁盘 xvda空间为15GB,并使用LVM管理磁盘
目标
- 调整虚拟机磁盘 xvda为50GB空间。
- 新的磁盘空间以 LVM方式划分给新分区 /data(便于后续文件系统扩展)。
操作步骤
调整虚拟机磁盘过程省略。
磁盘分区
使用 fdisk 命令创建新的分区。
# 执行命令
fdisk /dev/xvda
n # 创建新的分区
Command action
   e   extended
   p   primary partition (1-4)
e # 表示为扩展分区
Partition number (1-4): 3 #扩展分区编号
First cylinder (1959-6527, default 1959):
Using default value 1959
Last cylinder, +cylinders or +size{K,M,G} (1959-6527, default 6527):
Using default value 6527
Command (m for help): n # 创建逻辑分区
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l                       # l 表示逻辑
First cylinder (1959-6527, default 1959):
Using default value 1959
Last cylinder, +cylinders or +size{K,M,G} (1959-6527, default 6527):
Using default value 6527
Command (m for help): t # 调整分区类型
Partition number (1-5): 5
Hex code (type L to list codes): 8e  # 8e 表示lvm
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): p  # 分区信息
Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008fe04
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          52      409600   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              52        1959    15318016   8e  Linux LVM
/dev/xvda3            1959        6527    36699487+   5  Extended
/dev/xvda5            1959        6527    36699456   8e  Linux LVM
Command (m for help): w #保存并退出
重启系统
sync && reboot
LVM逻辑卷
逻辑卷名称
vgs
VG       #PV #LV #SN Attr   VSize VFree
VolGroup   2   2   0 wz--n- 49.60g 4.00m
创建物理卷
pvcreate /dev/xvda5
Physical volume "/dev/xvda5" successfully created
扩展卷组
vgextend VolGroup /dev/xvda5
Volume group "VolGroup" successfully extended
获得可用PE
vgdisplay | grep Free
Free  PE / Size       8959 / 35.00 GiB
创建新的逻辑卷
lvcreate -l 8959 -n lv_data VolGroup
Logical volume "lv_data" created.
格式化并挂载分区
# 格式化分区
mkfs.ext4 /dev/VolGroup/lv_data
# 挂载分区
mkdir /data/ 
mount /dev/VolGroup/lv_data /data/
验证
剩余PE
vgdisplay | grep Free
Free  PE / Size       0 / 0
分区信息
df -Th | tail -n2
/dev/mapper/VolGroup-lv_data
ext4    35G   48M   33G   1% /data