前言:

对于运维工作来说,磁盘管理是一个非常重要的工作。当然了,此类工作也是比较偏向底层的一项工作。

一个合理的磁盘分区设置,文件系统格式,以及准确的lvm逻辑管理会对我们的后期的扩展工作,管理工作带来很大的便利,并且能在一定程度上提升整个服务器的性能。

本文将以VMware虚拟机为例,讲解如何创建lvm,如何不重启服务器的扩容一个在使用的文件系统的根目录以及普通的磁盘如何转化为lvm。

一,

基本概念

基本概念

(1)PV:物理卷(Physical volume):物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘。一块硬盘,或多块硬盘。

(2)VG:卷组(Volume Group):卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组。一堆磁盘的统称。

(3)LV:逻辑卷(Logical Volume):逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组。一个逻辑分区,一个分区。

(4)PE(Physical Extent):每一个物理卷被划分为称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。

(5)LE(Logical Extent):逻辑卷也被划分为被称为LE(Logical Extents) 的可被寻址的基本单位。在同一个卷组中,LE的大小和PE是相同的,并且一一对应。
(6)lvm概念:LVM(Logical Volume Manager逻辑卷管理)是Linux环境中对磁盘分区进行管理的一种机制,是建立在硬盘和分区之上、文件系统之下的一个逻辑层,可提高磁盘分区管理的灵活性。

在centos内,如果是最小化安装可能会没有lvm管理工具,因此,需要安装lvm2:

yum install lvm2 -y

二,

本次实验的环境介绍

三块硬盘,100G的是系统盘

 磁盘挂载情况如下:

现在仅有sda在使用,并且sda已经是lvm逻辑卷管理,根目录是50G大小,50+2+47+1刚好是100G,sda磁盘的总共容量。

sdb已经分区并格式化并挂载到了data1目录,总容量是20G

sdc没有分区和格式化。是一个全新的磁盘,总容量是30G

假设现在的需求是将sdb和sdc都纳入lvm管理,并且将根目录扩容到70G

1,

查看扩容前的状态:

主要是使用lsblk,blkid,df,pvdisplay,vgdisplay,lvdisplay这几个命令,根目录的文件系统格式是ext4

[root@EULEER ~]# lsblk
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                8:0    0  100G  0 disk 
├─sda1             8:1    0    1G  0 part /boot
└─sda2             8:2    0   99G  0 part 
  ├─euleros-root 253:0    0   50G  0 lvm  /
  ├─euleros-swap 253:1    0    2G  0 lvm  [SWAP]
  └─euleros-home 253:2    0   47G  0 lvm  /home
sdb                8:16   0   20G  0 disk /data1
sdc                8:32   0   30G  0 disk 
sr0               11:0    1  4.6G  0 rom  /mnt
[root@EULEER ~]# blkid
/dev/sr0: UUID="2019-02-12-00-00-00-00" LABEL="EulerOS V2.0SP5 x86_64" TYPE="iso9660" 
/dev/sda1: UUID="3c6a7424-29c8-4d8d-96b8-1c666a2552b5" TYPE="ext4" 
/dev/sda2: UUID="vdoK22-iLHE-SXBp-II7t-jr83-YZrT-Ck9hp7" TYPE="LVM2_member" 
/dev/sdb: UUID="6d9e6047-8d2d-4761-97ac-139d9f263155" TYPE="xfs" 
/dev/mapper/euleros-root: UUID="2192f98c-8066-4ff4-ab12-38abb88ae21b" TYPE="ext4" 
/dev/mapper/euleros-swap: UUID="1ce50f1b-8271-4a6d-bd4f-27b427f195e7" TYPE="swap" 
/dev/mapper/euleros-home: UUID="3d61f021-8916-455e-97fe-0411218d85c2" TYPE="ext4" 


[root@EULEER ~]# df -ah
Filesystem                Size  Used Avail Use% Mounted on
rootfs                       -     -     -    - /
sysfs                        0     0     0    - /sys
proc                         0     0     0    - /proc
devtmpfs                  981M     0  981M   0% /dev
securityfs                   0     0     0    - /sys/kernel/security
tmpfs                     992M     0  992M   0% /dev/shm
devpts                       0     0     0    - /dev/pts
。。。。略略略
/dev/mapper/euleros-root   49G  5.1G   42G  11% /
debugfs                      0     0     0    - /sys/kernel/debug
mqueue                       0     0     0    - /dev/mqueue
systemd-1                    0     0     0    - /proc/sys/fs/binfmt_misc
hugetlbfs                    0     0     0    - /dev/hugepages
/dev/sr0                  4.6G  4.6G     0 100% /mnt
/dev/sda1                 976M  115M  795M  13% /boot
/dev/sdb                   20G   33M   20G   1% /data1
/dev/mapper/euleros-home   47G   62M   44G   1% /home
sunrpc                       0     0     0    - /var/lib/nfs/rpc_pipefs
tmpfs                     199M     0  199M   0% /run/user/0


[root@EULEER ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Mar  9 01:23:27 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/euleros-root /                       ext4    defaults        1 1
UUID=3c6a7424-29c8-4d8d-96b8-1c666a2552b5 /boot                   ext4    defaults        1 2
/dev/mapper/euleros-home /home                   ext4    defaults        1 2
/dev/mapper/euleros-swap swap                    swap    defaults        0 0
/dev/sr0 /mnt iso9660 defaults 0 0 



[root@EULEER ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               euleros
  PV Size               <99.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25343
  Free PE               1
  Allocated PE          25342
  PV UUID               vdoK22-iLHE-SXBp-II7t-jr83-YZrT-Ck9hp7
   
[root@EULEER ~]# vgdisplay 
  --- Volume group ---
  VG Name               euleros
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <99.00 GiB
  PE Size               4.00 MiB
  Total PE              25343
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               7jLpC0-m532-xsAA-AQk2-D7VA-f8G9-CKBsuP
   
[root@EULEER ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/euleros/swap
  LV Name                swap
  VG Name                euleros
  LV UUID                k3AxS2-cWUe-4zyz-PCli-bQNp-bUwo-2okGqc
  LV Write Access        read/write
  LV Creation host, time localhost, 2023-03-09 01:23:18 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/euleros/home
  LV Name                home
  VG Name                euleros
  LV UUID                fdgAw4-YN9L-zAh4-6O2E-f4vT-k7JC-lTDe99
  LV Write Access        read/write
  LV Creation host, time localhost, 2023-03-09 01:23:19 +0800
  LV Status              available
  # open                 1
  LV Size                46.99 GiB
  Current LE             12030
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/euleros/root
  LV Name                root
  VG Name                euleros
  LV UUID                qXMhds-ivkh-E1QE-7IVy-wZvq-pYYp-aKSPBZ
  LV Write Access        read/write
  LV Creation host, time localhost, 2023-03-09 01:23:23 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   


二,

磁盘规划说明

sdb磁盘划分为两个分区,每个分区10G。其中的第一个分区加入sda的lvm,第二个分区不加入lvm,采用标准分区。

sdc磁盘作为一个整体加入一个全新的lvm,并通过两次扩容,扩容到根目录,使得最终根目录容量到70G

三,

根目录扩容

第一次扩容 从50G扩容到60G,将sdb磁盘划分为两个10G的分区,将第二个分区,也就是sdb2扩容到根目录

###注:根目录扩容的前提条件是根目录是lvm逻辑卷

1,

利用fdisk划分sdb的分区,可以看到第一次分区是错误的,sdb1容量不对,第二次分区才是正确的。

[root@EULEER ~]# fdisk /dev/sdb
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x5c6eb410.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): e
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G  
Partition 1 of type Extended and of size 10 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@EULEER ~]# partprobe 
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@EULEER ~]# fdisk /dev/sdb
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 (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-20973567, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-20973567, default 20973567): 
Using default value 20973567
Partition 5 of type Linux and of size 10 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@EULEER ~]# partprobe 
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@EULEER ~]# lsblk
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                8:0    0  100G  0 disk 
├─sda1             8:1    0    1G  0 part /boot
└─sda2             8:2    0   99G  0 part 
  ├─euleros-root 253:0    0   50G  0 lvm  /
  ├─euleros-swap 253:1    0    2G  0 lvm  [SWAP]
  └─euleros-home 253:2    0   47G  0 lvm  /home
sdb                8:16   0   20G  0 disk 
├─sdb1             8:17   0    1K  0 part 
└─sdb5             8:21   0   10G  0 part 
sdc                8:32   0   30G  0 disk 
sr0               11:0    1  4.6G  0 rom  /mnt
[root@EULEER ~]# blkid
/dev/sr0: UUID="2019-02-12-00-00-00-00" LABEL="EulerOS V2.0SP5 x86_64" TYPE="iso9660" 
/dev/sda1: UUID="3c6a7424-29c8-4d8d-96b8-1c666a2552b5" TYPE="ext4" 
/dev/sda2: UUID="vdoK22-iLHE-SXBp-II7t-jr83-YZrT-Ck9hp7" TYPE="LVM2_member" 
/dev/mapper/euleros-root: UUID="2192f98c-8066-4ff4-ab12-38abb88ae21b" TYPE="ext4" 
/dev/mapper/euleros-swap: UUID="1ce50f1b-8271-4a6d-bd4f-27b427f195e7" TYPE="swap" 
/dev/mapper/euleros-home: UUID="3d61f021-8916-455e-97fe-0411218d85c2" TYPE="ext4" 
[root@EULEER ~]# fdisk /dev/sdb
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): t
Partition number (1,5, default 5): 5
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.
Syncing disks.





分区完毕后,查看分区的状态,并执行扩容命令,扩容了两次,第一次是9G,第二次是1G:

主要使用的命令是vgs, vgextend,lvextend,resize2fs

特别需要注意的是vgs命令,该命令不带参数的时候可以查看所有的vg,主要是该命令会显示vg的剩余容量,例如本例中,第一次查询是剩余4m,扩容vg后,可以看到剩余容量达到了10G,执行了vgextend euleros /dev/sdb5这个命令后,vgs命令显示pv增加了1,vfree表示有10G的空间扩容。

[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree 
  euleros   2   3   0 wz--n- 108.99g 10.00g 

vgextend 现有的vg名称 要添加的分区,本例就是vgextend euleros /dev/sdb5

resize2fs是针对ext4分区格式的命令,本例中要扩容的根目录是ext4分区格式。如果是xfs的分区格式,则使用xfs_growfs命令。该命令主要是同步df命令,否则是仅仅vgs命令显示扩容了,而df命令还是原来的显示。

[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  euleros   1   3   0 wz--n- <99.00g 4.00m
[root@EULEER ~]# vgextend euleros /dev/sdb5
  Physical volume "/dev/sdb5" successfully created.
  Volume group "euleros" successfully extended
[root@EULEER ~]# lsblk
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                8:0    0  100G  0 disk 
├─sda1             8:1    0    1G  0 part /boot
└─sda2             8:2    0   99G  0 part 
  ├─euleros-root 253:0    0   50G  0 lvm  /
  ├─euleros-swap 253:1    0    2G  0 lvm  [SWAP]
  └─euleros-home 253:2    0   47G  0 lvm  /home
sdb                8:16   0   20G  0 disk 
├─sdb1             8:17   0    1K  0 part 
└─sdb5             8:21   0   10G  0 part 
sdc                8:32   0   30G  0 disk 
sr0               11:0    1  4.6G  0 rom  /mnt
[root@EULEER ~]# blkid
/dev/sr0: UUID="2019-02-12-00-00-00-00" LABEL="EulerOS V2.0SP5 x86_64" TYPE="iso9660" 
/dev/sda1: UUID="3c6a7424-29c8-4d8d-96b8-1c666a2552b5" TYPE="ext4" 
/dev/sda2: UUID="vdoK22-iLHE-SXBp-II7t-jr83-YZrT-Ck9hp7" TYPE="LVM2_member" 
/dev/mapper/euleros-root: UUID="2192f98c-8066-4ff4-ab12-38abb88ae21b" TYPE="ext4" 
/dev/mapper/euleros-swap: UUID="1ce50f1b-8271-4a6d-bd4f-27b427f195e7" TYPE="swap" 
/dev/mapper/euleros-home: UUID="3d61f021-8916-455e-97fe-0411218d85c2" TYPE="ext4" 
/dev/sdb5: UUID="JKvfyx-9GzI-XXTD-eaq5-6LG1-4JPU-YhvyJo" TYPE="LVM2_member" 
[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree 
  euleros   2   3   0 wz--n- 108.99g 10.00g 
[root@EULEER ~]# lvextend -L +9G /dev/euleros/root
  Size of logical volume euleros/root changed from 50.00 GiB (12800 extents) to 59.00 GiB (15104 extents).
  Logical volume euleros/root successfully resized.

[root@EULEER ~]# resize2fs /dev/mapper/euleros-root 
resize2fs 1.45.0 (6-Mar-2019)
Filesystem at /dev/mapper/euleros-root is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 8
The filesystem on /dev/mapper/euleros-root is now 15466496 (4k) blocks long.
[root@EULEER ~]# df -ah
Filesystem                Size  Used Avail Use% Mounted on
rootfs                       -     -     -    - /
sysfs                        0     0     0    - /sys
proc                         0     0     0    - /proc
devtmpfs                  981M     0  981M   0% /dev
securityfs                   0     0     0    - /sys/kernel/security
tmpfs                     992M     0  992M   0% /dev/shm
devpts                       0     0     0    - /dev/pts
tmpfs                     992M  9.0M  983M   1% /run
tmpfs                     992M     0  992M   0% /sys/fs/cgroup
cgroup                       0     0     0    - /sys/fs/cgroup/systemd
pstore                       0     0     0    - /sys/fs/pstore
cgroup                       0     0     0    - /sys/fs/cgroup/freezer
cgroup                       0     0     0    - /sys/fs/cgroup/cpuset
cgroup                       0     0     0    - /sys/fs/cgroup/memory
cgroup                       0     0     0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                       0     0     0    - /sys/fs/cgroup/hugetlb
cgroup                       0     0     0    - /sys/fs/cgroup/pids
cgroup                       0     0     0    - /sys/fs/cgroup/devices
cgroup                       0     0     0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                       0     0     0    - /sys/fs/cgroup/perf_event
cgroup                       0     0     0    - /sys/fs/cgroup/files
cgroup                       0     0     0    - /sys/fs/cgroup/blkio
configfs                     0     0     0    - /sys/kernel/config
/dev/mapper/euleros-root   58G  5.1G   50G  10% /
debugfs                      0     0     0    - /sys/kernel/debug

[root@EULEER ~]# lvextend -L +1G /dev/euleros/root
  Size of logical volume euleros/root changed from 59.00 GiB (15104 extents) to 60.00 GiB (15360 extents).
  Logical volume euleros/root successfully resized.
[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  euleros   2   3   0 wz--n- 108.99g    0 

[root@EULEER ~]# resize2fs /dev/mapper/euleros-root 
resize2fs 1.45.0 (6-Mar-2019)
Filesystem at /dev/mapper/euleros-root is mounted on /; on-line resizing required
old_desc_blocks = 8, new_desc_blocks = 8
The filesystem on /dev/mapper/euleros-root is now 15728640 (4k) blocks long.


[root@EULEER ~]# df -ah
Filesystem                Size  Used Avail Use% Mounted on
rootfs                       -     -     -    - /
sysfs                        0     0     0    - /sys
proc                         0     0     0    - /proc
devtmpfs                  981M     0  981M   0% /dev
securityfs                   0     0     0    - /sys/kernel/security
tmpfs                     992M     0  992M   0% /dev/shm
devpts                       0     0     0    - /dev/pts
tmpfs                     992M   14M  979M   2% /run
tmpfs                     992M     0  992M   0% /sys/fs/cgroup
cgroup                       0     0     0    - /sys/fs/cgroup/systemd
pstore                       0     0     0    - /sys/fs/pstore
cgroup                       0     0     0    - /sys/fs/cgroup/freezer
cgroup                       0     0     0    - /sys/fs/cgroup/cpuset
cgroup                       0     0     0    - /sys/fs/cgroup/memory
cgroup                       0     0     0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                       0     0     0    - /sys/fs/cgroup/hugetlb
cgroup                       0     0     0    - /sys/fs/cgroup/pids
cgroup                       0     0     0    - /sys/fs/cgroup/devices
cgroup                       0     0     0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                       0     0     0    - /sys/fs/cgroup/perf_event
cgroup                       0     0     0    - /sys/fs/cgroup/files
cgroup                       0     0     0    - /sys/fs/cgroup/blkio
configfs                     0     0     0    - /sys/kernel/config
/dev/mapper/euleros-root   59G  5.1G   51G   9% /
debugfs                      0     0     0    - /sys/kernel/debug
mqueue                       0     0     0    - /dev/mqueue
systemd-1                    -     -     -    - /proc/sys/fs/binfmt_misc
hugetlbfs                    0     0     0    - /dev/hugepages
/dev/sr0                  4.6G  4.6G     0 100% /mnt
/dev/sda1                 976M  115M  795M  13% /boot
/dev/mapper/euleros-home   47G   62M   44G   1% /home
sunrpc                       0     0     0    - /var/lib/nfs/rpc_pipefs
tmpfs                     199M     0  199M   0% /run/user/0
binfmt_misc                  0     0     0    - /proc/sys/fs/binfmt_misc

[root@EULEER ~]# lsblk
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                8:0    0  100G  0 disk 
├─sda1             8:1    0    1G  0 part /boot
└─sda2             8:2    0   99G  0 part 
  ├─euleros-root 253:0    0   60G  0 lvm  /
  ├─euleros-swap 253:1    0    2G  0 lvm  [SWAP]
  └─euleros-home 253:2    0   47G  0 lvm  /home
sdb                8:16   0   20G  0 disk 
├─sdb1             8:17   0    1K  0 part 
└─sdb5             8:21   0   10G  0 part 
  └─euleros-root 253:0    0   60G  0 lvm  /
sdc                8:32   0   30G  0 disk 
sr0               11:0    1  4.6G  0 rom  /mnt
####注: 这里显示了两个挂载点 / ,不用奇怪,是正常现象。

[root@EULEER ~]# blkid
/dev/sr0: UUID="2019-02-12-00-00-00-00" LABEL="EulerOS V2.0SP5 x86_64" TYPE="iso9660" 
/dev/sda1: UUID="3c6a7424-29c8-4d8d-96b8-1c666a2552b5" TYPE="ext4" 
/dev/sda2: UUID="vdoK22-iLHE-SXBp-II7t-jr83-YZrT-Ck9hp7" TYPE="LVM2_member" 
/dev/mapper/euleros-root: UUID="2192f98c-8066-4ff4-ab12-38abb88ae21b" TYPE="ext4" 
/dev/mapper/euleros-swap: UUID="1ce50f1b-8271-4a6d-bd4f-27b427f195e7" TYPE="swap" 
/dev/mapper/euleros-home: UUID="3d61f021-8916-455e-97fe-0411218d85c2" TYPE="ext4" 
/dev/sdb5: UUID="JKvfyx-9GzI-XXTD-eaq5-6LG1-4JPU-YhvyJo" TYPE="LVM2_member" 

 

四,

新分区的lvm创建

1,

创建新的名为vg的lvm:

[root@EULEER ~]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.
[root@EULEER ~]# vgcreate vg /dev/sdb2
  Volume group "vg" successfully created
[root@EULEER ~]# lvcreate -L vg + 10G
  Size requires number argument.
  Invalid argument for --size: vg
  Error during parsing of command line.
[root@EULEER ~]# lvcreate -n vg -L 10G vg
  Volume group "vg" has insufficient free space (2559 extents): 2560 required.
[root@EULEER ~]# lvcreate -n vg -L 9G vg
  Logical volume "vg" created.

2,

将sdb2加入新lvm:

[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree   
  euleros   2   3   0 wz--n- 108.99g       0 
  vg        1   1   0 wz--n- <10.00g 1020.00m
[root@EULEER ~]# vgextend vg /dev/sd
/dev/sda2  /dev/sdb1  /dev/sdb2  
[root@EULEER ~]# lvextend -L +1020M /dev/vg/vg 
  Size of logical volume vg/vg changed from 9.00 GiB (2304 extents) to <10.00 GiB (2559 extents).
  Logical volume vg/vg successfully resized.
[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  euleros   2   3   0 wz--n- 108.99g    0 
  vg        1   1   0 wz--n- <10.00g    0 

3,

格式化新lvm:

[root@EULEER ~]# mkfs.xfs /dev/vg
vg/          vga_arbiter  
[root@EULEER ~]# mkfs.xfs /dev/vg/vg 
meta-data=/dev/vg/vg             isize=512    agcount=4, agsize=655104 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2620416, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0


 4

查看新lvm:

[root@EULEER ~]# lsblk
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                8:0    0  100G  0 disk 
├─sda1             8:1    0    1G  0 part /boot
└─sda2             8:2    0   99G  0 part 
  ├─euleros-root 253:0    0   60G  0 lvm  /
  ├─euleros-swap 253:1    0    2G  0 lvm  [SWAP]
  └─euleros-home 253:2    0   47G  0 lvm  /home
sdb                8:16   0   20G  0 disk 
├─sdb1             8:17   0   10G  0 part 
│ └─euleros-root 253:0    0   60G  0 lvm  /
└─sdb2             8:18   0   10G  0 part 
  └─vg-vg        253:3    0   10G  0 lvm  
sdc                8:32   0   30G  0 disk 
sr0               11:0    1  4.6G  0 rom  /mnt
[root@EULEER ~]# blkid
/dev/sr0: UUID="2019-02-12-00-00-00-00" LABEL="EulerOS V2.0SP5 x86_64" TYPE="iso9660" 
/dev/sda1: UUID="3c6a7424-29c8-4d8d-96b8-1c666a2552b5" TYPE="ext4" 
/dev/sda2: UUID="vdoK22-iLHE-SXBp-II7t-jr83-YZrT-Ck9hp7" TYPE="LVM2_member" 
/dev/sdb1: UUID="WLHsQw-tWIN-1WPD-fmc1-W7nO-diN2-gdE6B4" TYPE="LVM2_member" 
/dev/sdb2: UUID="0JBSkV-NnDy-OM7z-CoXb-z4ON-oFrD-4mH5Cv" TYPE="LVM2_member" 
/dev/mapper/euleros-root: UUID="2192f98c-8066-4ff4-ab12-38abb88ae21b" TYPE="ext4" 
/dev/mapper/euleros-swap: UUID="1ce50f1b-8271-4a6d-bd4f-27b427f195e7" TYPE="swap" 
/dev/mapper/euleros-home: UUID="3d61f021-8916-455e-97fe-0411218d85c2" TYPE="ext4" 
/dev/mapper/vg-vg: UUID="b97d0da8-09b2-4ad6-a666-4d54f4e0fabc" TYPE="xfs" 
[root@EULEER ~]# 

[root@EULEER ~]# mount /dev/vg/vg /data1/
[root@EULEER ~]# touch /data1/test
[root@EULEER ~]# 

4,

新磁盘sdc整体加入新lvm:

####注:可以看到,总计有39G容量没有分配,分两次通过vgs命令扩容新lvm的,由于上面那一步是个格式化的xfs,因此,是使用xfs_growfs命令扩容的。

[root@EULEER ~]# vgextend vg /dev/sdc
  Physical volume "/dev/sdc" successfully created.
  Volume group "vg" successfully extended
[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree  
  euleros   2   3   0 wz--n- 108.99g      0 
  vg        2   1   0 wz--n-  39.99g <30.00g
[root@EULEER ~]# lvextend -L +30G  /dev/vg/vg 
  Insufficient free space: 7680 extents needed, but only 7679 available
[root@EULEER ~]# lvextend -L +29G  /dev/vg/vg 
  Size of logical volume vg/vg changed from <10.00 GiB (2559 extents) to <39.00 GiB (9983 extents).
  Logical volume vg/vg successfully resized.
[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree   
  euleros   2   3   0 wz--n- 108.99g       0 
  vg        2   1   0 wz--n-  39.99g 1020.00m
[root@EULEER ~]# lvextend -L +1020M  /dev/vg/vg 
  Size of logical volume vg/vg changed from <39.00 GiB (9983 extents) to 39.99 GiB (10238 extents).
  Logical volume vg/vg successfully resized.
[root@EULEER ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  euleros   2   3   0 wz--n- 108.99g    0 
  vg        2   1   0 wz--n-  39.99g    0 
[root@EULEER ~]# xfs_growfs /dev/vg
vg/          vga_arbiter  
[root@EULEER ~]# xfs_growfs /dev/vg/vg 
meta-data=/dev/mapper/vg-vg      isize=512    agcount=4, agsize=655104 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2620416, 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 2620416 to 10483712

 

 




[root@EULEER ~]# df -ah
Filesystem                Size  Used Avail Use% Mounted on
rootfs                       -     -     -    - /
sysfs                        0     0     0    - /sys
proc                         0     0     0    - /proc
devtmpfs                  981M     0  981M   0% /dev
securityfs                   0     0     0    - /sys/kernel/security
tmpfs                     992M     0  992M   0% /dev/shm
devpts                       0     0     0    - /dev/pts
tmpfs                     992M  9.0M  983M   1% /run
tmpfs                     992M     0  992M   0% /sys/fs/cgroup
cgroup                       0     0     0    - /sys/fs/cgroup/systemd
pstore                       0     0     0    - /sys/fs/pstore
中间的无关紧要的部分略略略。。。。。。。。。。
configfs                     0     0     0    - /sys/kernel/config
/dev/mapper/euleros-root   59G  5.1G   51G   9% /
hugetlbfs                    0     0     0    - /dev/hugepages
systemd-1                    -     -     -    - /proc/sys/fs/binfmt_misc
mqueue                       0     0     0    - /dev/mqueue
debugfs                      0     0     0    - /sys/kernel/debug
/dev/sr0                  4.6G  4.6G     0 100% /mnt
/dev/sda1                 976M  115M  795M  13% /boot
/dev/mapper/euleros-home   47G   62M   44G   1% /home
sunrpc                       0     0     0    - /var/lib/nfs/rpc_pipefs
tmpfs                     199M     0  199M   0% /run/user/0
binfmt_misc                  0     0     0    - /proc/sys/fs/binfmt_misc
/dev/mapper/vg-vg          40G   33M   40G   1% /data1
[root@EULEER ~]# lsblk
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                8:0    0  100G  0 disk 
├─sda1             8:1    0    1G  0 part /boot
└─sda2             8:2    0   99G  0 part 
  ├─euleros-root 253:0    0   60G  0 lvm  /
  ├─euleros-swap 253:1    0    2G  0 lvm  [SWAP]
  └─euleros-home 253:2    0   47G  0 lvm  /home
sdb                8:16   0   20G  0 disk 
├─sdb1             8:17   0   10G  0 part 
│ └─euleros-root 253:0    0   60G  0 lvm  /
└─sdb2             8:18   0   10G  0 part 
  └─vg-vg        253:3    0   40G  0 lvm  /data1
sdc                8:32   0   30G  0 disk 
└─vg-vg          253:3    0   40G  0 lvm  /data1
sr0               11:0    1  4.6G  0 rom  /mnt
[root@EULEER ~]# blkid
/dev/sr0: UUID="2019-02-12-00-00-00-00" LABEL="EulerOS V2.0SP5 x86_64" TYPE="iso9660" 
/dev/sda1: UUID="3c6a7424-29c8-4d8d-96b8-1c666a2552b5" TYPE="ext4" 
/dev/sda2: UUID="vdoK22-iLHE-SXBp-II7t-jr83-YZrT-Ck9hp7" TYPE="LVM2_member" 
/dev/sdb1: UUID="WLHsQw-tWIN-1WPD-fmc1-W7nO-diN2-gdE6B4" TYPE="LVM2_member" 
/dev/sdb2: UUID="0JBSkV-NnDy-OM7z-CoXb-z4ON-oFrD-4mH5Cv" TYPE="LVM2_member" 
/dev/mapper/euleros-root: UUID="2192f98c-8066-4ff4-ab12-38abb88ae21b" TYPE="ext4" 
/dev/mapper/euleros-swap: UUID="1ce50f1b-8271-4a6d-bd4f-27b427f195e7" TYPE="swap" 
/dev/mapper/euleros-home: UUID="3d61f021-8916-455e-97fe-0411218d85c2" TYPE="ext4" 
/dev/mapper/vg-vg: UUID="b97d0da8-09b2-4ad6-a666-4d54f4e0fabc" TYPE="xfs" 
/dev/sdc: UUID="LTxfMg-F415-NVrC-U5nr-N94x-auj6-8S1Rzf" TYPE="LVM2_member" 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐