1、目前状态
根目录只有20G存储,显然不够。
查看/dev/vda情况
# fdisk -l
Disk /dev/vda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0x00343e90
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 41943039 41940992 20G 83 Linux
Disk /dev/vdb: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0xbfdd54bc
Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 209715199 209713152 100G 83 Linux
/dev/vda有100GB但是只挂载了20GB,下边把剩下的存储加入到/ 目录下;
# fdisk /dev/vda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (41943040-209715199, default 41943040):
Last sector, +sectors or +size{K,M,G,T,P} (41943040-209715199, default 209715199):
Created a new partition 2 of type 'Linux' and of size 80 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 100G 0 disk
├─vda1 253:1 0 20G 0 part /
└─vda2 253:2 0 80G 0 part
vdb 253:16 0 100G 0 disk
└─vdb1 253:17 0 100G 0 part /home/mysqlback
2、对新增的磁盘处理
输入partprobe 让系统识别新增的分区;创建物理卷,使用pvcreate /dev/vda2
# partprobe
# pvcreate /dev/vda2
-bash: pvcreate: command not found
# yum -y install lvm2
# pvcreate /dev/vda2
Physical volume "/dev/vda2" successfully created.
/dev/vda2 来着上边lsblk的结果 新建的分区
3、下边分两种情况,一种是vgdisplay 命令有返回值,一种是没有返回值;
3.1是有返回值的扩容方式;3.2是没有返回值的扩容方式(适用于阿里云虚机和阿里云合作的政务云)
3.1、使用vgextend命令进行动态扩展
# 这里的ao是通过vgdisplay或者pvdisplay查到的那个vgname
vgextend ao /dev/sdb1
查看扩展的磁盘
# vgdisplay
--- Volume group ---
VG Name ao
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 94.99 GiB
PE Size 4.00 MiB
Total PE 24318
Alloc PE / Size 24318 / 94.99 GiB
Free PE / Size 0 / 0
VG UUID 7J29QB-r8gV-YKYc-E7VF-sAyG-EVD1-jg10aY
将空闲的磁盘扩展到/分区
# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.7M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/ao-root 66G 29G 38G 43% /
/dev/mapper/ao-home 26G 212M 25G 1% /home
/dev/sda1 976M 142M 767M 16% /boot
tmpfs 372M 0 372M 0% /run/user/0
#/dev/mapper/ao-root是使用df -h查出来的/分区的文件系统名称
lvextend -l +100%FREE /dev/mapper/ao-root
重新识别/分区
# blkid
/dev/sda1: UUID="60fb36d0-ce63-469b-bef6-37dd5ac14fd2" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="4578c790-01"
/dev/sda2: UUID="mTmD1j-B6Um-HSDo-Y0w6-MRmp-WjK5-G6nqY6" TYPE="LVM2_member" PARTUUID="4578c790-02"
/dev/sdb1: UUID="i7fOR8-uOdL-z0fo-N7vq-UzfR-yYZf-N0V4An" TYPE="LVM2_member" PARTUUID="fcfdb231-01"
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-07-01-22-08-59-00" LABEL="anolis-BaseOS-dvd-x86_64-8" TYPE="iso9660" PTUUID="3252e058" PTTYPE="dos"
/dev/mapper/ao-root: UUID="18ccc3e3-2e56-4290-8940-aac27116249a" BLOCK_SIZE="512" TYPE="xfs"
/dev/mapper/ao-swap: UUID="e0a6aa5c-e5de-4234-b736-88a2bdefda04" TYPE="swap"
/dev/mapper/ao-home: UUID="c8e2e00d-853c-46e8-8534-5ff29766e439" BLOCK_SIZE="512" TYPE="xfs"
# xfs_growfs /dev/mapper/ao-root
meta-data=/dev/mapper/ao-root isize=512 agcount=6, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=17300480, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
查看扩容情况
# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.7M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/ao-root 66G 29G 38G 43% /
/dev/mapper/ao-home 26G 212M 25G 1% /home
/dev/sda1 976M 142M 767M 16% /boot
tmpfs 372M 0 372M 0% /run/user/0
3.2、是没有返回值的扩容方式(适用于阿里云虚机和阿里云合作的政务云)
# fdisk -l
Disk /dev/vda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0x00343e90
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 41943039 41940992 20G 83 Linux
Disk /dev/vdb: 100 GiB, 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
100GB只挂载了20GB
# fdisk -lu /dev/vda
Disk /dev/vda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0x00343e90
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 41943039 41940992 20G 83 Linux
# type growpart
growpart is /bin/growpart
# yum install -y cloud-utils-growpart
Last metadata expiration check: 0:03:51 ago on Tue 23 Apr 2024 04:53:20 PM CST.
Package cloud-utils-growpart-0.29-3.el8.noarch is already installed.
Dependencies resolved.
==========================================================================================================================================================================
Package Architecture Version Repository Size
==========================================================================================================================================================================
Upgrading:
cloud-utils-growpart noarch 0.33-0.0.1.an8 AppStream 20 k
Transaction Summary
==========================================================================================================================================================================
Upgrade 1 Package
Total download size: 20 k
Downloading Packages:
cloud-utils-growpart-0.33-0.0.1.an8.noarch.rpm 102 kB/s | 20 kB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 101 kB/s | 20 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Upgrading : cloud-utils-growpart-0.33-0.0.1.an8.noarch 1/2
Cleanup : cloud-utils-growpart-0.29-3.el8.noarch 2/2
Running scriptlet: cloud-utils-growpart-0.29-3.el8.noarch 2/2
Verifying : cloud-utils-growpart-0.33-0.0.1.an8.noarch 1/2
Verifying : cloud-utils-growpart-0.29-3.el8.noarch 2/2
Upgraded:
cloud-utils-growpart-0.33-0.0.1.an8.noarch
Complete!
# LC_ALL=en_US.UTF-8
# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=41940992 end=41943039 new: size=209713119 end=209715166
##注意/dev/vda和1之间有空格!!!!
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.8G 0 3.8G 0% /dev/shm
tmpfs tmpfs 3.8G 460K 3.8G 1% /run
tmpfs tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/vda1 ext4 20G 4.0G 15G 22% /
tmpfs tmpfs 776M 0 776M 0% /run/user/0
# resize2fs /dev/vda1
resize2fs 1.46.0 (29-Jan-2020)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 7
The filesystem on /dev/vda1 is now 26214139 (4k) blocks long.
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.8G 0 3.8G 0% /dev/shm
tmpfs tmpfs 3.8G 460K 3.8G 1% /run
tmpfs tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/vda1 ext4 99G 4.0G 91G 5% /
tmpfs tmpfs 776M 0 776M 0% /run/user/0
扩展阅读:https://blog.51cto.com/u_15147537/7277209
https://blog.csdn.net/jincm13/article/details/18077501