美文网首页
VMware Linux(Centos)虚拟机扩容根目录磁盘空间

VMware Linux(Centos)虚拟机扩容根目录磁盘空间

作者: 一件小毛衣 | 来源:发表于2019-03-17 13:45 被阅读0次

    1:编辑虚拟机设置,点击[硬盘],选择[扩展] 填写大小:


    1.jpg 2.jpg

    点击扩展后VMware提示磁盘已经成功扩展。


    3.png

    完成扩展后,需从客户机操作系统内部对磁盘【重新分区】和【扩展文件系统】

    2:启动虚拟机操作系统Centos,查看磁盘情况:

    # fdisk -l
    

    显示如下:

    Disk /dev/sda: 32.2 GB, 32212254720 bytes
    255 heads, 63 sectors/track, 3916 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00094582
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        2611    20458496   8e  Linux LVM
    
    Disk /dev/mapper/vg_rxf-lv_root: 18.9 GB, 18865979392 bytes
    255 heads, 63 sectors/track, 2293 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/mapper/vg_rxf-lv_swap: 2080 MB, 2080374784 bytes
    255 heads, 63 sectors/track, 252 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    

    可以看见分区情况如下:

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        2611    20458496   8e  Linux LVM
    

    3:创建分区sda3:
    输入指令

    # fdisk /dev/sda
    

    根据命令提示创建分区:

    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): n  #输入n表示创建新分区
    Command action
       e   extended
       p   primary partition (1-4)
    p       #输入p
    Partition number (1-4): 3 #输入3,表示sda3,前面已经有2个了
    First cylinder (2611-3916, default 2611): #回车,默认值
    Using default value 2611
    Last cylinder, +cylinders or +size{K,M,G} (2611-3916, default 3916):   #回车,默认值
    Using default value 3916
    
    Command (m for help): w #输入w保存,退出
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
    

    再查看分区情况

    # fdisk -l
    

    情况如下:

    Disk /dev/sda: 32.2 GB, 32212254720 bytes
    255 heads, 63 sectors/track, 3916 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00094582
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        2611    20458496   8e  Linux LVM
    /dev/sda3            2611        3916    10483750   83  Linux
    
    Disk /dev/mapper/vg_rxf-lv_root: 18.9 GB, 18865979392 bytes
    255 heads, 63 sectors/track, 2293 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/mapper/vg_rxf-lv_swap: 2080 MB, 2080374784 bytes
    255 heads, 63 sectors/track, 252 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    

    可以看见现在的分区情况如下:

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        2611    20458496   8e  Linux LVM
    /dev/sda3            2611        3916    10483750   83  Linux
    

    这时分区已经变成3个了,但是还没有挂载,还不能用。
    4:重启操作系统

    # reboot
    

    5:格式化新分区ext3

    # mkfs -t ext3 /dev/sda3
    

    显示情况如下:

    mke2fs 1.41.12 (17-May-2010)
    文件系统标签=
    操作系统:Linux
    块大小=4096 (log=2)
    分块大小=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    655360 inodes, 2620937 blocks
    131046 blocks (5.00%) reserved for the super user
    第一个数据块=0
    Maximum filesystem blocks=2684354560
    80 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
    
    正在写入inode表: 完成                            
    Creating journal (32768 blocks): 完成
    Writing superblocks and filesystem accounting information: 完成
    
    This filesystem will be automatically checked every 29 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    

    6:将物理硬盘分区初始化为物理卷,以便LVM使用,输入指令

    # lvs
    

    显示如下:

      LV      VG     Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
      lv_root vg_rxf -wi-ao---- 17.57g                                             
      lv_swap vg_rxf -wi-ao----  1.94g  
    

    输入指令:

    # pvcreate /dev/sda3
    

    显示如下:

      Physical volume "/dev/sda3" successfully created
    

    7:向卷组中添加物理卷来增加容量。
    输入df -h 查看lvm组名

    # df -h
    
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/mapper/vg_rxf-lv_root   18G   18G  112M 100% /
    tmpfs                       931M  4.0K  931M   1% /dev/shm
    /dev/sda1                   485M   35M  425M   8% /boot
    

    其中vg_rxf为根所在组名.
    输入指令,增加卷组的容量

    # vgextend vg_rxf /dev/sda3
    
      Volume group "vg_rxf" successfully extended
    

    8:查看可以扩展的空间大小:

    vgdisplay
    
      --- Volume group ---
      VG Name               vg_rxf
      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               29.50 GiB
      PE Size               4.00 MiB
      Total PE              7553
      Alloc PE / Size       4994 / 19.51 GiB
      Free  PE / Size       2559 / 10.00 GiB
      VG UUID               KFyuD1-cj5n-cukx-z1Zf-Gg2T-IQLT-v6BD4N
    

    Free PE / Size 就是可以提供分配的自由空间,最多10.00 GiB,在扩展时输入小于该值
    9:扩充磁盘空间

    # lvextend -L+9G /dev/mapper/vg_rxf-lv_root /dev/sda3
    
      Extending logical volume lv_root to 26.57 GiB
      Logical volume lv_root successfully resized
    

    10:使用e2fsck指令查看检测文件系统错误

    # e2fsck -a /dev/mapper/vg_rxf-lv_root
    
    /dev/mapper/vg_rxf-lv_root is mounted.
    e2fsck: 无法继续, 中止.
    

    11:使用resize2fs指令来增大或者搜索未加载的"ext2/ext3"文件系统的大小

    resize2fs /dev/mapper/vg_rxf-lv_root
    
    Filesystem at /dev/mapper/vg_rxf-lv_root is mounted on /; on-line resizing required
    old desc_blocks = 2, new_desc_blocks = 2
    Performing an on-line resize of /dev/mapper/vg_rxf-lv_root to 6965248 (4k) blocks.
    The filesystem on /dev/mapper/vg_rxf-lv_root is now 6965248 blocks long.
    

    12:查看扩展空间后的结果:

    # df -h
    
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/mapper/vg_rxf-lv_root   27G   18G  8.9G  66% /
    tmpfs                       931M  4.0K  931M   1% /dev/shm
    /dev/sda1                   485M   35M  425M   8% /boot
    

    可以看见,大功告成。

    相关文章

      网友评论

          本文标题:VMware Linux(Centos)虚拟机扩容根目录磁盘空间

          本文链接:https://www.haomeiwen.com/subject/gkfumqtx.html