给虚拟机添加硬盘(或扩容)

  1. 停止虚拟机
  2. 在管理页面给虚拟机新增一块硬盘
  3. 重新启动虚拟机

登入虚拟机,对新增硬盘进行分区

下方所示为硬盘扩容非新增,但操作方式都一致

  1. root@zentao:/home/ubuntu# fdisk /dev/sda
  2. Welcome to fdisk (util-linux 2.27.1).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. The size of this disk is 4 TiB (4398046511104 bytes). DOS partition table format can not be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
  6. Command (m for help): p ###查看已有分区
  7. Disk /dev/sda: 4 TiB, 4398046511104 bytes, 8589934592 sectors
  8. Units: sectors of 1 * 512 = 512 bytes
  9. Sector size (logical/physical): 512 bytes / 512 bytes
  10. I/O size (minimum/optimal): 512 bytes / 512 bytes
  11. Disklabel type: dos
  12. Disk identifier: 0x039343bf
  13. Device Boot Start End Sectors Size Id Type
  14. /dev/sda1 * 2048 1499135 1497088 731M 83 Linux
  15. /dev/sda2 1501182 419428351 417927170 199.3G 5 Extended
  16. /dev/sda5 1501184 419428351 417927168 199.3G 8e Linux LVM
  17. Command (m for help): F ###查看可分配空间
  18. Unpartitioned space /dev/sda: 3.8 TiB, 4183299194880 bytes, 8170506240 sectors
  19. Units: sectors of 1 * 512 = 512 bytes
  20. Sector size (logical/physical): 512 bytes / 512 bytes
  21. Start End Sectors Size
  22. 419428352 8589934591 8170506240 3.8T
  23. Command (m for help): n ###创建分区
  24. Partition type
  25. p primary (1 primary, 1 extended, 2 free)
  26. l logical (numbered from 5)
  27. Select (default p): p
  28. Partition number (3,4, default 3):
  29. First sector (1499136-4294967295, default 1499136): 419428352
  30. Last sector, +sectors or +size{K,M,G,T,P} (419428352-4294967294, default 4294967294):
  31. Created a new partition 3 of type 'Linux' and of size 1.8 TiB.
  32. Command (m for help): p
  33. Disk /dev/sda: 4 TiB, 4398046511104 bytes, 8589934592 sectors
  34. Units: sectors of 1 * 512 = 512 bytes
  35. Sector size (logical/physical): 512 bytes / 512 bytes
  36. I/O size (minimum/optimal): 512 bytes / 512 bytes
  37. Disklabel type: dos
  38. Disk identifier: 0x039343bf
  39. Device Boot Start End Sectors Size Id Type
  40. /dev/sda1 * 2048 1499135 1497088 731M 83 Linux
  41. /dev/sda2 1501182 419428351 417927170 199.3G 5 Extended
  42. /dev/sda3 419428352 4294967294 3875538943 1.8T 83 Linux
  43. /dev/sda5 1501184 419428351 417927168 199.3G 8e Linux LVM
  44. Partition table entries are not in disk order.
  45. Command (m for help): t ###修改分区type
  46. Partition number (1-3,5, default 5): 3 ###指定要修改的分区
  47. Partition type (type L to list all types): 8e ###8e对应的type为Linux LVM
  48. Changed type of partition 'Linux' to 'Linux LVM'.
  49. Command (m for help): w ###写入分区表
  50. The partition table has been altered

扩容根目录

  1. 查看VG Name
  1. root@zentao:/home/ubuntu# vgdisplay
  2. --- Volume group ---
  3. VG Name zentao-vg
  4. System ID
  5. Format lvm2
  6. Metadata Areas 3
  7. Metadata Sequence No 7
  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 3
  15. Act PV 3
  16. VG Size 4.00 TiB
  17. PE Size 4.00 MiB
  18. Total PE 1048390
  19. Alloc PE / Size 1048390 / 4.00 TiB
  20. Free PE / Size 0 / 0
  21. VG UUID 8l2jBN-VnmO-TphJ-RqBA-rnda-ROoW-QE4pQ5
  1. 查看目录挂载信息
  1. root@zentao:/home/ubuntu# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. udev 3.9G 0 3.9G 0% /dev
  4. tmpfs 799M 9.1M 790M 2% /run
  5. /dev/mapper/zentao--vg-root 2.2T 26G 2.1T 2% /
  6. tmpfs 3.9G 0 3.9G 0% /dev/shm
  7. tmpfs 5.0M 0 5.0M 0% /run/lock
  8. tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
  9. /dev/sda1 720M 58M 625M 9% /boot
  10. overlay 2.2T 26G 2.1T 2% /var/lib/docker/overlay2/6bc943202e08c87727eda74a4f454f62a10103e59f53be5e049ce1ee0d1298ce/merged
  11. overlay 2.2T 26G 2.1T 2% /var/lib/docker/overlay2/ed8c8d79e65da008e4fad92b40e9eba5632216832f941df1d1a933ca9753e36f/merged
  12. overlay 2.2T 26G 2.1T 2% /var/lib/docker/overlay2/5a36352524032e25eca0a973fbab10ca20b333f06ee871a34648fca264b97ea9/merged
  13. tmpfs 799M 0 799M 0% /run/user/1000
  1. 分别执行以下命令对根目录进行扩容
  1. mkfs.ext4 /dev/sda3
  2. pvcreate /dev/sda3
  3. vgextend zentao-bg /dev/sda3
  4. ###直接将所有空余空间扩容,或者也可以指定扩容大小
  5. lvextend -l +100%FREE /dev/mapper/zentao--vg-root
  6. resize2fs /dev/mapper/zentao--vg-root
  1. 查看扩容后的根目录大小
  1. root@zentao:/home/ubuntu# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. udev 3.9G 0 3.9G 0% /dev
  4. tmpfs 799M 9.1M 790M 2% /run
  5. /dev/mapper/zentao--vg-root 4.0T 26G 3.8T 1% /
  6. tmpfs 3.9G 0 3.9G 0% /dev/shm
  7. tmpfs 5.0M 0 5.0M 0% /run/lock
  8. tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
  9. /dev/sda1 720M 58M 625M 9% /boot
  10. overlay 4.0T 26G 3.8T 1% /var/lib/docker/overlay2/ed8c8d79e65da008e4fad92b40e9eba5632216832f941df1d1a933ca9753e36f/merged
  11. overlay 4.0T 26G 3.8T 1% /var/lib/docker/overlay2/6bc943202e08c87727eda74a4f454f62a10103e59f53be5e049ce1ee0d1298ce/merged
  12. overlay 4.0T 26G 3.8T 1% /var/lib/docker/overlay2/5a36352524032e25eca0a973fbab10ca20b333f06ee871a34648fca264b97ea9/merged
  13. tmpfs 799M 0 799M 0% /run/user/1000
  14. root@zentao:/home/ubuntu#
  15. root@zentao:/home/ubuntu# lsblk
  16. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  17. sda 8:0 0 4T 0 disk
  18. ├─sda1 8:1 0 731M 0 part /boot
  19. ├─sda3 8:3 0 1.8T 0 part
  20. └─zentao--vg-root 252:0 0 4T 0 lvm /
  21. └─sda5 8:5 0 199.3G 0 part
  22. ├─zentao--vg-root 252:0 0 4T 0 lvm /
  23. └─zentao--vg-swap_1 252:1 0 980M 0 lvm [SWAP]
  24. sdb 8:16 0 2T 0 disk
  25. └─sdb1 8:17 0 2T 0 part
  26. └─zentao--vg-root 252:0 0 4T 0 lvm /
  27. sr0 11:0 1 873M 0 rom