【学习】Centos7物理机扩容
(默认已经插好新硬盘)
查看磁盘名称
[root@localhost dev]# fdisk -l
磁盘 /dev/sda:512.1 GB, 512110190592 字节,1000215216 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:dos
磁盘标识符:0x000b5573
磁盘 /dev/sdb:4000.8 GB, 4000787030016 字节,7814037168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:gpt
Disk identifier: 6BC7198F-A315-40CD-BC52-09D5EC750B00
这里4T的硬盘就是新加硬盘,名称为 /dev/sdb
使用fdisk分区
fdisk /dev/sdb
[root@localhost packages]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):m
命令操作
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
首先输入n,添加新分区
命令(输入 m 获取帮助):n
分区号 (2-3,默认 2):2
第一个扇区 (a-b,默认 a):a
Last sector, +sectors or +size{K,M,G,T,P} (b-c,默认 c):c
之后输入t,修改分区类型,找到“Linux LVM ”
命令(输入 m 获取帮助):t
分区号 (1,2,默认 2):2
分区类型(输入 L 列出所有类型):L
31 Linux LVM E6D6D379-F507-44C2-A23C-238F2A3DF928
分区类型(输入 L 列出所有类型):31
之后输入p,查看分区
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:4000.8 GB, 4000787030016 字节,7814037168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:gpt
Disk identifier: 6BC7198F-A315-40CD-BC52-09D5EC750B00
# Start End Size Type Name
1 2048 7814035455 3.7T Linux LVM Basic data partition
2 34 2047 1007K Linux LVM
Partition 2 does not start on physical sector boundary.
最后输入w,将分区表写入硬盘
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
完成分区操作后,创建物理卷
pvcreate /dev/sdb1
查看物理卷,证明成功
[root@localhost packages]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 476.45 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 121971
Free PE 0
Allocated PE 121971
PV UUID qdGFx5-GE4o-EWRt-UfXw-uoeO-qdzA-oK1dcE
"/dev/sdb1" is a new physical volume of "<3.64 TiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <3.64 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID mpyHlw-7KIS-xTPz-4z9Y-gVhY-b6Bp-xP93hi
显示卷组详情,记下根目录分区名字“centos”
[root@localhost packages]# 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 <476.45 GiB
PE Size 4.00 MiB
Total PE 121971
Alloc PE / Size 121971 / <476.45 GiB
Free PE / Size 0 / 0
VG UUID ql9uiS-7yCg-wM8O-slSR-1bWA-tg4F-viyW3q
将新做好的分区"/dev/sdb1"加入到根目录分区“centos”中,之后重新查看卷组详情
[root@localhost packages]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
[root@localhost packages]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 4.10 TiB
PE Size 4.00 MiB
Total PE 1075832
Alloc PE / Size 121971 / <476.45 GiB
Free PE / Size 953861 / <3.64 TiB
VG UUID ql9uiS-7yCg-wM8O-slSR-1bWA-tg4F-viyW3q
卷扩容并调整分区大小,依照自己的路径写
[root@localhost packages]# lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from <456.45 GiB (116851 extents) to 4.08 TiB (1070712 extents).
Logical volume centos/root successfully resized.
[root@localhost packages]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=29913856 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=119655424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=58425, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 119655424 to 1096409088
[root@localhost packages]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 4.1G 59G 7% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 4.1T 457G 3.7T 11% /
/dev/sda1 494M 180M 315M 37% /boot
tmpfs 13G 40K 13G 1% /run/user/0
查看扩容是否成功
[root@localhost packages]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 4.1G 59G 7% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 4.1T 457G 3.7T 11% /
/dev/sda1 494M 180M 315M 37% /boot
tmpfs 13G 40K 13G 1% /run/user/0
~