Linux调整根目录分区大小(CentOS7)

Linux调整root根目录磁盘大小

[root@zabbix ~]# df -h                                         ------------查看磁盘                                         
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 26M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 36G 4.9G 31G 14% /          -----------当前36G
/dev/sdb1 591G 4.8G 556G 1% /data
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 1.6G 12K 1.6G 1% /run/user/42
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# fdisk -l                             -----查看磁盘大小

磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0000eb92

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM

磁盘 /dev/sdb:644.2 GB, 644245094400 字节,1258291200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xa583bdd7

设备 Boot Start End Blocks Id System
/dev/sdb1 2048 1258291199 629144576 83 Linux

磁盘 /dev/mapper/centos-root:37.7 GB, 37706792960 字节,73646080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@zabbix ~]# fdisk /dev/sda                                                 ---对磁盘进行分区
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 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                       ---------输入 n 新增分区
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p                         -------------------输入p 选择新增主分区并选择分区号、第一个扇区、最后一个扇区号(在此均用默认值):
分区号 (3,4,默认 3):
起始 扇区 (83886080-209715199,默认为 83886080):
将使用默认值 83886080
Last 扇区, +扇区 or +size{K,M,G} (83886080-209715199,默认为 209715199):
将使用默认值 209715199
分区 3 已设置为 Linux 类型,大小设为 60 GiB

命令(输入 m 获取帮助):w                                         --------这里输入w  写入分区表
The partition table has been altered!

Calling 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@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# fdisk -l                                                   ------------------------分区完成后再次查看磁盘大小

磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0000eb92

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
/dev/sda3 83886080 209715199 62914560 83 Linux                                    -----------------------这里多了一个刚分好的磁盘

磁盘 /dev/sdb:644.2 GB, 644245094400 字节,1258291200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xa583bdd7

设备 Boot Start End Blocks Id System
/dev/sdb1 2048 1258291199 629144576 83 Linux

磁盘 /dev/mapper/centos-root:37.7 GB, 37706792960 字节,73646080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# vgdisplay -v                        -----------------查看卷分组                     
--- 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 <39.00 GiB
PE Size 4.00 MiB
Total PE 9983
Alloc PE / Size 9982 / 38.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID OqYA0k-8Xl3-WXXZ-LnYz-FGiO-LWce-iDBkvS

--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID ZQAvzL-hZ5D-Pi9v-OweB-JJmL-Xjb1-2pm34N
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:11 +0800
LV Status available
# open 2
LV Size <3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID zg2AcT-jRMl-H5lm-871w-umwY-7DJo-y81b00
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:12 +0800
LV Status available
# open 1
LV Size <35.12 GiB
Current LE 8990
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

--- Physical volumes ---
PV Name /dev/sda2
PV UUID W8i5G8-dIuP-6cf6-oS7j-iKYV-Y8Lj-pViCO8
PV Status allocatable
Total PE / Free PE 9983 / 1

[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# pvcreate /dev/sda3          -------------为之前新增的分区创建物理卷
Device /dev/sda3 not found.                          -------------输入这个命令报错
[root@zabbix ~]# partprobe                          ------------输入 partprobe 解决        
[root@zabbix ~]# pvcreate /dev/sda3            ---------------为之前新增的分区创建物理卷
Physical volume "/dev/sda3" successfully created.       -----看到提示
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# pvdisplay       ------------------------查看结果
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <39.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 9983
Free PE 1
Allocated PE 9982
PV UUID W8i5G8-dIuP-6cf6-oS7j-iKYV-Y8Lj-pViCO8

"/dev/sda3" is a new physical volume of "60.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 60.00 GiB                                     ---------------------------------这个新增的磁盘60G
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID O6ASsi-jn6p-5hEN-iHqj-2Uh1-MRCI-f6nffz

[root@zabbix ~]# vgextend centos /dev/sda3                      --------------------扩展卷分组
Volume group "centos" successfully extended
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# lvdisplay                           -----------------------查看逻辑卷
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID ZQAvzL-hZ5D-Pi9v-OweB-JJmL-Xjb1-2pm34N
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:11 +0800
LV Status available
# open 2
LV Size <3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID zg2AcT-jRMl-H5lm-871w-umwY-7DJo-y81b00
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:12 +0800
LV Status available
# open 1
LV Size <35.12 GiB
Current LE 8990
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# lvextend -L +60G /dev/centos/root                       -------------------------------扩展逻辑卷
Size of logical volume centos/root changed from <35.12 GiB (8990 extents) to <95.12 GiB (24350 extents).
Logical volume centos/root successfully resized.
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# xfs_growfs /dev/centos/root                             --------------------------------扩大文件系统
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2301440 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9205760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4495, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9205760 to 24934400
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# df -TH                                       ------------------------------完成后再次查看磁盘
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 8.4G 0 8.4G 0% /dev
tmpfs tmpfs 8.4G 0 8.4G 0% /dev/shm
tmpfs tmpfs 8.4G 27M 8.4G 1% /run
tmpfs tmpfs 8.4G 0 8.4G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 103G 5.2G 97G 6% /       --------------------------------容量已增加
/dev/sdb1 ext3 635G 5.2G 597G 1% /data
/dev/sda1 xfs 1.1G 194M 871M 19% /boot
tmpfs tmpfs 1.7G 13k 1.7G 1% /run/user/42
tmpfs tmpfs 1.7G 0 1.7G 0% /run/user/0
[root@zabbix ~]#

原文地址:https://www.cnblogs.com/jingjiaming/p/14188856.html