物理磁盘先扩容新增后可能需要重启才会看到。
扩容步骤
查看分区情况
[root@app1 ~]# fdisk -l
磁盘 /dev/sda:37.6 GB, 37580963840 字节,73400320 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009d704
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 62914559 10485760 83 Linux
磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
###分区操作
[root@app1 ~]#fdisk /dev/sda
磁盘 /dev/sda:37.6 GB, 37580963840 字节,73400320 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009d704
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 62914559 10485760 83 Linux
磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
分区逻辑卷LVM类型
[root@app1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 35G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 19G 0 part
│ ├─centos-root 253:0 0 17G 0 lvm /
│ └─centos-swap 253:1 0 2G 0 lvm [SWAP]
└─sda3 8:3 0 10G 0 part
sr0 11:0 1 4.2G 0 rom
####创建分区
[root@app1 ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
已选择分区 4
起始 扇区 (62914560-73400319,默认为 62914560):
将使用默认值 62914560
Last 扇区, +扇区 or +size{K,M,G} (62914560-73400319,默认为 73400319):
将使用默认值 73400319
分区 4 已设置为 Linux 类型,大小设为 5 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sda:37.6 GB, 37580963840 字节,73400320 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009d704
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 62914559 10485760 83 Linux
/dev/sda4 62914560 73400319 5242880 83 Linux
命令(输入 m 获取帮助):t
分区号 (1-4,默认 4):
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”
命令(输入 m 获取帮助):p
磁盘 /dev/sda:37.6 GB, 37580963840 字节,73400320 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009d704
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 62914559 10485760 83 Linux
/dev/sda4 62914560 73400319 5242880 8e Linux LVM
命令(输入 m 获取帮助):w
The partition table has been altered!
alling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。
###需要重启,才会看到生效
[root@app1 ~]# lvm
lvm> pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
lvm> exit
Exiting.
[root@app1 ~]#
[root@app1 ~]#
[root@app1 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <19.00 GiB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0
VG UUID HuLuUk-iA1U-TmWL-QS8h-DEfd-vhYn-9fEewc
[root@app1 ~]# lvm
lvm> vgextend centos /dev/sda4
Volume group "centos" successfully extended
lvm> lvextend -L +5G /dev/mapper/centos-root
Insufficient free space: 1280 extents needed, but only 1279 available
lvm> lvextend -L +4.8G /dev/mapper/centos-root
Rounding size to boundary between physical extents: 4.80 GiB.
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <21.80 GiB (5580 extents).
Logical volume centos/root successfully resized.
lvm> exit
Exiting.
[root@app1 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 5713920