当前位置:   article > 正文

虚拟机Linux磁盘扩容(原始磁盘分配容量小,扩展后不能直接加入到根目录分区中)_虚拟机扩展磁盘空间后怎么分配

虚拟机扩展磁盘空间后怎么分配

目录

一、扩展磁盘大小

1.点击硬盘

2.点击扩展(注意:扩展硬盘前一定要先关闭虚拟机)

3. 指定合适的硬盘大小,点击“扩展”

​编辑4.打开虚拟机

二、查看并创建系统分区

1.在应用程序中的工具中点击磁盘

2.创建新的分区

3.创建新分区

4.执行分区的创建

5.查看分区(新分区为、dev/sda3)

6.查看文件格式、分区格式化

7.进入lvm管理

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

三、文件系统的扩容

对centos7执行执行扩容

再次查看磁盘使用情况

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

一、扩展磁盘大小

 1.点击硬盘

 2.点击扩展(注意:扩展硬盘前一定要先关闭虚拟机

3. 指定合适的硬盘大小,点击“扩展”
4.打开虚拟机

二、查看并创建系统分区

 1.在应用程序中的工具中点击磁盘

[root@node1 ~]# fdisk -l

 

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. [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)
4.执行分区的创建
  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!
5.查看分区(新分区为、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
6.查看文件格式、分区格式化
  1. #查看文件系统格式
  2. df -T -h
  3. #分区格式化
  4. mkfs.xfs /dev/sda3 #格式化为xfs格式

注意:这一步可能会出现文件或目录不存在,可能是没有刷新造成的,会出现格式化xfs格式失败,这个时候要重启虚拟机再执行下面的命令!!!

7.进入lvm管理
  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. --- Logical volume ---
  29. LV Path /dev/centos/swap
  30. LV Name swap
  31. VG Name centos
  32. LV UUID ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
  33. LV Write Access read/write
  34. LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  35. LV Status available
  36. # open 2
  37. LV Size 1.00 GiB
  38. Current LE 256
  39. Segments 1
  40. Allocation inherit
  41. Read ahead sectors auto
  42. - currently set to 8192
  43. Block device 253:1
  44. --- Logical volume ---
  45. LV Path /dev/centos/root
  46. LV Name root
  47. VG Name centos
  48. LV UUID 2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
  49. LV Write Access read/write
  50. LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  51. LV Status available
  52. # open 1
  53. LV Size <8.00 GiB
  54. Current LE 2047
  55. Segments 1
  56. Allocation inherit
  57. Read ahead sectors auto
  58. - currently set to 8192
  59. Block device 253:0
  60. --- Physical volumes ---
  61. PV Name /dev/sda2
  62. PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  63. PV Status allocatable
  64. Total PE / Free PE 2303 / 0
  65. lvm> vgextend centos /dev/sda3 #将初始化过的分区加入到虚拟卷组centos
  66. Volume group "centos" successfully extended
8.可以查看到新加入的物理卷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. --- Logical volume ---
  23. LV Path /dev/centos/swap
  24. LV Name swap
  25. VG Name centos
  26. LV UUID ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
  27. LV Write Access read/write
  28. LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  29. LV Status available
  30. # open 2
  31. LV Size 1.00 GiB
  32. Current LE 256
  33. Segments 1
  34. Allocation inherit
  35. Read ahead sectors auto
  36. - currently set to 8192
  37. Block device 253:1
  38. --- Logical volume ---
  39. LV Path /dev/centos/root
  40. LV Name root
  41. VG Name centos
  42. LV UUID 2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
  43. LV Write Access read/write
  44. LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  45. LV Status available
  46. # open 1
  47. LV Size <8.00 GiB
  48. Current LE 2047
  49. Segments 1
  50. Allocation inherit
  51. Read ahead sectors auto
  52. - currently set to 8192
  53. Block device 253:0
  54. --- Physical volumes ---
  55. PV Name /dev/sda2
  56. PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  57. PV Status allocatable
  58. Total PE / Free PE 2303 / 0
  59. PV Name /dev/sda3
  60. PV UUID V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
  61. PV Status allocatable
  62. Total PE / Free PE 5119 / 5119
  63. #/dev/mapper/centos-root 为根路径挂载点
  64. lvm> lvextend -l+5119 /dev/mapper/centos-root ##扩展已有卷的容量(5119 是通过vgdisplay查看Free PE / Size的大小)
  65. Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 27.99 GiB (7166 extents).
  66. Logical volume centos/root successfully resized.
  67. lvm> pvdisplay
  68. --- Physical volume ---
  69. PV Name /dev/sda2
  70. VG Name centos
  71. PV Size <9.00 GiB / not usable 3.00 MiB
  72. Allocatable yes (but full)
  73. PE Size 4.00 MiB
  74. Total PE 2303
  75. Free PE 0
  76. Allocated PE 2303
  77. PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  78. --- Physical volume ---
  79. PV Name /dev/sda3
  80. VG Name centos
  81. PV Size 20.00 GiB / not usable 4.00 MiB
  82. Allocatable yes (but full)
  83. PE Size 4.00 MiB
  84. Total PE 5119
  85. Free PE 0
  86. Allocated PE 5119
  87. PV UUID V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
  88. lvm>quit  #退出

三、文件系统的扩容

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

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

对centos7执行执行扩容
xfs_growfs /dev/mapper/centos-root

再次查看磁盘使用情况
df -h 

 

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

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

闽ICP备14008679号