Linux LVM 磁盘扩容

操作步骤如下:

查看挂载点        
root@ubuntu:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               706M     0  706M   0% /dev
tmpfs                              148M  1.4M  147M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   19G  8.0G  9.7G  46% /
tmpfs                              739M     0  739M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              739M     0  739M   0% /sys/fs/cgroup
/dev/loop0                         117M  117M     0 100% /snap/core/14946
/dev/loop1                         106M  106M     0 100% /snap/core/16202
/dev/sda2                          974M  228M  679M  26% /boot
overlay                             19G  8.0G  9.7G  46% /var/lib/docker/overlay2/652c9e13376c13dc87f8dbdc821f3e62da91f4ee9283a8af461ade3fd0e00c1a/merged
tmpfs   
查看显示当前的逻辑卷 logical volume:lvdisplay
root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                NcV8GQ-KOeB-NClt-eV3y-VdDp-tbvK-hHXJz4
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2022-04-03 04:07:41 +0000
  LV Status              available
  # open                 1
  LV Size                <19.00 GiB
  Current LE             4863
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
查看显示当前的 volume group 卷组
root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                NcV8GQ-KOeB-NClt-eV3y-VdDp-tbvK-hHXJz4
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2022-04-03 04:07:41 +0000
  LV Status              available
  # open                 1
  LV Size                <19.00 GiB
  Current LE             4863
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
查看显示当前的 physical volume 物理卷
root@ubuntu:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <19.00 GiB / not usable 0   
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               fcIoyX-hV3P-kSSf-QjlO-ZC2e-3iIg-5oGO2z

开始扩容

查看 fdisk
root@ubuntu:~# fdisk -l
Disk /dev/loop0: 116.8 MiB, 122433536 bytes, 239128 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/loop1: 105.8 MiB, 110960640 bytes, 216720 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/sda: 20 GiB, 21474836480 bytes, 41943040 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: gpt
Disk identifier: 0E37800A-E3A9-4E56-8107-FC4DAD87ACCC

Device       Start      End  Sectors Size Type
/dev/sda1     2048     4095     2048   1M BIOS boot
/dev/sda2     4096  2101247  2097152   1G Linux filesystem
/dev/sda3  2101248 41940991 39839744  19G Linux filesystem


Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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/ubuntu--vg-ubuntu--lv: 19 GiB, 20396900352 bytes, 39837696 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@ubuntu:~# fdisk -l |grep '/dev'
Disk /dev/loop0: 116.8 MiB, 122433536 bytes, 239128 sectors
Disk /dev/loop1: 105.8 MiB, 110960640 bytes, 216720 sectors
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
/dev/sda1     2048     4095     2048   1M BIOS boot
/dev/sda2     4096  2101247  2097152   1G Linux filesystem
/dev/sda3  2101248 41940991 39839744  19G Linux filesystem
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 19 GiB, 20396900352 bytes, 39837696 sectors
创建 sdb 分区 ;其中 n :表示 new 新建分区;l: 选择逻辑分区,如果没有,则首先创建 (p) 主分区 ;w :写入磁盘
root@ubuntu:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.31.1).
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.
Created a new DOS disklabel with disk identifier 0x03f8ca09.

Command (m for help): 


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

Created a new partition 1 of type 'Linux' and of size 20 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
格式化磁盘
root@ubuntu:~# mkfs -t ext4 /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 987d40a1-5e64-4e9e-afa1-b77d7960b2c4
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

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

创建 PV 

root@ubuntu:~# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

查看卷组

root@ubuntu:~# pvscan
  PV /dev/sda3   VG ubuntu-vg       lvm2 [<19.00 GiB / 0    free]
  PV /dev/sdb1                      lvm2 [<20.00 GiB]
  Total: 2 [<39.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 1 [<20.00 GiB]

扩容 VG 

查看 VG 
root@ubuntu:~# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               BcexQ8-11N1-2huf-qoSE-YzXY-NYvb-LJxO2n
扩容 VG
root@ubuntu:~# vgextend ubuntu-vg /dev/sdb1
  Volume group "ubuntu-vg" successfully extended

扩容 LV

查看 VG 同上
root@ubuntu:~# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               38.99 GiB
  PE Size               4.00 MiB
  Total PE              9982
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               BcexQ8-11N1-2huf-qoSE-YzXY-NYvb-LJxO2n
查看 LV 逻辑卷
root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                NcV8GQ-KOeB-NClt-eV3y-VdDp-tbvK-hHXJz4
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2022-04-03 04:07:41 +0000
  LV Status              available
  # open                 1
  LV Size                <19.00 GiB
  Current LE             4863
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256

扩容 LV 按固定大小追加;注意:路径为查看到的 LV 逻辑卷(LV Path   /dev/ubuntu-vg/ubuntu-lv)

root@ubuntu:~# lvextend -L +10G /dev/ubuntu-vg/ubuntu-lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <19.00 GiB (4863 extents) to <29.00 GiB (7423 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
扩容 LV 按百分比大小追加
root@ubuntu:~# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <29.00 GiB (7423 extents) to 38.99 GiB (9982 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
刷新分区
root@ubuntu:~# resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 7601152 (4k) blocks long.
查看系统磁盘空间使用情况
root@ubuntu:~# df -h 
Filesystem                         Size  Used Avail Use% Mounted on
udev                               706M     0  706M   0% /dev
tmpfs                              148M  1.4M  147M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   29G  8.0G   20G  30% /
tmpfs                              739M     0  739M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              739M     0  739M   0% /sys/fs/cgroup
/dev/loop0                         117M  117M     0 100% /snap/core/14946
/dev/loop1                         106M  106M     0 100% /snap/core/16202
/dev/sda2                          974M  228M  679M  26% /boot
overlay                             29G  8.0G   20G  30% /var/lib/docker/overlay2/652c9e13376c13dc87f8dbdc821f3e62da91f4ee9283a8af461ade3fd0e00c1a/merged
tmpfs                              148M     0  148M   0% /run/user/0
验证是否成功
root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                NcV8GQ-KOeB-NClt-eV3y-VdDp-tbvK-hHXJz4
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2022-04-03 04:07:41 +0000
  LV Status              available
  # open                 1
  LV Size                38.99 GiB
  Current LE             9982
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值