虚拟机磁盘逻辑卷如何扩容

云计算 虚拟化
空间不太够,所以在虚拟机上把分配磁盘空间扩大的20GB。在esx server上扩容磁盘空间的方法很简单,在此不提,下面具体说说如何把该扩容的磁盘空间在虚拟机上应用上去。

在esx server上安装虚拟机时,由于只分配了默认的8GB磁盘空间。空间不太够,所以在虚拟机上把分配磁盘空间扩大的20GB。在esx server上扩容磁盘空间的方法很简单,在此不提,下面具体说说如何把该扩容的磁盘空间在虚拟机上应用上去。

 以下是未扩容前的状态:

[root@localhost ~]# fdisk -l 
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes 
 
255 heads, 63 sectors/track, 2610 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        1044     8281507+  8e  Linux LVM 
 
  
 
[root@localhost ~]# df -h 
 
Filesystem            Size  Used Avail Use% Mounted on 
 
/dev/mapper/VolGroup-LogVol00 
 
                      7.0G  4.8G  1.8G  73% / 
 
/dev/sda1              99M   12M   82M  13% /boot 
 
tmpfs                 187M     0  187M   0% /dev/shm 
 
/dev/hdc              183M  183M     0 100% /media/VMware Tools 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.

可以看到sda有21.4GB,但是只利用了sda1和sda2;根目录挂载在/dev/mapper/VolGroup-LogVol00,我们要做的是,把sda上剩余的空间扩容到/dev/mapper/VolGroup-LogVol00。 

1)首先,通过fdisk /dev/sda命令将sda剩余空间创建一个分区:

[root@localhost ~]# fdisk /dev/sda 
 
The number of cylinders for this disk is set to 2610. 
 
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): m 
 
Command action 
 
   a   toggle a bootable flag 
 
   b   edit bsd disklabel 
 
   c   toggle the dos compatibility flag 
 
   d   delete a partition 
 
   l   list known partition types 
 
   m   print this menu 
 
   n   add a new partition 
 
   o   create a new empty DOS partition table 
 
   p   print the partition table 
 
   q   quit without saving changes 
 
   s   create a new empty Sun disklabel 
 
   t   change a partition's system id 
 
   u   change display/entry units 
 
   v   verify the partition table 
 
   w   write table to disk and exit 
 
   x   extra functionality (experts only
 
Command (m for help): n 
 
Command action 
 
   e   extended 
 
   p   primary partition (1-4) 
 

 
Partition number (1-4): 3 
 
First cylinder (1045-2610, default 1045): 
 
Using default value 1045 
 
Last cylinder or +size or +sizeM or +sizeK (1045-2610, default 2610): 
 
Using default value 2610 
 
Command (m for help): w 
 
The partition table has been altered! 
 
Calling ioctl() to re-read partition table
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 
 
The kernel still uses the old table
 
The new table will be used at the next reboot. 
 
Syncing disks. 
 
[root@localhost ~]# 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.

此时可以看到多了一个sda3的分区: 

[root@localhost ~]# fdisk -l 
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes 
 
255 heads, 63 sectors/track, 2610 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        1044     8281507+  8e  Linux LVM 
 
/dev/sda3            1045        2610    12578895   83  Linux 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

此时查看了一下/dev下,不知道为何没有/dev/sda3,于是重启了一下虚拟机RHEL,重启完成后,出现了/dev/sda3.

一开始在这个地方折腾了一会,如果不重启,在利用命令pvcreate /dev/sda3创建pv时,总是提示Device /dev/sda3 not found (or ignored by filtering).

重启完成后,进入lvm模式,创建pv:

lvm> pvcreate /dev/sda3 
  Physical volume "/dev/sda3" successfully created 
  • 1.
  • 2.

扩容vg:vgextend vg_gcc /dev/sda3

lvm> vgextend VolGroup /dev/sda3 
  /dev/cdrom: open failed: Read-only file system 
  Attempt to close device '/dev/cdrom' which is not open
  Volume group "VolGroup" successfully extended 
  • 1.
  • 2.
  • 3.
  • 4.

把lv扩容到vg的剩余容量:lvextend /dev/vg_gcc/lv_root /dev/sda3

lvm> lvextend /dev/VolGroup/LogVol00 /dev/sda3 
  Extending logical volume LogVol01 to 12.72 GB 
  Logical volume LogVol01 successfully resized 
  • 1.
  • 2.
  • 3.

***,通过resize2fs命令令新增的空间在线(on-line)生效:resize2fs /dev/vg_gcc/lv_root

[root@localhost dev]# resize2fs /dev/VolGroup/LogVol00  
resize2fs 1.39 (29-May-2006) 
Filesystem at /dev/VolGroup/LogVol00 is mounted on /; on-line resizing required 
Performing an on-line resize of /dev/VolGroup/LogVol00 to 5005312 (4k) blocks. 
The filesystem on /dev/VolGroup/LogVol00 is now 5005312 blocks long. 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

效果如下:

[root@localhost dev]# df -h 
Filesystem            Size  Used Avail Use% Mounted on 
/dev/mapper/VolGroup-LogVol00 
                       19G  4.8G   13G  28% / 
/dev/sda1              99M   12M   82M  13% /boot 
tmpfs                 187M     0  187M   0% /dev/shm 
/dev/hdc              3.4G  3.4G     0 100% /media/RHEL_5.2 x86_64 DVD 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

 至此,扩容已成功完成。

责任编辑:武晓燕 来源: 博客园
相关推荐

2021-12-28 07:47:26

ESXI虚拟机 添加新硬盘

2014-01-13 09:47:35

虚拟机

2012-04-10 10:29:29

2010-12-23 14:05:12

虚拟机

2020-11-29 17:00:51

VirtualBox虚拟硬盘Linux

2022-08-14 09:11:13

Kubernetes容器云原生

2012-05-18 10:22:23

2009-09-27 10:20:19

挂载虚拟机磁盘Xen环境

2010-07-26 09:02:38

2013-07-17 09:32:58

2010-02-26 15:28:15

Python虚拟机

2009-06-12 16:15:42

死锁Java虚拟机

2021-01-04 05:49:34

VMwareLinux虚拟机

2012-04-27 09:29:57

虚拟化虚拟机

2009-06-29 19:36:07

虚拟机备份虚拟环境

2013-11-19 14:05:08

VDP虚拟机

2018-07-10 15:10:50

OpenStack虚拟机metadata

2013-04-07 09:52:40

Ubuntu虚拟机虚拟化软件

2009-11-30 17:20:32

LINUX虚拟机磁盘

2009-11-10 11:02:20

VMwareLINUX虚拟机
点赞
收藏

51CTO技术栈公众号