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

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

作者:gnix 2018-07-31 13:51:16

云计算

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

专注于为中小企业提供成都网站设计、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业长垣免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

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

 以下是未扩容前的状态:

  
 
 
 
  1. [root@localhost ~]# fdisk -l
  2. Disk /dev/sda: 21.4 GB, 21474836480 bytes
  3. 255 heads, 63 sectors/track, 2610 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5.    Device Boot      Start         End      Blocks   Id  System
  6. /dev/sda1   *           1          13      104391   83  Linux
  7. /dev/sda2              14        1044     8281507+  8e  Linux LVM
  8.  
  9. [root@localhost ~]# df -h
  10. Filesystem            Size  Used Avail Use% Mounted on
  11. /dev/mapper/VolGroup-LogVol00
  12.                       7.0G  4.8G  1.8G  73% /
  13. /dev/sda1              99M   12M   82M  13% /boot
  14. tmpfs                 187M     0  187M   0% /dev/shm
  15. /dev/hdc              183M  183M     0 100% /media/VMware Tools

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

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

  
 
 
 
  1. [root@localhost ~]# fdisk /dev/sda
  2. The number of cylinders for this disk is set to 2610.
  3. There is nothing wrong with that, but this is larger than 1024,
  4. and could in certain setups cause problems with:
  5. 1) software that runs at boot time (e.g., old versions of LILO)
  6. 2) booting and partitioning software from other OSs
  7.    (e.g., DOS FDISK, OS/2 FDISK)
  8. Command (m for help): m
  9. Command action
  10.    a   toggle a bootable flag
  11.    b   edit bsd disklabel
  12.    c   toggle the dos compatibility flag
  13.    d   delete a partition
  14.    l   list known partition types
  15.    m   print this menu
  16.    n   add a new partition
  17.    o   create a new empty DOS partition table
  18.    p   print the partition table
  19.    q   quit without saving changes
  20.    s   create a new empty Sun disklabel
  21.    t   change a partition's system id
  22.    u   change display/entry units
  23.    v   verify the partition table
  24.    w   write table to disk and exit
  25.    x   extra functionality (experts only)
  26. Command (m for help): n
  27. Command action
  28.    e   extended
  29.    p   primary partition (1-4)
  30. p
  31. Partition number (1-4): 3
  32. First cylinder (1045-2610, default 1045):
  33. Using default value 1045
  34. Last cylinder or +size or +sizeM or +sizeK (1045-2610, default 2610):
  35. Using default value 2610
  36. Command (m for help): w
  37. The partition table has been altered!
  38. Calling ioctl() to re-read partition table.
  39. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
  40. The kernel still uses the old table.
  41. The new table will be used at the next reboot.
  42. Syncing disks.
  43. [root@localhost ~]#

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

  
 
 
 
  1. [root@localhost ~]# fdisk -l
  2. Disk /dev/sda: 21.4 GB, 21474836480 bytes
  3. 255 heads, 63 sectors/track, 2610 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5.    Device Boot      Start         End      Blocks   Id  System
  6. /dev/sda1   *           1          13      104391   83  Linux
  7. /dev/sda2              14        1044     8281507+  8e  Linux LVM
  8. /dev/sda3            1045        2610    12578895   83  Linux

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

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

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

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

扩容vg:vgextend vg_gcc /dev/sda3

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

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

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

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

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

效果如下:

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

 至此,扩容已成功完成。

分享名称:虚拟机磁盘逻辑卷如何扩容
文章转载:http://www.hantingmc.com/qtweb/news11/400461.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联