Centos7 磁盘空间不足扩容
Centos7.6
1-磁盘扩容
将原有盘扩容
列出所有可用块设备的信息
[root@192 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1900G 0 disk #刚扩容的1800G已经加到sda磁盘
├─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]
sr0 11:0 1 1024M 0 rom
查看服务器磁盘信息
[root@192 ~]# fdisk -l
Disk /dev/sda: 1900.4 GB, 1907374182400 bytes, 209715200 sectors #刚扩容的1800G已经加到sda磁盘
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c5f41
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
查看原磁盘容量
[root@192 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.5G 16G 9% / # /dev/mapper/centos-root容量17G
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
tmpfs 781M 0 781M 0% /run/user/0
#Filesystem: 文件系统的名称
#Size: 文件系统的总容量
#Used: 已使用的磁盘空间
#Avail: 可用的磁盘空间。
#Use%: 已使用空间占总空间的百分比
#Mounted on: 文件系统的挂载点(即文件系统所在目录)
2.磁盘分区
进行磁盘分区
p primary: 主分区
e extended: 扩展分区
p 是列表查看分区信息
w 退出
[root@192 ~]# fdisk /dev/sda
Command (m for help): n # n:表示新建分区
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p # p:创建主分区
Partition number (3,4, default 3): 3 # 3:分区号为3
First sector (41943040-19209715199, default 41943040): # 柱面从41943040开始
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-19209715199): # 柱面最大19209715199
Using default value 19209715199
Partition 3 of type Linux and of size 80 GiB is set
Command (m for help): p # p:查看分区信息
Disk /dev/sda: 1800.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c5f41
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 209715199 83886080 83 Linux # 已分区sda3
Command (m for help): w # w:保存(按照以上分区信息写入磁盘)
刷新磁盘分区
[root@192 ~]# partprobe /dev/sda
查看硬盘信息
[root@192 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1900G 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 1800G 0 part # 第三分区已创建
sr0 11:0 1 1024M 0 rom
创建物理卷
[root@192 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
查看物理卷
[root@192 ~]# pvdisplay /dev/sda3
"/dev/sda3" is a new physical volume of "80.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 80.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID vAisVP-0olP-8ACu-6XZs-NlRM-dpv7-e10KsJ
3.卷组
vgdisplay 为空,说明无卷组,有卷组和无卷组操作有差异,注意看自己是哪一种
3.1有卷组
查看卷组
[root@192 ~]# vgdisplay
--- Volume group ---
VG Name centos #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 Ozigc7-SRYy-3vzx-cNcc-IYJm-lGu4-M23j0L
将物理卷加入卷组(centos卷组名)
[root@192 ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
查看逻辑卷
[root@192 ~]# lvdisplay /dev/centos/root
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID Fa9Ff5-wh4x-ZK2C-riAo-Za00-629r-jolBLE
LV Write Access read/write
LV Creation host, time localhost, 2020-06-26 14:21:32 +0800
LV Status available
# open 1
LV Size <1800.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
将100%空余空间加入逻辑卷(centos/root是逻辑卷)
[root@192 ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <1800.00 GiB to 1800.99 GiB (24830 extents).
Logical volume centos/root successfully resized.
重新识别逻辑分区大小
[root@192 ~]# xfs_growfs /dev/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 25425920
如出现xfs_growfs: /dev/system/root is not a mounted XFS filesystem
#查看/dev/centos/root挂载在哪里
suse-oracle1:~ # df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 871M 0 871M 0% /dev
tmpfs 14G 80K 14G 1% /dev/shm
tmpfs 886M 11M 876M 2% /run
tmpfs 886M 0 886M 0% /sys/fs/cgroup
/dev/centos/root 15G 11G 4.8G 69% / # /
tmpfs 178M 16K 178M 1% /run/user/474
tmpfs 178M 0 178M 0% /run/user/0
重新识别逻辑分区大小
[root@yw ~]# xfs_growfs /
查看磁盘是否扩容
[root@192 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 97G 1.5G 1900G 2% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
tmpfs 781M 0 781M 0% /run/user/0
3.2无卷组
查看卷组
[root@192 ~]# vgdisplay #卷组为空
查看逻辑分区
[root@192 ~]# lvdisplay #逻辑分区为空
创建卷组
[root@192 ~]# vgcreate centos /dev/sda3
Volume group "centos" successfully created
创建逻辑卷
[root@192 ~]# lvcreate -L 1800G -n root centos
Logical volume "root" created.
格式化逻辑分区
[root@192 ~]# mkfs.xfs /dev/centos/root
#扩展已有卷的容量并同步到文件系统
扩展
[root@192 ~]# lvextend -l +100%FREE /dev/mapper/centos-root
重新识别centos大小
[root@192 ~]# fs_growfs /dev/mapper/centos-root
创建挂载点
[root@192 ~]# mkdir /temp
新增逻辑分区,挂在到了 /temp 目录
#逻辑分区 /dev/centos/root 变成了 /dev/mapper/centos-root
[root@192 ~]# mount /dev/centos/root /temp
永久挂载
[root@192 ~]# vim /etc/fstab
#新添:
/dev/mapper/centos-root /temp xfs defaults 0 0