对新增加的硬盘进行分区

  1. [root@vnode1 ~]# fdisk /dev/sda
  2. 欢迎使用 fdisk (util-linux 2.23.2)。
  3. 更改将停留在内存中,直到您决定将更改写入磁盘。
  4. 使用写入命令前请三思。
  5. 命令(输入 m 获取帮助):p
  6. ....
  7. 设备 Boot Start End Blocks Id System
  8. /dev/sda1 * 2048 1026047 512000 83 Linux
  9. /dev/sda2 1026048 83886079 41430016 8e Linux LVM
  10. 命令(输入 m 获取帮助):n
  11. Partition type:
  12. p primary (2 primary, 0 extended, 2 free)
  13. e extended
  14. Select (default p): p
  15. 分区号 (3,4,默认 3):3
  16. 起始 扇区 (83886080-167772159,默认为 83886080):
  17. 将使用默认值 83886080
  18. Last 扇区, +扇区 or +size{K,M,G} (83886080-167772159,默认为 167772159):
  19. 将使用默认值 167772159
  20. 分区 3 已设置为 Linux 类型,大小设为 40 GiB
  21. 命令(输入 m 获取帮助):t
  22. 分区号 (1-3,默认 3):3
  23. Hex 代码(输入 L 列出所有代码):8e
  24. 已将分区“Linux”的类型更改为“Linux LVM
  25. 命令(输入 m 获取帮助):w
  26. The partition table has been altered!
  27. Calling ioctl() to re-read partition table.
  28. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
  29. The kernel still uses the old table. The new table will be used at
  30. the next reboot or after you run partprobe(8) or kpartx(8)
  31. 正在同步磁盘

重启机器

对新增加的硬盘格式化

  1. [root@vnode1 ~]# mkfs.ext3 /dev/sda3
  2. mke2fs 1.42.9 (28-Dec-2013)
  3. 文件系统标签=
  4. OS type: Linux
  5. 块大小=4096 (log=2)
  6. 分块大小=4096 (log=2)
  7. Stride=0 blocks, Stripe width=0 blocks
  8. 2621440 inodes, 10485760 blocks
  9. 524288 blocks (5.00%) reserved for the super user
  10. 第一个数据块=0
  11. Maximum filesystem blocks=4294967296
  12. 320 block groups
  13. 32768 blocks per group, 32768 fragments per group
  14. 8192 inodes per group
  15. Superblock backups stored on blocks:
  16. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  17. 4096000, 7962624
  18. Allocating group tables: 完成
  19. 正在写入inode表: 完成
  20. Creating journal (32768 blocks): 完成
  21. Writing superblocks and filesystem accounting information: 完成

添加新LVM到已有的LVM组,实现扩容

  1. [root@vnode1 ~]# lvm
  2. lvm> pvcreate /dev/sda3
  3. WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  4. Wiping ext3 signature on /dev/sda3.
  5. Physical volume "/dev/sda3" successfully created
  6. lvm> vgextend centos /dev/sda3
  7. Volume group "centos" successfully extended
  8. lvm> lvextend -L +39.9G /dev/mapper/centos-root
  9. Rounding size to boundary between physical extents: 39.90 GiB
  10. Size of logical volume centos/root changed from 35.47 GiB (9080 extents) to 75.37 GiB (19295 extents).
  11. Logical volume root successfully resized.
  12. lvm> pvdisplay
  13. --- Physical volume ---
  14. PV Name /dev/sda2
  15. VG Name centos
  16. PV Size 39.51 GiB / not usable 3.00 MiB
  17. Allocatable yes (but full)
  18. PE Size 4.00 MiB
  19. Total PE 10114
  20. Free PE 0
  21. Allocated PE 10114
  22. PV UUID vtNvX3-b1yw-ePoh-YGHQ-tDhL-x0ru-mfts3k
  23. --- Physical volume ---
  24. PV Name /dev/sda3
  25. VG Name centos
  26. PV Size 40.00 GiB / not usable 4.00 MiB
  27. Allocatable yes
  28. PE Size 4.00 MiB
  29. Total PE 10239
  30. Free PE 34
  31. Allocated PE 10205
  32. PV UUID jWqvcF-R53u-ZeAy-zO2L-PbtI-51VP-yHNZ1g
  33. lvm> quit
  34. Exiting.
  35. [root@vnode1 ~]#

因为我的centos7的某些分区用的是xfs的文件系统

  1. [root@vnode1 ~]# df -T
  2. 文件系统 类型 1K-块 已用 可用 已用% 挂载点
  3. /dev/mapper/centos-root xfs 37173520 5574340 31599180 15% /
  4. devtmpfs devtmpfs 3987400 0 3987400 0% /dev
  5. tmpfs tmpfs 3997856 0 3997856 0% /dev/shm
  6. tmpfs tmpfs 3997856 8628 3989228 1% /run
  7. tmpfs tmpfs 3997856 0 3997856 0% /sys/fs/cgroup
  8. /dev/sda1 xfs 508588 127152 381436 26% /boot
  9. tmpfs tmpfs 799572 0 799572 0% /run/user/0
  10. [root@vnode1 ~]#

xfs_growfs

  1. [root@vnode1 ~]# xfs_growfs /dev/mapper/centos-root
  2. meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=2324480 blks
  3. = sectsz=512 attr=2, projid32bit=1
  4. = crc=0 finobt=0
  5. data = bsize=4096 blocks=9297920, imaxpct=25
  6. = sunit=0 swidth=0 blks
  7. naming =version 2 bsize=4096 ascii-ci=0 ftype=0
  8. log =internal bsize=4096 blocks=4540, version=2
  9. = sectsz=512 sunit=0 blks, lazy-count=1
  10. realtime =none extsz=4096 blocks=0, rtextents=0
  11. data blocks changed from 9297920 to 19758080

看到扩容后的磁盘空间

  1. [root@vnode1 ~]# df -h
  2. 文件系统 容量 已用 可用 已用% 挂载点
  3. /dev/mapper/centos-root 76G 5.4G 71G 8% /
  4. devtmpfs 3.9G 0 3.9G 0% /dev
  5. tmpfs 3.9G 0 3.9G 0% /dev/shm
  6. tmpfs 3.9G 8.5M 3.9G 1% /run
  7. tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
  8. /dev/sda1 497M 125M 373M 26% /boot
  9. tmpfs 781M 0 781M 0% /run/user/0