一,Centos为硬盘新增容量分区并挂载到根目录

1.查看硬盘的情况。
image.png
可以看到硬盘新增了大小,但是没有被用起来。
下面我要做的其实就是lvm扩展

  1. [root@Slave2 ~]# fdisk /dev/sda
  2. Welcome to fdisk (util-linux 2.23.2).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Command (m for help): p
  6. Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectors
  7. Units = sectors of 1 * 512 = 512 bytes
  8. Sector size (logical/physical): 512 bytes / 512 bytes
  9. I/O size (minimum/optimal): 512 bytes / 512 bytes
  10. Disk label type: dos
  11. Disk identifier: 0x0001784c
  12. Device Boot Start End Blocks Id System
  13. /dev/sda1 * 2048 2099199 1048576 83 Linux
  14. /dev/sda2 2099200 33554431 15727616 8e Linux LVM
  15. Command (m for help): n
  16. Partition type:
  17. p primary (2 primary, 0 extended, 2 free)
  18. e extended
  19. Select (default p): p
  20. Partition number (3,4, default 3): 3
  21. First sector (33554432-838860799, default 33554432): 33554432
  22. Last sector, +sectors or +size{K,M,G} (33554432-838860799, default 838860799): 838860799
  23. Partition 3 of type Linux and of size 384 GiB is set
  24. Command (m for help): p
  25. Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectors
  26. Units = sectors of 1 * 512 = 512 bytes
  27. Sector size (logical/physical): 512 bytes / 512 bytes
  28. I/O size (minimum/optimal): 512 bytes / 512 bytes
  29. Disk label type: dos
  30. Disk identifier: 0x0001784c
  31. Device Boot Start End Blocks Id System
  32. /dev/sda1 * 2048 2099199 1048576 83 Linux
  33. /dev/sda2 2099200 33554431 15727616 8e Linux LVM
  34. /dev/sda3 33554432 838860799 402653184 83 Linux
  35. Command (m for help): w
  36. The partition table has been altered!
  37. Calling ioctl() to re-read partition table.
  38. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
  39. The kernel still uses the old table. The new table will be used at
  40. the next reboot or after you run partprobe(8) or kpartx(8)
  41. Syncing disks.
  42. [root@Slave2 ~]#

用 partprobe /dev/sda3 没有启作用,重启后生效
image.png
image.png
可以看到sda3为刚刚新增的分区。
开始扩容:
创建物理卷:

  1. [root@Slave2 ~]# lvm
  2. lvm> pvcreate /dev/sda3
  3. Physical volume "/dev/sda3" successfully created.
  4. lvm>

查看物理卷和卷组:

  1. lvm> pvdisplay
  2. --- Physical volume ---
  3. PV Name /dev/sda2
  4. VG Name centos
  5. PV Size <15.00 GiB / not usable 3.00 MiB
  6. Allocatable yes (but full)
  7. PE Size 4.00 MiB
  8. Total PE 3839
  9. Free PE 0
  10. Allocated PE 3839
  11. PV UUID VZ9vj7-442j-SGbv-3ZRj-gdDs-kQuK-YIPcEj
  12. "/dev/sda3" is a new physical volume of "384.00 GiB"
  13. --- NEW Physical volume ---
  14. PV Name /dev/sda3
  15. VG Name
  16. PV Size 384.00 GiB
  17. Allocatable NO
  18. PE Size 0
  19. Total PE 0
  20. Free PE 0
  21. Allocated PE 0
  22. PV UUID TRQMxO-ouRd-E4GM-mL60-R4Ub-3FsX-BjiXZF
  23. lvm>

将物理卷加入到卷组:

  1. lvm> vgextend centos /dev/sda3
  2. Volume group "centos" successfully extended
  3. lvm> vgdisplay
  4. --- Volume group ---
  5. VG Name centos
  6. System ID
  7. Format lvm2
  8. Metadata Areas 2
  9. Metadata Sequence No 4
  10. VG Access read/write
  11. VG Status resizable
  12. MAX LV 0
  13. Cur LV 2
  14. Open LV 2
  15. Max PV 0
  16. Cur PV 2
  17. Act PV 2
  18. VG Size 398.99 GiB
  19. PE Size 4.00 MiB
  20. Total PE 102142
  21. Alloc PE / Size 3839 / <15.00 GiB
  22. Free PE / Size 98303 / <384.00 GiB
  23. VG UUID e6v5QC-dUMm-yUWn-KSy7-5eOx-ttq6-5eyDID
  24. lvm>

将卷组剩余空间添加到逻辑卷组/dev/centos/root

  1. lvm> lvextend -l +100%FREE /dev/centos/root
  2. Size of logical volume centos/root changed from 13.39 GiB (3429 extents) to 397.39 GiB (101732 extents).
  3. Logical volume centos/root successfully resized.
  4. lvm>

同步到文件系统

  1. lvm> exit
  2. Exiting.
  3. [root@Slave2 ~]# xfs_growfs /dev/centos/root
  4. meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=877824 blks
  5. = sectsz=512 attr=2, projid32bit=1
  6. = crc=1 finobt=0 spinodes=0
  7. data = bsize=4096 blocks=3511296, imaxpct=25
  8. = sunit=0 swidth=0 blks
  9. naming =version 2 bsize=4096 ascii-ci=0 ftype=1
  10. log =internal bsize=4096 blocks=2560, version=2
  11. = sectsz=512 sunit=0 blks, lazy-count=1
  12. realtime =none extsz=4096 blocks=0, rtextents=0
  13. data blocks changed from 3511296 to 104173568
  14. [root@Slave2 ~]# df -h
  15. Filesystem Size Used Avail Use% Mounted on
  16. devtmpfs 7.8G 0 7.8G 0% /dev
  17. tmpfs 7.8G 0 7.8G 0% /dev/shm
  18. tmpfs 7.8G 8.8M 7.8G 1% /run
  19. tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
  20. /dev/mapper/centos-root 398G 9.9G 388G 3% /
  21. /dev/sda1 1014M 150M 865M 15% /boot
  22. tmpfs 1.6G 0 1.6G 0% /run/user/0
  23. [root@Slave2 ~]#