LVM在线扩展磁盘实例

LVM在线扩展磁盘实例

1、添加磁盘,连接至主机。开机,进入系统。使用root登录,运行fdisk,将新加的磁盘分区

[root@xmydlinux ~]# fdisk –l

————————————————   
Disk /dev/hda: 6442 MB, 6442450944 bytes    
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System   
/dev/hda1   *           1          13      104391   83  Linux    
/dev/hda2              14         783     6185025   8e  Linux LVM

Disk /dev/hdb: 2147 MB, 2147483648 bytes     
16 heads, 63 sectors/track, 4161 cylinders    
Units = cylinders of 1008 * 512 = 516096 bytes

Disk /dev/hdb doesn’t contain a valid partition table   
————————————————

[root@xmydlinux ~]# fdisk /dev/hdb

————————————————   
Command (m for help): n  //创建分区    
Command action    
   e   extended    
   p   primary partition (1-4)


p  
Partition number (1-4): 1  
First cylinder (1-4161, default 1): 1  
Last cylinder or +size or +sizeM or +sizeK (1-4161, default 4161):  
Using default value 4161

Command (m for help): p   //查看分区

Disk /dev/hdb: 2147 MB, 2147483648 bytes   
16 heads, 63 sectors/track, 4161 cylinders    
Units = cylinders of 1008 * 512 = 516096 bytes

   Device Boot      Start         End      Blocks   Id  System   
/dev/hdb1               1        4161     2097112+  83  Linux

Command (m for help): t   //更改ID值(LVM卷为:8e)    
Selected partition 1    
Hex code (type L to list codes): 8e

Command (m for help): w  //保存退出    
The partition table has been altered!

Calling ioctl() to re-read partition table.   
————————————————

[root@xmydlinux ~]# fdisk -l

————————————————   
Disk /dev/hda: 6442 MB, 6442450944 bytes    
255 heads, 63 sectors/track, 783 cylinders    
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System   
/dev/hda1   *           1          13      104391   83  Linux    
/dev/hda2              14         783     6185025   8e  Linux LVM

Disk /dev/hdb: 2147 MB, 2147483648 bytes   
16 heads, 63 sectors/track, 4161 cylinders    
Units = cylinders of 1008 * 512 = 516096 bytes

   Device Boot      Start         End      Blocks   Id  System   
/dev/hdb1               1        4161     2097112+  8e  Linux LVM     
————————————————

2、创建PV

[root@xmydlinux ~]# pvcreate  /dev/hdb1    
  Physical volume "/dev/hdb1" successfully created

3、扩展VG

[root@xmydlinux ~]# vgextend /dev/VolGroup00  /dev/hdb1    
  Volume group "VolGroup00" successfully extended

运行vgdisplay ,查看扩展后的VG,如果显示容量增加,表示,VG扩展成功

[root@xmydlinux ~]# vgdisplay 
———————————————— 
— Volume group —    
  VG Name               VolGroup00    
  System ID            
  Format                lvm2    
  Metadata Areas        2    
  Metadata Sequence No  4    
  VG Access             read/write    
  VG Status             resizable    
  MAX LV                0    
  Cur LV                2    
  Open LV               2    
  Max PV                0    
  Cur PV                2    
  Act PV                2    
  VG Size               7.84 GB    
  PE Size               32.00 MB    
  Total PE              251    
  Alloc PE / Size       188 / 5.88 GB     
  Free  PE / Size       63 / 1.97 GB
    
  VG UUID               p1jDY9-SMaJ-wUA2-nKq9-okfi-CuBy-17mSyq    
————————————————

4、扩展LV

[root@xmydlinux ~]# lvextend -L +1.9G /dev/VolGroup00/LogVol00    
———————————————— 
  Rounding up size to full physical extent 1.91 GB    
  Extending logical volume LogVol00 to 6.78 GB    
  Logical volume LogVol00 successfully resized    
————————————————

5、激活VG

[root@xmydlinux ~]# vgchange -a y /dev/VolGroup00    
  2 logical volume(s) in volume group "VolGroup00" now active

6、调整文件系统大小

[root@xmydlinux ~]# e2fsck  -a /dev/VolGroup00/LogVol00  //调整前先检查下文件系统    
————————————————    
/dev/VolGroup00/LogVol00 is mounted. 

WARNING!!!  Running e2fsck on a mounted filesystem may cause   
SEVERE filesystem damage.

Do you really want to continue (y/n)? y

/dev/VolGroup00/LogVol00: recovering journal   
/dev/VolGroup00/LogVol00: Clearing orphaned inode 786561 (uid=500, gid=500, mode=0100600, size=0)    
/dev/VolGroup00/LogVol00: Clearing orphaned inode 786556 (uid=500, gid=500, mode=0100600, size=0)    
/dev/VolGroup00/LogVol00: Clearing orphaned inode 786554 (uid=500, gid=500, mode=0100600, size=0)    
/dev/VolGroup00/LogVol00: Clearing orphaned inode 786436 (uid=500, gid=500, mode=0100600, size=0)    
/dev/VolGroup00/LogVol00: Clearing orphaned inode 786435 (uid=500, gid=500, mode=0100600, size=0)    
/dev/VolGroup00/LogVol00: clean, 123302/1277952 files, 823124/1277952 blocks    
————————————————

[root@xmydlinux ~]# resize2fs /dev/VolGroup00/LogVol00    
————————————————    
resize2fs 1.39 (29-May-2006)    
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required    
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 1777664 (4k) blocks.    
The filesystem on /dev/VolGroup00/LogVol00 is now 1777664 blocks long.    
————————————————

在线扩容完成!

附LVM相关知识

附1、LVM介绍

LVM(Logicl Volume Manager),逻辑卷管理器,通过使用逻辑卷管理器对硬盘存储设备进行管理,可以实现硬盘空间的动态划分和调整。

结构图:

image

物理卷—–PV(Physical Volume)   
物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘。

卷组——–VG(Volumne Group)   
卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组。

逻辑卷—–LV(Logical Volume)   
逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷要以属于同一个卷组,也可以属于不同的多个卷组。

附2、lvm常用管理工具:

动作
物理卷
卷组逻辑卷
扫描pvscan vgscanlvscan
查看pvdisplayvgdisplaylvdisplay
新建pvcreatvgcreatlvcreat
卸载pvremovevgremovelvremove
增大无 vgextendlvextend
减小无 vgreducelvreduce
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值