LVM扩展磁盘大小

云主机扩容

拥有一个200G的硬盘空闲,未挂载,现需利用起来

/home    /usr/local/src    /var/lib/docker  分别分配40G,剩下的先闲置,后续按需求增加

pvcreate: command not found

yum -y install lvm2
#解决
[root@centos home]# pvcreate /dev/sdb1
-bash: pvcreate: command not found

查看现有磁盘容量情况

[root@centos home]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  8.5M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda2        36G  2.1G   32G   7% /
tmpfs           379M     0  379M   0% /run/user/0

查看可用的硬盘

[root@centos home]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0   40G  0 disk 
├─vda1 253:1    0    4G  0 part [SWAP]
└─vda2 253:2    0   36G  0 part /
vdb    253:16   0  200G  0 disk 
#vdb就是新增的硬盘

查看磁盘路径,方便下一步操作

[root@centos home]# 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: 0x000bcc64

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048     8390655     4194304   82  Linux swap / Solaris
/dev/vda2   *     8390656    83886046    37747695+  83  Linux

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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/vdb: 214.7 GB中间,/dev/vdb为磁盘路径

通过fdisk工具将各物理磁盘或分区的系统类型设为Linux LVM

[root@centos home]# fdisk /dev/vdb
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, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-419430399, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): 
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set

Command (m for help): t  
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition Linux to Linux LVM

Command (m for help): p

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0xf96ee173

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   419430399   209714176   8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.

将各物理磁盘或分区初始化为PV(physical volume,物理卷)

1、创建物理卷

[root@centos home]# pvcreate /dev/vdb1
WARNING: xfs signature detected on /dev/vdb1 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/vdb1.
  Physical volume "/dev/vdb1" successfully created.
#删除物理卷:例 pvremove /dev/sdb1

2、扫描当前系统上的所有物理卷

[root@centos home]# pvscan
  PV /dev/vdb1                      lvm2 [<200.00 GiB]
  Total: 1 [<200.00 GiB] / in use: 0 [0   ] / in no VG: 1 [<200.00 GiB]

创建VG(volume group,卷组)

创建centos组,并且将/dev/vdb1加入到组中

[root@centos home]# vgcreate centos /dev/vdb1
  Volume group "centos" successfully created

查看卷组属性

[root@centos home]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <200.00 GiB
  PE Size               4.00 MiB
  Total PE              51199
  Alloc PE / Size       0 / 0   
  Free  PE / Size       51199 / <200.00 GiB
  VG UUID               v6i653-rLEZ-3RLU-jGpm-ZDOe-UBmQ-wyluxb

通过增加物理卷实现扩展LVM卷组容量

[root@centos home]# vgextend centos /dev/vdb2

通过删除物理卷实现减少LVM卷组容量

[root@centos home]# vgreduce centos /dev/vdb2

删除LVM卷组,强制删除centos卷组,卷组中逻辑卷必须离线

[root@centos home]# vgremove -f centos

创建逻辑卷

lvcreate -L:指定大小 -n:指定名称 卷组

[root@centos home]# lvcreate -L 40G -n home centos
  Logical volume "home" created.
[root@centos home]# lvcreate -L 40G -n src centos
  Logical volume "src" created.
[root@centos home]# lvcreate -L 40G -n docker centos
  Logical volume "docker" created.

显示逻辑卷属性

[root@centos home]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                bXIM25-77dt-cxW6-5eyd-X7Vr-1zQU-2OIde3
  LV Write Access        read/write
  LV Creation host, time centos, 2021-08-24 15:27:58 +0800
  LV Status              available
  # open                 0
  LV Size                40.00 GiB
  Current LE             10240
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:0
   
  --- Logical volume ---
  LV Path                /dev/centos/src
  LV Name                src
  VG Name                centos
  LV UUID                2EnC7U-T78n-q8CM-IBBN-d1ZW-EfHa-s8D5Gk
  LV Write Access        read/write
  LV Creation host, time centos, 2021-08-24 15:29:52 +0800
  LV Status              available
  # open                 0
  LV Size                40.00 GiB
  Current LE             10240
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:1
   
  --- Logical volume ---
  LV Path                /dev/centos/docker
  LV Name                docker
  VG Name                centos
  LV UUID                LoddQz-yITi-0qP9-iGku-aexY-L5Dk-bK3PEf
  LV Write Access        read/write
  LV Creation host, time centos, 2021-08-24 15:30:14 +0800
  LV Status              available
  # open                 0
  LV Size                40.00 GiB
  Current LE             10240
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:2

扩展逻辑卷大小

[root@centos home]# lvextend -L +10G /dev/centos/home

缩小逻辑卷大小

[root@centos home]# lvreduce -L 10G /dev/centos/home

删除逻辑卷

[root@centos home]# lvremove -f /dev/centos/home

格式化逻辑卷

[root@centos home]# mke2fs -t ext4 /dev/centos/home
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485760 blocks
524288 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

显示格式化后的文件格式

[root@centos home]# lsblk -f
NAME              FSTYPE      LABEL UUID                                   MOUNTPOINT
vda                                                                        
├─vda1            swap              995a500d-eecf-4bc6-88cf-e700c15a2250   [SWAP]
└─vda2            ext4              950d2628-76ab-47b8-ac48-d349cb5d670c   /
vdb                                                                        
└─vdb1            LVM2_member       5S9ait-Qt4u-uDUu-SHnw-Yxfe-A5Lp-ZK9wNC 
  ├─centos-home   ext4              b458697a-72c0-40c0-95a5-e262ac1d21ac   
  ├─centos-src    ext4              42c172db-b0a0-460b-aac4-5f5b665a3640   
  └─centos-docker ext4              a8298a94-4f82-47d5-86fa-dc5a66b50a62   

挂载逻辑卷

#查询逻辑卷路径
[root@centos home]# fdisk -l
#挂载
[root@centos home]# mount /dev/mapper/centos-src /usr/local/src
[root@centos home]# mount /dev/mapper/centos-home /home

 

LVM扩展磁盘大小

上一篇:AWS(amazon ec2)服务器流量查询


下一篇:LeetCode-Minimum Window Substring-最小窗口子串-滑动窗口算法(尺取法)