为lvm逻辑分区扩容

时间:2021-07-16
本文章向大家介绍为lvm逻辑分区扩容,主要包括为lvm逻辑分区扩容使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

如果你的设备空间有额外的硬盘空间,而原本的硬盘空间又不够时,可以进行扩容,前提是该分区是LVM分区。
步骤:
1.使用fdisk /dev/vda将剩余的空间分区,分别执行命令n,p,enter,enter,w即可,分别是创建一个分区,类型为primary,使用默认的分区号,使用剩余的所有硬盘空间,保存。

# fdisk -l /dev/vda

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000dd99c

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 526335 262144 83 Linux
/dev/vda2 526336 14680063 7076864 83 Linux
[root@host-192-168-0-102 yamu]#
[root@host-192-168-0-102 yamu]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).

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 (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (14680064-83886079, default 14680064):
Using default value 14680064
Last sector, +sectors or +size{K,M,G} (14680064-83886079, default 83886079):
Using default value 83886079
Partition 3 of type Linux and of size 33 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.

2.使用fdisk -l查看是否有新的分区生成:
`# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000dd99c

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 526335 262144 83 Linux
/dev/vda2 526336 14680063 7076864 83 Linux
/dev/vda3 14680064 83886079 34603008 83 Linux

Disk /dev/mapper/centos-root: 7243 MB, 7243563008 bytes, 14147584 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`

3.使用lsblk命令查看是否有新的分区信息,如果没有则重启设备。
4.使用pvcreate /dev/vda3命令将新的分区设置为PV物理卷。
# pvcreate /dev/vda3 File descriptor 3 (/var/log/ddicli/ddicli.log) leaked on pvcreate invocation. Parent PID 1944: bash File descriptor 4 (pipe:[19155]) leaked on pvcreate invocation. Parent PID 1944: bash File descriptor 5 (pipe:[19155]) leaked on pvcreate invocation. Parent PID 1944: bash File descriptor 10 (/dev/urandom) leaked on pvcreate invocation. Parent PID 1944: bash Physical volume "/dev/vda3" successfully created.

5.将PV物理卷加入卷组VG中:vgextend centos /dev/vda3
# vgextend centos /dev/vda3 File descriptor 3 (/var/log/ddicli/ddicli.log) leaked on vgextend invocation. Parent PID 1944: bash File descriptor 4 (pipe:[19155]) leaked on vgextend invocation. Parent PID 1944: bash File descriptor 5 (pipe:[19155]) leaked on vgextend invocation. Parent PID 1944: bash File descriptor 10 (/dev/urandom) leaked on vgextend invocation. Parent PID 1944: bash Volume group "centos" successfully extended

6.扩容LV:lvextend -l +100%FREE /dev/mapper/centos-root
# lvextend -l +100%FREE /dev/mapper/centos-root File descriptor 3 (/var/log/ddicli/ddicli.log) leaked on lvextend invocation. Parent PID 1944: bash File descriptor 4 (pipe:[19155]) leaked on lvextend invocation. Parent PID 1944: bash File descriptor 5 (pipe:[19155]) leaked on lvextend invocation. Parent PID 1944: bash File descriptor 10 (/dev/urandom) leaked on lvextend invocation. Parent PID 1944: bash Size of logical volume centos/root changed from <6.75 GiB (1727 extents) to 39.74 GiB (10174 extents). Logical volume centos/root successfully resized. [root@host-192-168-0-102 yamu]# [root@host-192-168-0-102 yamu]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 40G 0 disk ├─vda1 252:1 0 256M 0 part /boot ├─vda2 252:2 0 6.8G 0 part │ └─centos-root 253:0 0 39.8G 0 lvm / └─vda3 252:3 0 33G 0 part └─centos-root 253:0 0 39.8G 0 lvm /

学无止境,你说呢?

原文地址:https://www.cnblogs.com/moumouLiu/p/15020854.html