欢迎光临
我们一直在努力

虚拟机磁盘扩容后扩充LVM逻辑卷

在VMware Esxi主机上安装虚拟机时,由于只分配了默认的50GB磁盘空间。今天要在虚拟机RHEL5.9上安装Oracle 11gR2,空间不太够,所以在虚拟机上把分配磁盘空间扩大到100GB。在Esxi 上扩容磁盘空间的方法很简单,在此不提,下面具体说说如何把该扩容的磁盘空间在虚拟机上应用上去。

扩充之前:

[root@tedb ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       15G  4.1G  9.5G  31% /
/dev/mapper/VolGroup00-LogVol02
                       25G   11G   13G  46% /db
/dev/sda1              99M   25M   70M  26% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm

其中/db就是需要扩充的对象
1、在VMware Esxi主机上将现有磁盘50G增加到100G,之后重新启动Linux系统,此操作简单不再详细解释;

2、使用命令查看扩充的容量是否可以fdisk

[root@tedb ~]# fdisk  -l

Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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        6527    52323705   8e  Linux LVM

Disk /dev/dm-0: 15.8 GB, 15804137472 bytes
255 heads, 63 sectors/track, 1921 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 27.2 GB, 27279753216 bytes
255 heads, 63 sectors/track, 3316 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-1 doesn't contain a valid partition table

Disk /dev/dm-2: 10.4 GB, 10468982784 bytes
255 heads, 63 sectors/track, 1272 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-2 doesn't contain a valid partition table
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@tedb ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       15G  4.1G  9.5G  31% /
/dev/mapper/VolGroup00-LogVol02
                       25G   11G   13G  46% /db
/dev/sda1              99M   25M   70M  26% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm

磁盘/dev/sda的容量已经从50G变成100G啦!但是新增的50G目前还无法使用。

3、将新增的50G容量建立为新的LVM卷组

[root@tedb ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 13054.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n        #新建分区
Command action
   e   extended
   p   primary partition (1-4)
p                             #新建分区类型
Partition number (1-4): 3     #新分区编号
First cylinder (6528-13054, default 6528): 6528     
Last cylinder or +size or +sizeM or +sizeK (6528-13054, default 13054): 13054
#以上两行为指定分区的大小,使用默认值即可
Command (m for help): t       
Partition number (1-4): 3     
Hex code (type L to list codes): 8e    #修改为LVM
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): w      #保存分区变更
The partition table has been altered!

Calling ioctl() to re-read partition table.
......
The new table will be used at the next reboot.
#完成之后需要重启,重启之后看新的LVM /dev/sda3分区是否存在
[root@tedb ~]# fdisk -l

Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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        6527    52323705   8e  Linux LVM
/dev/sda3            6528       13054    52428127+  8e  Linux LVM
#/dev/sda3已经存在啦!可以进行逻辑卷的拉伸步骤啦!

4、 创建PV

[root@tedb ~]# pvcreate /dev/sda3
  Writing physical volume data to disk "/dev/sda3"
  Physical volume "/dev/sda3" successfully created

5、将PV添加到VG(卷组)

[root@tedb ~]# vgextend /dev/mapper/VolGroup00 /dev/sda3
  Volume group "VolGroup00" successfully extended
[root@tedb ~]# vgs /dev/mapper/VolGroup00
  VG         #PV #LV #SN Attr   VSize  VFree 
  VolGroup00   2   3   0 wz--n- 99.84G 49.97G

经过以上步骤看见vg下面已经有剩余的空间啦,现在开始拉伸逻辑卷吧

6、拉伸逻辑卷更新文件系统
/db所处挂载的逻辑卷是/dev/mapper/VolGroup00-LogVol02 我们将拉伸/dev/mapper/VolGroup00-LogVol02 49G空间

[root@tedb ~]# lvextend -L +49G /dev/mapper/VolGroup00-LogVol02 
  Extending logical volume LogVol02 to 74.41 GB
  Logical volume LogVol02 successfully resized
[root@tedb ~]# 
[root@tedb ~]# resize2fs /dev/mapper/VolGroup00-LogVol02
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-LogVol02 is mounted on /db; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-LogVol02 to 19505152 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-LogVol02 is now 19505152 blocks long.

[root@tedb ~]# 
[root@tedb ~]# 
[root@tedb ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       15G  4.1G  9.5G  31% /
/dev/mapper/VolGroup00-LogVol02
                       73G   11G   58G  16% /db
/dev/sda1              99M   25M   70M  26% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm

到目前为止,有足够的空间玩啦!

未经允许不得转载:SRE空间 » 虚拟机磁盘扩容后扩充LVM逻辑卷

分享到:更多 ()

评论 抢沙发

评论前必须登录!

 

oracle