您的位置:首页 > 运维架构 > Linux

linux下LVM添加磁盘实践操作

2013-09-11 22:34 330 查看
LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2.4内核上实现,目前最新版本为:稳定版1.0.5,开发版 1.1.0-rc2,以及LVM2开发版。

LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性

可以看一下lvm的示意图

每个磁盘可以分成多个分区,每个分区相当于一个pv,将pv化分成vg,在vg的基础上创建逻辑分区lv,逻辑分区lv上创建操作系统的文件系统。注意boot需要直接建到物理分区上去的。



RedHat默认情况下是安装lvm包的。

检测操作系统是否安装了lvm

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

system-config-lvm-1.1.4-1.3.el4

lvm2-2.02.42-5.el4

在支持热插拔的服务器上安装一块硬盘。

先用partprobe扫描是否有新的磁盘在用fdisk -l查看磁盘,我安装的磁盘就是最后一个

Disk /dev/sdg: 1073 MB, 1073741824 bytes

[root@rac3 ~]# partprobe

[root@rac3 ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sda1 * 1 13 104391 83 Linux

/dev/sda2 14 140 1020127+ 8e Linux LVM

/dev/sda3 141 1305 9357862+ 8e Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdb1 1 37 297171 83 Linux

/dev/sdb2 38 74 297202+ 83 Linux

/dev/sdb3 75 561 3911827+ 83 Linux

/dev/sdb4 562 1305 5976180 83 Linux

Disk /dev/sdc: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdc1 1 130 1044193+ 83 Linux

Disk /dev/sdd: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdd1 1 130 1044193+ 83 Linux

Disk /dev/sde: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sde1 1 522 4192933+ 83 Linux

Disk /dev/sdf: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdf1 1 522 4192933+ 8e Linux LVM

Disk /dev/sdg: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

1、先对磁盘进行分区格式化

[root@rac3 ~]# fdisk /dev/sdg

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.

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

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-130, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):

Using default value 130

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

2、创建pv,

如果想将整个磁盘创建成一个物理卷,用下面,

[root@rac3 ~]# pvcreate /dev/sdg

Physical volume "/dev/sdg" successfully created

也可以将当个分区创建成一个物理卷

[root@rac3 ~]# pvcreate /dev/sdg1

Physical volume "/dev/sdg1" successfully created

查看所有的pv

[root@rac3 ~]# pvscan

PV /dev/sda2 VG VolGroup00 lvm2 [992.00 MB / 0 free]

PV /dev/sda3 VG VolGroup00 lvm2 [8.91 GB / 0 free]

PV /dev/sdf1 VG VolGroup00 lvm2 [3.97 GB / 0 free]

PV /dev/sdg lvm2 [1.00 GB]

PV /dev/sdg1 lvm2 [1019.72 MB]

Total: 5 [15.84 GB] / in use: 3 [13.84 GB] / in no VG: 2 [2.00 GB]

查看物理卷组

[root@rac3 ~]# vgscan

Reading all physical volumes. This may take a while...

Found volume group "VolGroup00" using metadata type lvm2

可以看到目前只有一个物理卷组

可以将新添加的物理卷添加到这个物理卷组中

[root@rac3 ~]# vgextend VolGroup00 /dev/sdg1

Volume group "VolGroup00" successfully extended

查看已经有的lv

[root@rac3 ~]# lvscan

ACTIVE '/dev/VolGroup00/LogVol01' [12.88 GB] inherit

ACTIVE '/dev/VolGroup00/LogVol00' [992.00 MB] inherit

可以看到刚才扩展的VolGroup00上创建了两个lv

扩展系统文件占用的那个lv /dev/VolGroup00/LogVol01

在扩展的时候先看看vg空闲空间

--- Volume group ---

VG Name VolGroup00

System ID

Format lvm2

Metadata Areas 4

Metadata Sequence No 8

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 2

Open LV 2

Max PV 0

Cur PV 4

Act PV 4

VG Size 14.81 GB

PE Size 32.00 MB

Total PE 474

Alloc PE / Size 474 / 14.81 GB

Free PE / Size 0 / 0 --这里显示vg的空余空间

VG UUID RC2l2s-SAFG-IeDh-qKiT-wDwf-bDfj-DGBoKo

扩展lv

[root@rac3 ~]# lvresize -L +0.96G /dev/VolGroup00/LogVol01

Rounding up size to full physical extent 992.00 MB

Extending logical volume LogVol01 to 13.84 GB

Logical volume LogVol01 successfully resized

这时候需要在线重建lv

[root@rac3 ~]# ext2online /dev/mapper/VolGroup00-LogVol01

查看文件系统已经添加上去了,/dev/mapper/VolGroup00-LogVol01多了1G的空间

[root@rac3 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol01

14G 7.9G 5.2G 61% /

/dev/sda1 99M 14M 81M 14% /boot

none 196M 0 196M 0% /dev/shm

/dev/sdc1 1020M 145M 875M 15% /ocr

/dev/sdd1 1020M 147M 873M 15% /votingdisk

转自:/article/11231846.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: