LVM逻辑卷扩容


发布于 2023-02-02 / 97 阅读 / 0 评论 /
LVM逻辑卷扩容

磁盘新建分区

fdisk /dev/sda
#列出磁盘分区信息
Command (m for help): p
Disk /dev/sda: 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: 0x000cebcb
​
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM
​
#新增一个分区
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 (104857600-419430399, default 104857600): 
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-419430399, default 419430399): 
Using default value 419430399
Partition 3 of type Linux and of size 150 GiB is set
​
#修改新分区类型为LVM
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
​
#列出磁盘分区信息
Command (m for help): p
Disk /dev/sda: 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: 0x000cebcb
​
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM
/dev/sda3       104857600   419430399   157286400   8e  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.

新分区格式磁盘

#重启服务器
reboot
​
#查看磁盘类型
lsblk -f
NAME         FSTYPE        LABEL UUID                              MOUNTPOINT
sda                                                                   
├─sda1       xfs           abeaa8a6-fe72-465e-933a-ddf666f8c7fb     /boot
├─sda2       LVM2_member   mu3gmi-QeYf-syh9-Untp-6xdV-z0Yx-YU6Wga 
│ ├─lvm-root xfs           26b139fd-e009-4a6e-9d1c-445aae31a7b6     /
│ └─lvm-swap swap          2c5f91d1-e28e-4a5d-8401-b3a41e50264c     [SWAP]
└─sda3       LVM2_member   1yp2XX-gNEf-fX2B-MnH2-0SRW-hUmz-vHNLkd 
​
#将新分区格式化为xfs格式
mkfs.xfs /dev/sda3

lvm逻辑卷扩容

#创建物理卷设备
pvcreate /dev/sda3
​
#查看逻辑卷组名称
vgdisplay
  --- Volume group ---
  VG Name               lvm
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               198.99 GiB
  PE Size               4.00 MiB
  Total PE              50942
  Alloc PE / Size       50942 / 198.99 GiB
  Free  PE / Size       0 / 0   
  VG UUID               HHM6ac-0L1y-dEUY-igpA-w6Rq-Jyzz-xq6RLg
​
#将物理卷拓展到lvm卷组
vgextend lvm /dev/sda3
​
#查看逻辑卷组相信信息(空间数量和挂载路径)
vgdisplay -v
  --- Volume group ---
  VG Name               lvm
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               198.99 GiB
  PE Size               4.00 MiB
  Total PE              50942
  Alloc PE / Size       12543 / <49.00 GiB
  Free  PE / Size       38399 / <150.00 GiB  #还剩空间PE数量
  VG UUID               HHM6ac-0L1y-dEUY-igpA-w6Rq-Jyzz-xq6RLg
    
  --- Logical volume ---
  LV Path                /dev/lvm/root  #挂载路径
  LV Name                root
  VG Name                lvm
  LV UUID                5piXf1-3bfw-02en-mF4v-2pZf-vOag-nMcQpk
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-05-02 07:40:31 +0800
  LV Status              available
  # open                 1
  LV Size                <45.00 GiB
  Current LE             11519
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
​
#逻辑卷拓展
lvextend /dev/lvm/root -rl +38399
​
#验证是否拓展
df -h
Filesystem            Size  Used Avail Use% Mounted on
devtmpfs              7.9G     0  7.9G   0% /dev
tmpfs                 7.9G     0  7.9G   0% /dev/shm
tmpfs                 7.9G   12M  7.9G   1% /run
tmpfs                 7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/mapper/lvm-root  195G  1.8G  194G   1% /
/dev/sda1            1014M  137M  878M  14% /boot
tmpfs                 1.6G     0  1.6G   0% /run/user/0




是否对你有帮助?

评论