添加新硬盘,扩展Centos7根分区

时间:2021-10-16 08:16:55

##背景介绍,系统安装时,分配的硬盘容量太小,根分区空间不够用,现添加一个新硬盘,通过以下步骤来扩展centos7根分区

 [root@t201 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs .9G .9G % /dev
tmpfs .9G .9G % /dev/shm
tmpfs .9G 8.6M .9G % /run
tmpfs .9G .9G % /sys/fs/cgroup
/dev/mapper/centos-root 14G .2G 12G % /
/dev/sda1 1014M 134M 881M % /boot
tmpfs 797M 797M % /run/user/
[root@t201 ~]# fdisk -l 磁盘 /dev/sda:17.2 GB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节
磁盘标签类型:dos
磁盘标识符:0x000db98a 设备 Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 8e Linux LVM 磁盘 /dev/sdb:21.5 GB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节 磁盘 /dev/mapper/centos-root:14.4 GB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节 磁盘 /dev/mapper/centos-swap: MB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节 [root@t201 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.)。 更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。 Device does not contain a recognized partition table
使用磁盘标识符 0xb1065d94 创建新的 DOS 磁盘标签。 命令(输入 m 获取帮助):m
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
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
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only) 命令(输入 m 获取帮助):n
Partition type:
p primary ( primary, extended, free)
e extended
Select (default p): p
分区号 (-,默认 ):
起始 扇区 (-,默认为 ):
将使用默认值
Last 扇区, +扇区 or +size{K,M,G} (-,默认为 ):
将使用默认值
分区 已设置为 Linux 类型,大小设为 GiB 命令(输入 m 获取帮助):w
The partition table has been altered! Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@t201 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs .9G .9G % /dev
tmpfs .9G .9G % /dev/shm
tmpfs .9G 8.6M .9G % /run
tmpfs .9G .9G % /sys/fs/cgroup
/dev/mapper/centos-root 14G .2G 12G % /
/dev/sda1 1014M 134M 881M % /boot
tmpfs 797M 797M % /run/user/
[root@t201 ~]# fdisk -l 磁盘 /dev/sda:17.2 GB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节
磁盘标签类型:dos
磁盘标识符:0x000db98a 设备 Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 8e Linux LVM 磁盘 /dev/sdb:21.5 GB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节
磁盘标签类型:dos
磁盘标识符:0xb1065d94 设备 Boot Start End Blocks Id System
/dev/sdb1 Linux 磁盘 /dev/mapper/centos-root:14.4 GB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节 磁盘 /dev/mapper/centos-swap: MB, 字节, 个扇区
Units = 扇区 of * = bytes
扇区大小(逻辑/物理): 字节 / 字节
I/O 大小(最小/最佳): 字节 / 字节 [root@t201 ~]# vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size <15.00 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / <15.00 GiB
Free PE / Size /
VG UUID Fj5EY6-duHB-Vtmx-RaKo-JpuY-UwCy-f3xemr --- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID YKyysg-qNJY-x3sa-HjHm-5JHX-mBRf-mTpVXl
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 1.60 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID dLgGwO-UXqd-41WI-C97j-suC8-siWt-3QWQQv
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 13.39 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Physical volumes ---
PV Name /dev/sda2
PV UUID dzMQgG-eMzE-6Vi4-WHOt-BdDH-KuTt-Ofk0gH
PV Status allocatable
Total PE / Free PE / [root@t201 ~]# pvcreate /dev/sdb
sdb sdb1
[root@t201 ~]# pvcreate /dev/sdb
sdb sdb1
[root@t201 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@t201 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <15.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE
Free PE
Allocated PE
PV UUID dzMQgG-eMzE-6Vi4-WHOt-BdDH-KuTt-Ofk0gH "/dev/sdb1" is a new physical volume of "<20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <20.00 GiB
Allocatable NO
PE Size
Total PE
Free PE
Allocated PE
PV UUID G9jtn0-Gg0H-U55j-Hwzs-pafT-Mhtx-doyA9f [root@t201 ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
[root@t201 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID YKyysg-qNJY-x3sa-HjHm-5JHX-mBRf-mTpVXl
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 1.60 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID dLgGwO-UXqd-41WI-C97j-suC8-siWt-3QWQQv
LV Write Access read/write
LV Creation host, time localhost, -- :: +
LV Status available
# open
LV Size 13.39 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : [root@t201 ~]# lvextend -l +%Free /dev/centos/root
Size of logical volume centos/root changed from 13.39 GiB ( extents) to 33.39 GiB ( extents).
Logical volume centos/root successfully resized.
[root@t201 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize= agcount=, agsize= blks
= sectsz= attr=, projid32bit=
= crc= finobt= spinodes=
data = bsize= blocks=, imaxpct=
= sunit= swidth= blks
naming =version bsize= ascii-ci= ftype=
log =internal bsize= blocks=, version=
= sectsz= sunit= blks, lazy-count=
realtime =none extsz= blocks=, rtextents=
data blocks changed from to
[root@t201 ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs .9G .9G % /dev
tmpfs tmpfs .9G .9G % /dev/shm
tmpfs tmpfs .9G 8.6M .9G % /run
tmpfs tmpfs .9G .9G % /sys/fs/cgroup
/dev/mapper/centos-root xfs 34G .2G 32G % /
/dev/sda1 xfs 1014M 134M 881M % /boot
tmpfs tmpfs 797M 797M % /run/user/
[root@t201 ~]#