博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
虚拟机硬盘扩容
阅读量:5114 次
发布时间:2019-06-13

本文共 8738 字,大约阅读时间需要 29 分钟。

测试机器环境:

VMware Workstation 12 虚拟机

虚拟机:

Linux版本:CentOS MinimalCD 6.5

Windows版本:Windows 7


查看原机器硬盘配置

增加磁盘容量有2种方案:

  1. 增加虚拟磁盘容量,下图将原盘20G扩容到50G:
  2. 添加一块新虚拟磁盘,下图增加一块50G的磁盘:

 

2种方案都要在系统里作扩容处理。

Linux系统扩容:

2种方案扩容基本相同,先将扩的磁盘容量分区,并转换成lvm盘,作pv,加入lv,将系统原有的lvm扩容,文件系统重定义大小。

以下是对第1种方案的详细步骤:

  • 用 fdisk 配置新的具有 8e system ID 的 partition

没有扩容前查看磁盘信息:

[root@localhost ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0009de9a   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              64        2611    20458496   8e  Linux LVMDisk /dev/mapper/VolGroup-lv_root: 18.9 GB, 18865979392 bytes255 heads, 63 sectors/track, 2293 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes255 heads, 63 sectors/track, 252 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000[root@localhost ~]# df -HFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       19G  704M   17G   5% /tmpfs                 515M     0  515M   0% /dev/shm/dev/sda1             500M   29M  445M   7% /boot

查看磁盘sda已扩展到50G:

[root@localhost ~]# fdisk -lDisk /dev/sda: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0009de9a   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              64        2611    20458496   8e  Linux LVMDisk /dev/mapper/VolGroup-lv_root: 18.9 GB, 18865979392 bytes255 heads, 63 sectors/track, 2293 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes255 heads, 63 sectors/track, 252 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

利用fdisk命令将未分区的磁盘分区,具体百度fdisk,并将新的分区改为lvm区。查看磁盘信息:

[root@localhost ~]# fdisk -lDisk /dev/sda: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000e545e   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              64        2611    20458496   8e  Linux LVM/dev/sda3            2611        6528    31457280   8e  Linux LVMDisk /dev/mapper/VolGroup-lv_root: 18.9 GB, 18865979392 bytes255 heads, 63 sectors/track, 2293 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes255 heads, 63 sectors/track, 252 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

分完区,sda3只是存于系统,但还没有加载这个设备,partprobe命令可以不重启及加载设备,但是Minimal版本没有安装这个命令,重启系统显然更加方便。

重启后查看设备:

[root@localhost ~]# ls /dev/sd*/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3
  • 利用 pvcreate 创建 PV

先查看一下pv:

[root@localhost ~]# pvscan    #查看pv信息   PV /dev/sda2   VG VolGroup        lvm2 [19.51 GiB / 0    free]  Total: 1 [19.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 0 [0   ]

将sda3做成pv

[root@localhost ~]#  pvcreate /dev/sda3    #将sda3创建成pv  Physical volume "/dev/sda3" successfully created[root@localhost ~]# pvscan   PV /dev/sda2   VG VolGroup        lvm2 [19.51 GiB / 0    free]  PV /dev/sda3                      lvm2 [30.00 GiB]  Total: 2 [49.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [30.00 GiB]
  • 利用 vgextend 将 PV 加入我们的VolGroup

    [root@localhost ~]# vgscan        #查看vg信息   Reading all physical volumes.  This may take a while...  Found volume group "VolGroup" using metadata type lvm2[root@localhost ~]# vgextend VolGroup /dev/sda3    #将sda3加入VolGroup  Volume group "VolGroup" successfully extended[root@localhost ~]# vgdisplay    #显示VG信息   --- Volume group ---  VG Name               VolGroup  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               49.50 GiB  PE Size               4.00 MiB  Total PE              12673  Alloc PE / Size       4994 / 19.51 GiB  Free  PE / Size       7679 / 30.00 GiB  VG UUID               cr8dzd-IkxI-gvEj-nA5K-gYlM-eYal-caOLdz
  • 利用 lvresize 将新加入的 PV 内的 PE 加入lv_root中,透过 resize2fs 将文件系统的容量确实添加。

    [root@localhost ~]# lvscan       #查看lv信息  ACTIVE            '/dev/VolGroup/lv_root' [17.57 GiB] inherit  ACTIVE            '/dev/VolGroup/lv_swap' [1.94 GiB] inherit[root@localhost ~]#  lvextend -L 30G /dev/VolGroup/lv_root /dev/sda3    #从sda3取容量,扩充lv_root到30G  Size of logical volume VolGroup/lv_root changed from 17.57 GiB (4498 extents) to 30.00 GiB (7680 extents).  Logical volume lv_root successfully resized.[root@localhost ~]# resize2fs /dev/VolGroup/lv_root resize2fs 1.41.12 (17-May-2010)Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing requiredold desc_blocks = 2, new_desc_blocks = 2Performing an on-line resize of /dev/VolGroup/lv_root to 7864320 (4k) blocks.The filesystem on /dev/VolGroup/lv_root is now 7864320 blocks long.[root@localhost ~]# pvs  PV         VG       Fmt  Attr PSize  PFree   /dev/sda2  VolGroup lvm2 a--u 19.51g     0   /dev/sda3  VolGroup lvm2 a--u 30.00g 17.57g         #上面的步骤将lv_root扩充到30G,sda3还剩余17.57G

    [root@localhost ~]# df -H

    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/VolGroup-lv_root
                           32G  748M   30G   3% /
    tmpfs                 515M     0  515M   0% /dev/shm
    /dev/sda1             500M   29M  445M   7% /boot

  另一种增加lv_root的示例 :
[root@localhost ~]# vgdisplay   --- Volume group ---  VG Name               VolGroup  System ID               Format                lvm2  Metadata Areas        2  Metadata Sequence No  5  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               49.50 GiB  PE Size               4.00 MiB  Total PE              12673  Alloc PE / Size       8176 / 31.94 GiB  Free  PE / Size       4497 / 17.57 GiB    #Free PE  VG UUID               cr8dzd-IkxI-gvEj-nA5K-gYlM-eYal-caOLdz[root@localhost ~]#  lvextend -l +4497 /dev/VolGroup/lv_root /dev/sda3  #参数 l 是使用pe数,目前freePE为4497,本命令行是将所有freePE增加给lv_root    Size of logical volume VolGroup/lv_root changed from 30.00 GiB (7680 extents) to 47.57 GiB (12177 extents).  Logical volume lv_root successfully resized.[root@localhost ~]#  resize2fs /dev/VolGroup/lv_root  resize2fs 1.41.12 (17-May-2010)Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing requiredold desc_blocks = 2, new_desc_blocks = 3Performing an on-line resize of /dev/VolGroup/lv_root to 12469248 (4k) blocks.The filesystem on /dev/VolGroup/lv_root is now 12469248 blocks long.[root@localhost ~]# pvs  PV         VG       Fmt  Attr PSize  PFree  /dev/sda2  VolGroup lvm2 a--u 19.51g    0   /dev/sda3  VolGroup lvm2 a--u 30.00g    0 [root@localhost ~]# vgs  VG       #PV #LV #SN Attr   VSize  VFree  VolGroup   2   2   0 wz--n- 49.50g    0 [root@localhost ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       47G  721M   44G   2% /tmpfs                 491M     0  491M   0% /dev/shm/dev/sda1             477M   28M  425M   7% /boot

 

Windows系统扩容:

Windows可以借助磁盘工具将增加的磁盘扩容进系统中,2008以上的系统可以直接借助系统的磁盘管理操作。这里不在详述。

转载于:https://www.cnblogs.com/ysztcn/p/6203013.html

你可能感兴趣的文章
过滤机的故障排除
查看>>
javascript小技巧
查看>>
C#登录窗口(访问数据库)的制作,类文件的制作及使用
查看>>
大小写转换
查看>>
[树状数组][二分] 洛谷 P2161 会场预约
查看>>
[数位dp] Jzoj P4239 光棍
查看>>
167. Two Sum II - Input array is sorted两数之和
查看>>
面试中关于Java你所需知道的的一切
查看>>
由一个activity跳转到另一个activity
查看>>
PLSQL
查看>>
浮动float的一些规则
查看>>
跳频通信(梅文华)pdf
查看>>
Java基础-重要版本
查看>>
POJ1006 中国剩余定理
查看>>
部署JUnit
查看>>
【图论 搜索】bzoj1064: [Noi2008]假面舞会
查看>>
Python补充之函数
查看>>
获取含有class为某个值的a标签或img标签
查看>>
接口测试概念
查看>>
【LeetCode】107. Binary Tree Level Order Traversal II (2 solutions)
查看>>