linux虚拟机lvm扩容,Linux扩展LVM容量(为EVE-NG内的Linux虚拟机硬盘扩容)

本文以EVE-NG中的Linux虚拟机为例,其中的方法也适用于其它虚拟化平台如VMWare,因为主要是对Linux系统的操作。

基本步骤为:

在主机扩展虚拟机硬盘文件的大小

在虚拟机中对新增的容量进行分区

将新建的分区转换为PV

将新增的PV加入原有的VG

对原有VG内的LV进行扩容

对原有的文件系统进行扩容

在EVE-NG新建一个LAB,添加Linux虚拟机,启动虚拟机

增加虚拟机硬盘文件大小

在EVE-NG查看Linux虚拟机的硬盘文件信息

root@eve-ng:~# qemu-img info /opt/unetlab/tmp/0/a0124e93-19d6-445f-bf12-9bf67704fe62/1/hda.qcow2

image: /opt/unetlab/tmp/0/a0124e93-19d6-445f-bf12-9bf67704fe62/1/hda.qcow2

file format: qcow2

virtual size: 30G (32212254720 bytes)

disk size: 18M

cluster_size: 65536

backing file: /opt/unetlab/addons/qemu/linux-centos-7.5/hda.qcow2

Format specific information:

compat: 1.1

lazy refcounts: false

refcount bits: 16

corrupt: false

root@eve-ng:~#

在Linux虚拟机下查看扩容前的硬盘分区信息

[root@centos ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/centos-root 28G 1.1G 27G 4% /

devtmpfs 232M 0 232M 0% /dev

tmpfs 244M 0 244M 0% /dev/shm

tmpfs 244M 4.5M 240M 2% /run

tmpfs 244M 0 244M 0% /sys/fs/cgroup

/dev/sda1 1014M 130M 885M 13% /boot

tmpfs 49M 0 49M 0% /run/user/0

[root@centos ~]#

[root@centos ~]#

[root@centos ~]# fdisk -l

[ 30.105421] blk_update_request: I/O error, dev fd0, sector 0

[ 30.127359] blk_update_request: I/O error, dev fd0, sector 0

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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

注意这个信息

dos表明类型是MBR

如果使用gdisk工具对MBR类型的硬盘进行分区,需要做特殊处理

Disk identifier: 0x0005ef33

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 62914559 30407680 8e Linux LVM

Disk /dev/mapper/centos-root: 30.1 GB, 30056382464 bytes, 58703872 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 /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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

为Linux虚拟机的硬盘文件扩容

必须先关闭Linux虚拟机再做扩容操作,否则可能出现问题,例如在EVE-NG中看到硬盘文件是40G(virtual size),但在Linux虚拟机中仍然是看到30G

root@eve-ng:~# qemu-img resize /opt/unetlab/tmp/0/a0124e93-19d6-445f-bf12-9bf67704fe62/1/hda.qcow2 + 10G

qemu-img: Expecting one image file name

Try 'qemu-img --help' for more information

root@eve-ng:~# qemu-img resize /opt/unetlab/tmp/0/a0124e93-19d6-445f-bf12-9bf67704fe62/1/hda.qcow2 +10G

Image resized.

root@eve-ng:~#

对硬盘文件扩容后,查看硬盘文件信息

root@eve-ng:~# qemu-img info /opt/unetlab/tmp/0/a0124e93-19d6-445f-bf12-9bf67704fe62/1/hda.qcow2

image: /opt/unetlab/tmp/0/a0124e93-19d6-445f-bf12-9bf67704fe62/1/hda.qcow2

file format: qcow2

virtual size: 40G (42949672960 bytes)

disk size: 18M

cluster_size: 65536

backing file: /opt/unetlab/addons/qemu/linux-centos-7.5/hda.qcow2

Format specific information:

compat: 1.1

lazy refcounts: false

refcount bits: 16

corrupt: false

root@eve-ng:~#

硬盘文件变成了40G,但新增加的10G容量要在虚拟机操作系统中做进一步操作才能使用。如分区、格式化等。

如果使用VMWare Workstation,对虚拟机硬盘进行扩容后,会弹出提示,说明新增的容量要在客户机中做相应操作。

再次启动Linux虚拟机,查看硬盘分区信息

[root@centos ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/centos-root 28G 1.1G 27G 4% /

devtmpfs 232M 0 232M 0% /dev

tmpfs 244M 0 244M 0% /dev/shm

tmpfs 244M 4.5M 240M 2% /run

tmpfs 244M 0 244M 0% /sys/fs/cgroup

/dev/sda1 1014M 130M 885M 13% /boot

tmpfs 49M 0 49M 0% /run/user/0

[root@centos ~]# fdisk -l

[ 45.634232] blk_update_request: I/O error, dev fd0, sector 0

[ 45.656169] blk_update_request: I/O error, dev fd0, sector 0

Disk /dev/sda: 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: 0x0005ef33

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 62914559 30407680 8e Linux LVM

Disk /dev/mapper/centos-root: 30.1 GB, 30056382464 bytes, 58703872 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 /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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

在虚拟机系统中看到设备文件/dev/sda(即硬盘)已经变成40G,但Linux系统的文件系统并没有增加容量

在虚拟机中扩容分区

对新增硬盘容量进行分区-gdisk

查看当前分区信息

[root@centos ~]# gdisk -l /dev/sda

GPT fdisk (gdisk) version 0.8.6

Partition table scan:

MBR: MBR only

BSD: not present

APM: not present

GPT: not present

***************************************************************

Found invalid GPT and valid MBR; converting MBR to GPT format.

***************************************************************

Disk /dev/sda: 83886080 sectors, 40.0 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): BC3BE10E-1115-47F6-B7E7-76107063E161

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 83886046

Partitions will be aligned on 2048-sector boundaries

Total free space is 20973501 sectors (10.0 GiB)

Number Start (sector) End (sector) Size Code Name

1 2048 2099199 1024.0 MiB 8300 Linux filesystem

2 2099200 62914559 29.0 GiB 8E00 Linux LVM

使用gdisk对新增容量进行分区

新增的硬盘容量需要先进行分区

[root@centos ~]# gdisk或者

[root@centos ~]# gdisk /dev/sda/dev/sda为硬盘的设备名称,不能写/dev/sda1等

GPT fdisk (gdisk) version 0.8.6

Type device filename, or press to exit: /dev/sda

Partition table scan:

MBR: MBR only

BSD: not present

APM: not present

GPT: not present

***************************************************************

Found invalid GPT and valid MBR; converting MBR to GPT format.

THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if

you don't want to convert your MBR partitions to GPT format!

***************************************************************

请注意这个提示

出现这个提示说明当前操作的硬盘/dev/sda使用的是MBR,而不是GPT,gdisk似乎会自动将硬盘由MBR改为GTP,

结果就是重启系统时会无法启动,卡在"booting system from hard disk"这个状态。

查看解决方法:MBR与GPT

Command (? for help): p

#打印当前分区信息

Disk /dev/sda: 83886080 sectors, 40.0 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): 7A7245B0-FE60-471C-A6BA-3C6C30C024DE

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 83886046

Partitions will be aligned on 2048-sector boundaries

Total free space is 20973501 sectors (10.0 GiB)

Number Start (sector) End (sector) Size Code Name

1 2048 2099199 1024.0 MiB 8300 Linux filesystem

2 2099200 62914559 29.0 GiB 8E00 Linux LVM

Command (? for help): v

#验证分区

No problems found. 20973501 free sectors (10.0 GiB) available in 2

segments, the largest of which is 20971487 (10.0 GiB) in size.

Command (? for help): n

新建分区

Partition number (3-128, default 3): 回车

选择新建分区的编号

First sector (34-83886046, default = 62914560) or {+-}size{KMGTP}: 回车

#指定新建分区的起始扇区,回车使用默认值,即空闲空间的第一个扇区

Last sector (62914560-83886046, default = 83886046) or {+-}size{KMGTP}: +1G

#指定新建分区的结束扇区,回车使用默认值,即空闲空间的最后一个扇区

#在初始扇区的基础上加1G

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300): L

8200 Linux swap 8300 Linux filesystem 8301 Linux reserved

8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot

Hex code or GUID (L to show codes, Enter = 8300): 8e00

Changed type of partition to 'Linux LVM'

?ommand (? for help): n

Partition number (4-128, default 4): 回车

First sector (34-83886046, default = 65011712) or {+-}size{KMGTP}: 回车

Last sector (65011712-83886046, default = 83886046) or {+-}size{KMGTP}: +1G

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300): 8e00

Changed type of partition to 'Linux LVM'

Command (? for help): n

Partition number (5-128, default 5): 回车

First sector (34-83886046, default = 67108864) or {+-}size{KMGTP}: 回车

Last sector (67108864-83886046, default = 83886046) or {+-}size{KMGTP}: +1G

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300): 8e00

Changed type of partition to 'Linux LVM'

Command (? for help): n

Partition number (6-128, default 6): 回车

First sector (34-83886046, default = 69206016) or {+-}size{KMGTP}: 回车

Last sector (69206016-83886046, default = 83886046) or {+-}size{KMGTP}: +1G

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300): 8e00

Changed type of partition to 'Linux LVM'

Command (? for help): p

打印分区信息

Disk /dev/sda: 83886080 sectors, 40.0 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): C8B1855B-15C9-4F46-B986-2807505282F0

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 83886046

Partitions will be aligned on 2048-sector boundaries

Total free space is 12584893 sectors (6.0 GiB)

Number Start (sector) End (sector) Size Code Name

1 2048 2099199 1024.0 MiB 8300 Linux filesystem

2 2099200 62914559 29.0 GiB 8E00 Linux LVM

3 62914560 65011711 1024.0 MiB 8E00 Linux LVM

4 65011712 67108863 1024.0 MiB 8E00 Linux LVM

5 67108864 69206015 1024.0 MiB 8E00 Linux LVM

6 69206016 71303167 1024.0 MiB 8E00 Linux LVM

Command (? for help): w

#保存分区信息

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING

PARTITIONS!!

Do you want to proceed? (Y/N): y

OK; writing new GUID partition table (GPT) to /dev/sda.

Warning: The kernel is still using the old partition table.

The new table will be used at the next reboot.

The operation has completed successfully.

对新增硬盘容量进行分区-fdisk

[root@centos ~]# fdisk /dev/sda

fdisk后面写硬盘设备/dev/sda

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): m#查看菜单

Command action

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)

Command (m for help): n

#新建分区

Partition type:

p primary (2 primary, 0 extended, 2 free)

e extended

Select (default p): e

#创建扩展分区

与gdisk不同的是,fdisk在新建分区是要选择主分区(primary)或扩展分区(extended),根据自己的需要创建即可

这里选择的是扩展分区

Partition number (3,4, default 3): 回车

First sector (62914560-83886079, default 62914560):

#指定新建分区的起始扇区,回车使用默认值,即空闲空间的第一个扇区

Using default value 62914560

Last sector, +sectors or +size{K,M,G} (62914560-83886079, default 83886079): 回车

#指定新建分区的结束扇区,回车使用默认值,即空闲空间的最后一个扇区

Using default value 83886079

Partition 3 of type Extended and of size 10 GiB is set

#新增的10G空间都划分给逻辑分区了

这里创建扩展分区

扩展分区可以理解为是一个容器,它不是一个可以格式化的对象,还要在扩展分区里继续划分逻辑分区,逻辑分区才可以格式化

Command (m for help): n

Partition type:

p primary (2 primary, 1 extended, 1 free)

l logical (numbered from 5)

Select (default p): l

#创建逻辑分区

Adding logical partition 5

First sector (62916608-83886079, default 62916608): 回车

Using default value 62916608

Last sector, +sectors or +size{K,M,G} (62916608-83886079, default 83886079): +1G

#在初始扇区的基础上加1G的空间

Partition 5 of type Linux and of size 1 GiB is set

Command (m for help): n

Partition type:

p primary (2 primary, 1 extended, 1 free)

l logical (numbered from 5)

Select (default p): l

Adding logical partition 6

First sector (65015808-83886079, default 65015808): 回车

Using default value 65015808

Last sector, +sectors or +size{K,M,G} (65015808-83886079, default 83886079): +1G

Partition 6 of type Linux and of size 1 GiB is set

Command (m for help): n

Partition type:

p primary (2 primary, 1 extended, 1 free)

l logical (numbered from 5)

Select (default p): l

Adding logical partition 7

First sector (67115008-83886079, default 67115008): 回车

Using default value 67115008

Last sector, +sectors or +size{K,M,G} (67115008-83886079, default 83886079): +1G

Partition 7 of type Linux and of size 1 GiB is set

Command (m for help): n

Partition type:

p primary (2 primary, 1 extended, 1 free)

l logical (numbered from 5)

Select (default p): l

Adding logical partition 8

First sector (69214208-83886079, default 69214208): 回车

Using default value 69214208

Last sector, +sectors or +size{K,M,G} (69214208-83886079, default 83886079): +1G

Partition 8 of type Linux and of size 1 GiB is set

Command (m for help): p

#打印分区信息

Disk /dev/sda: 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: 0x0005ef33

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 62914559 30407680 8e Linux LVM

/dev/sda3 62914560 83886079 10485760 5 Extended

/dev/sda5 62916608 65013759 1048576 83 Linux

/dev/sda6 65015808 67112959 1048576 83 Linux

/dev/sda7 67115008 69212159 1048576 83 Linux

/dev/sda8 69214208 71311359 1048576 83 Linux

创建的分区默认的分区系统ID(partition's system ID)是83,即Linux

在这里要把ID改为8e,即Linux LVM

Command (m for help): t

#修改分区的系统ID

Partition number (1-3,5-8, default 8): 5

Hex code (type L to list all codes): L

2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-

8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t

Partition number (1-3,5-8, default 8): 6

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t

Partition number (1-3,5-8, default 8): 7

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t

Partition number (1-3,5-8, default 8): 8

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

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.

查看新建的分区

[root@centos ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/centos-root 28G 1.2G 27G 4% /

devtmpfs 232M 0 232M 0% /dev

tmpfs 244M 0 244M 0% /dev/shm

tmpfs 244M 4.5M 240M 2% /run

tmpfs 244M 0 244M 0% /sys/fs/cgroup

/dev/sda1 1014M 130M 885M 13% /boot

tmpfs 49M 0 49M 0% /run/user/0

[root@centos ~]#

[root@centos ~]# fdisk -l

[ 174.094649] blk_update_request: I/O error, dev fd0, sector 0

[ 174.117595] blk_update_request: I/O error, dev fd0, sector 0

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 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: gpt

Disk identifier: 808D0AC2-6A5A-4F6F-BAE7-5424758BB11D

# Start End Size Type Name

1 2048 2099199 1G Linux filesyste Linux filesystem

2 2099200 62914559 29G Linux LVM Linux LVM

3 62914560 65011711 1G Linux LVM Linux LVM

4 65011712 67108863 1G Linux LVM Linux LVM

5 67108864 69206015 1G Linux LVM Linux LVM

6 69206016 71303167 1G Linux LVM Linux LVM

Disk /dev/mapper/centos-root: 30.1 GB, 30056382464 bytes, 58703872 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 /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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@centos ~]# ll /dev/sda*

brw-rw----. 1 root disk 8, 0 Jul 30 21:02 /dev/sda

brw-rw----. 1 root disk 8, 1 Jul 30 21:02 /dev/sda1

brw-rw----. 1 root disk 8, 2 Jul 30 21:02 /dev/sda2

使分区生效

要使分区生效,可以重启系统,或者使用partprobe命令

[root@centos ~]# partprobe -s

/dev/sda: gpt partitions 1 2 3 4 5 6

[root@centos ~]#

[root@centos ~]# ll /dev/sda*

brw-rw----. 1 root disk 8, 0 Jul 30 21:05 /dev/sda

brw-rw----. 1 root disk 8, 1 Jul 30 21:05 /dev/sda1

brw-rw----. 1 root disk 8, 2 Jul 30 21:05 /dev/sda2

brw-rw----. 1 root disk 8, 3 Jul 30 21:05 /dev/sda3

brw-rw----. 1 root disk 8, 4 Jul 30 21:05 /dev/sda4

brw-rw----. 1 root disk 8, 5 Jul 30 21:05 /dev/sda5

brw-rw----. 1 root disk 8, 6 Jul 30 21:05 /dev/sda6

创建PV

查看文件系统信息

[root@centos ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/centos-root 28G 1.2G 27G 4% /

devtmpfs 232M 0 232M 0% /dev

tmpfs 244M 0 244M 0% /dev/shm

tmpfs 244M 4.5M 240M 2% /run

tmpfs 244M 0 244M 0% /sys/fs/cgroup

/dev/sda1 1014M 130M 885M 13% /boot

tmpfs 49M 0 49M 0% /run/user/0

查看当前硬盘设备

[root@centos ~]# ll /dev/sda*

brw-rw----. 1 root disk 8, 0 Jul 30 21:05 /dev/sda

brw-rw----. 1 root disk 8, 1 Jul 30 21:05 /dev/sda1

brw-rw----. 1 root disk 8, 2 Jul 30 21:05 /dev/sda2

brw-rw----. 1 root disk 8, 3 Jul 30 21:05 /dev/sda3

brw-rw----. 1 root disk 8, 4 Jul 30 21:05 /dev/sda4

brw-rw----. 1 root disk 8, 5 Jul 30 21:05 /dev/sda5

brw-rw----. 1 root disk 8, 6 Jul 30 21:05 /dev/sda6

扫描系统上的PV

[root@centos ~]# pvscan

PV /dev/sda2 VG centos lvm2 [<29.00 GiB / 4.00 MiB free]

Total: 1 [<29.00 GiB] / in use: 1 [<29.00 GiB] / in no VG: 0 [0 ]

PV的名称为/dev/sda2

属于centos这个VG

创建PV

[root@centos ~]# pvcreate /dev/sda{3,4,5,6}

Physical volume "/dev/sda3" successfully created.

Physical volume "/dev/sda4" successfully created.

Physical volume "/dev/sda5" successfully created.

Physical volume "/dev/sda6" successfully created.

pvcreate命令后面写设备名称,如/dev/sda3

再次扫描PV,可以看到新增的PV

[root@centos ~]# pvscan

PV /dev/sda2 VG centos lvm2 [<29.00 GiB / 4.00 MiB free]

PV /dev/sda6 lvm2 [1.00 GiB]

PV /dev/sda5 lvm2 [1.00 GiB]

PV /dev/sda3 lvm2 [1.00 GiB]

PV /dev/sda4 lvm2 [1.00 GiB]

Total: 5 [<33.00 GiB] / in use: 1 [<29.00 GiB] / in no VG: 4 [4.00 GiB]

PV名称与设备名称同名,如/dev/sda2

扩展VG

扫描系统上的VG

[root@centos ~]# vgscan

Reading volume groups from cache.

Found volume group "centos" using metadata type lvm2

VG名称为centos

将新建的PV加入原有的VG,即扩展VG容量

[root@centos ~]# vgextend centos /dev/sda{3,4,5,6}

Volume group "centos" successfully extended

centos为VG的名称

/dev/sda3为PV的名称

查看VG的详细信息

[root@centos ~]# vgdisplay centos

--- 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 <29.00 GiB

PE Size 4.00 MiB

Total PE 7423

Alloc PE / Size 7422 / 28.99 GiB

Free PE / Size 1 / 4.00 MiB

VG UUID yVMVnN-Qkj8-E7ld-g6FP-e7mF-7RQP-lj6WKI

扩展LV

LV即Logical Volume,逻辑卷

LV即硬盘分区,是格式化的对象

扫描系统上的LV

[root@centos ~]# lvscan

ACTIVE '/dev/centos/swap' [1.00 GiB] inherit

ACTIVE '/dev/centos/root' [27.99 GiB] inherit

LV全称为/dev/centos/root,对LV进行操作时,应写LV的全称

/dev/centos/root中,centos是VG名称,root是LV名称

查看LV的详细信息

[root@centos ~]# lvdisplay /dev/centos/root

--- Logical volume ---

LV Path /dev/centos/root

LV Name root

VG Name centos

LV UUID Xe2D4n-AkzU-Dc8C-bcmo-3RUb-yuhC-RyPERg

LV Write Access read/write

LV Creation host, time centos, 2018-06-09 02:21:50 +0800

LV Status available

# open 1

LV Size 27.99 GiB

Current LE 7166

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 8192

Block device 253:0

扩展原有的LV

[root@centos ~]# lvextend /dev/centos/root /dev/sda{3,4,5,6}

Size of logical volume centos/root changed from 27.99 GiB (7166 extents) to <31.98 GiB (8186 extents).

Logical volume centos/root successfully resized.

/dev/centos/root为LV名称

/dev/sda3是PV名称

这里的做法是,以PV为单位对LV进行扩展,即将整个PV加入原有的LV

查看LV,容量已经增大了

[root@centos ~]# lvscan

ACTIVE '/dev/centos/swap' [1.00 GiB] inherit

ACTIVE '/dev/centos/root' [<31.98 GiB] inherit

但查看文件系统时容量没有改变

[root@centos ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

/dev/mapper/centos-root xfs 28G 1.2G 27G 4% /

devtmpfs devtmpfs 232M 0 232M 0% /dev

tmpfs tmpfs 244M 0 244M 0% /dev/shm

tmpfs tmpfs 244M 4.5M 240M 2% /run

tmpfs tmpfs 244M 0 244M 0% /sys/fs/cgroup

/dev/sda1 xfs 1014M 130M 885M 13% /boot

tmpfs tmpfs 49M 0 49M 0% /run/user/0

扩展文件系统

需要对文件系统进行扩展才最终使得容量增加

ext2/ext3/ext4文件系统使用命令resize2fs

xfs文件系统使用命令xfs_growfs

文件系统名称可使用df命令查看

[root@centos ~]# xfs_growfs /dev/mapper/centos-root或者

[root@centos ~]# xfs_growfs /

meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1834496 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0 spinodes=0

data = bsize=4096 blocks=7337984, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal bsize=4096 blocks=3583, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

data blocks changed from 7337984 to 8382464

xfs_growfs的说明是,命令后面写挂载点

再次查看文件系统信息,容量已经增加了

[root@centos ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/centos-root 32G 1.2G 31G 4% /

devtmpfs 232M 0 232M 0% /dev

tmpfs 244M 0 244M 0% /dev/shm

tmpfs 244M 4.5M 240M 2% /run

tmpfs 244M 0 244M 0% /sys/fs/cgroup

/dev/sda1 1014M 130M 885M 13% /boot

tmpfs 49M 0 49M 0% /run/user/0

参考资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值