当前位置:   article > 正文

VMWare虚拟机扩展磁盘空间(扩充root根目录空间)

虚拟机扩展磁盘空间

1. 扩展虚拟机磁盘空间

Vm虚拟机下Linux扩展原有磁盘空间,10G

在这里插入图片描述

 

10G的基础上不能满足需求,只好进行磁盘扩展。

在这里插入图片描述

 

调整到合适的磁盘空间

在这里插入图片描述

在这里插入图片描述
需注意以下几点: linux只能扩展磁盘容量而不能减小, 所填写的容量为总容量,即包含已分区的磁盘。 

2.查看、创建系统分区

1.启动虚拟机,查看磁盘分区

[root@node1 ~]# fdisk -l

在这里插入图片描述

 总磁盘大小32.2GB,其中磁盘分了sda1,sda2两个分区。Linux LVM为虚拟机分区约有9GB磁盘空间。

2.创建新分区

  1. [root@node1 ~]# fdisk /dev/sda
  2. #输入m查看帮助文档
  3. Command (m for help): m
  4. Command action
  5.    a   toggle a bootable flag
  6.    b   edit bsd disklabel
  7.    c   toggle the dos compatibility flag
  8.    d   delete a partition
  9.    g   create a new empty GPT partition table
  10.    G   create an IRIX (SGI) partition table
  11.    l   list known partition types
  12.    m   print this menu
  13.    n   add a new partition #创建新分区
  14.    o   create a new empty DOS partition table
  15.    p   print the partition table
  16.    q   quit without saving changes
  17.    s   create a new empty Sun disklabel
  18.    t   change a partition's system id
  19.    u   change display/entry units
  20.    v   verify the partition table
  21.    w   write table to disk and exit
  22.    x   extra functionality (experts only)


3.执行分区创建

  1. Command (m for help): n
  2. Partition type:
  3.    p   primary (2 primary, 0 extended, 2 free) #创建主分区
  4.    e   extended #创建扩展分区
  5. Select (default p): p
  6. Partition number (3,4, default 3):  #由前面已有2个分区,所有从3开始
  7. First sector (20971520-62914559, default 20971520): #一路回车即可
  8. Using default value 20971520
  9. Last sector, +sectors or +size{K,M,G} (20971520-62914559, default 62914559): 
  10. Using default value 62914559
  11. Partition 3 of type Linux and of size 20 GiB is set
  12. Command (m for help): w #保存退出
  13. The partition table has been altered!


4.重新查看分区

我们的新建分区/dev/sda3

  1. [root@node1 ~]# fdisk -l
  2. Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
  3. Units = sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disk label type: dos
  7. Disk identifier: 0x00009cb6
  8.    Device Boot      Start         End      Blocks   Id  System
  9. /dev/sda1   *        2048     2099199     1048576   83  Linux
  10. /dev/sda2         2099200    20971519     9436160   8e  Linux LVM
  11. #sda3为新创建的分区
  12. /dev/sda3        20971520    62914559    20971520   83  Linux
  13. Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 sectors
  14. Units = sectors of 1 * 512 = 512 bytes
  15. Sector size (logical/physical): 512 bytes / 512 bytes
  16. I/O size (minimum/optimal): 512 bytes / 512 bytes
  17. Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
  18. Units = sectors of 1 * 512 = 512 bytes
  19. Sector size (logical/physical): 512 bytes / 512 bytes
  20. I/O size (minimum/optimal): 512 bytes / 512 bytes


5.查看文件系统格式、分区格式化

  1. #查看文件系统格式
  2.  df  -T -h
  3. #分区格式化
  4. mkfs.xfs /dev/sda3  #格式化为xfs格式
  1. #进入lvm管理
  2. lvm
  3. lvm> pvcreate /dev/sda3  #这是初始化刚才的分区3
  4. WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  5.   Wiping ext4 signature on /dev/sda3.
  6.   Physical volume "/dev/sda3" successfully created.
  7. lvm> vgdisplay -v #卷和卷组的命令可以通过 vgdisplay查看
  8.   --- Volume group ---
  9.   VG Name               centos
  10.   System ID             
  11.   Format                lvm2
  12.   Metadata Areas        1
  13.   Metadata Sequence No  3
  14.   VG Access             read/write
  15.   VG Status             resizable
  16.   MAX LV                0
  17.   Cur LV                2
  18.   Open LV               2
  19.   Max PV                0
  20.   Cur PV                1
  21.   Act PV                1
  22.   VG Size               <9.00 GiB
  23.   PE Size               4.00 MiB
  24.   Total PE              2303
  25.   Alloc PE / Size       2303 / <9.00 GiB
  26.   Free  PE / Size       0 / 0   
  27.   VG UUID               zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
  28.    
  29.   --- Logical volume ---
  30.   LV Path                /dev/centos/swap
  31.   LV Name                swap
  32.   VG Name                centos
  33.   LV UUID                ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
  34.   LV Write Access        read/write
  35.   LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  36.   LV Status              available
  37.   # open                 2
  38.   LV Size                1.00 GiB
  39.   Current LE             256
  40.   Segments               1
  41.   Allocation             inherit
  42.   Read ahead sectors     auto
  43.   - currently set to     8192
  44.   Block device           253:1
  45.    
  46.   --- Logical volume ---
  47.   LV Path                /dev/centos/root
  48.   LV Name                root
  49.   VG Name                centos
  50.   LV UUID                2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
  51.   LV Write Access        read/write
  52.   LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  53.   LV Status              available
  54.   # open                 1
  55.   LV Size                <8.00 GiB
  56.   Current LE             2047
  57.   Segments               1
  58.   Allocation             inherit
  59.   Read ahead sectors     auto
  60.   - currently set to     8192
  61.   Block device           253:0
  62.    
  63.   --- Physical volumes ---
  64.   PV Name               /dev/sda2     
  65.   PV UUID               kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  66.   PV Status             allocatable
  67.   Total PE / Free PE    2303 / 0
  68. lvm> vgextend centos /dev/sda3 #将初始化过的分区加入到虚拟卷组centos
  69.   Volume group "centos" successfully extended

可以查看到新加入的物理卷sda3

在这里插入图片描述

 通过vgdisplay再次查看,可以发现Volume group中多了Free PE / Size 5119 / <20.00 GiB一行记录

  1. lvm> vgdisplay -v
  2.   --- Volume group ---
  3.   VG Name               centos
  4.   System ID             
  5.   Format                lvm2
  6.   Metadata Areas        2
  7.   Metadata Sequence No  4
  8.   VG Access             read/write
  9.   VG Status             resizable
  10.   MAX LV                0
  11.   Cur LV                2
  12.   Open LV               2
  13.   Max PV                0
  14.   Cur PV                2
  15.   Act PV                2
  16.   VG Size               28.99 GiB
  17.   PE Size               4.00 MiB
  18.   Total PE              7422
  19.   Alloc PE / Size       2303 / <9.00 GiB
  20.   Free  PE / Size       5119 / <20.00 GiB
  21.   VG UUID               zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
  22.    
  23.   --- Logical volume ---
  24.   LV Path                /dev/centos/swap
  25.   LV Name                swap
  26.   VG Name                centos
  27.   LV UUID                ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
  28.   LV Write Access        read/write
  29.   LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  30.   LV Status              available
  31.   # open                 2
  32.   LV Size                1.00 GiB
  33.   Current LE             256
  34.   Segments               1
  35.   Allocation             inherit
  36.   Read ahead sectors     auto
  37.   - currently set to     8192
  38.   Block device           253:1
  39.    
  40.   --- Logical volume ---
  41.   LV Path                /dev/centos/root
  42.   LV Name                root
  43.   VG Name                centos
  44.   LV UUID                2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
  45.   LV Write Access        read/write
  46.   LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  47.   LV Status              available
  48.   # open                 1
  49.   LV Size                <8.00 GiB
  50.   Current LE             2047
  51.   Segments               1
  52.   Allocation             inherit
  53.   Read ahead sectors     auto
  54.   - currently set to     8192
  55.   Block device           253:0
  56.    
  57.   --- Physical volumes ---
  58.   PV Name               /dev/sda2     
  59.   PV UUID               kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  60.   PV Status             allocatable
  61.   Total PE / Free PE    2303 / 0
  62.    
  63.   PV Name               /dev/sda3     
  64.   PV UUID               V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
  65.   PV Status             allocatable
  66.   Total PE / Free PE    5119 / 5119
  67. #/dev/mapper/centos-root 为根路径挂载点
  68. lvm> lvextend -l+5119 /dev/mapper/centos-root ##扩展已有卷的容量(5119 是通过vgdisplay查看Free  PE / Size的大小)
  69.   Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 27.99 GiB (7166 extents).
  70.   Logical volume centos/root successfully resized.
  71. lvm> pvdisplay
  72.   --- Physical volume ---
  73.   PV Name               /dev/sda2
  74.   VG Name               centos
  75.   PV Size               <9.00 GiB / not usable 3.00 MiB
  76.   Allocatable           yes (but full)
  77.   PE Size               4.00 MiB
  78.   Total PE              2303
  79.   Free PE               0
  80.   Allocated PE          2303
  81.   PV UUID               kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  82.    
  83.   --- Physical volume ---
  84.   PV Name               /dev/sda3
  85.   VG Name               centos
  86.   PV Size               20.00 GiB / not usable 4.00 MiB
  87.   Allocatable           yes (but full)
  88.   PE Size               4.00 MiB
  89.   Total PE              5119
  90.   Free PE               0
  91.   Allocated PE          5119
  92.   PV UUID               V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
  93. lvm>quit  #退出


3.文件系统的扩容

以上只是做成了卷扩容,接下来做文件系统的真正扩容

  1. #执行df -h时根目录的挂载点
  2. df -h

在这里插入图片描述

centos7执行执行扩容

xfs_growfs /dev/mapper/centos-root

在这里插入图片描述

再次查看磁盘使用情况

df -h 

可以看见根目录下的磁盘空间已经扩展为28G了

在这里插入图片描述
 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/192100
推荐阅读
相关标签
  

闽ICP备14008679号