扩容带有LVM的Linux分区

date
slug
lvm-extend
status
Published
tags
Linux
summary
如何扩容LVM下的Linux分区
type
Post
  1. 拓展物理卷大小:
    1. 这里使用的是 Pve,仅需在 Pve 中编辑磁盘大小即可
      notion image
  1. 使用 parted 工具修改对应卷大小
    1. $ sudo parted # 进入 parted 工具
      
      GNU Parted 3.4
      Using /dev/sda
      Welcome to GNU Parted! Type 'help' to view a list of commands.
      
      $ print /dev/sda # 查看分区情况
      
      Model: QEMU QEMU HARDDISK (scsi)
      Disk /dev/sda: 137GB
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:
      
      Number  Start   End     Size    File system  Name  Flags
       1      1049kB  2097kB  1049kB                     bios_grub
       2      2097kB  2150MB  2147MB  ext4
       3      2150MB  68.7GB  66.6GB
      我们要扩容的是 3 号分区,所以我们键入
      $ resizepart 3
      End?  [68.7GB]? 137G # 我这里选择扩容剩下所有空间,输入 137G
      $ quit # 退出 parted
      此时在 fdisk 中即可看到分区容量已经变为 125.6G
      $ sudo fdisk -l
      
      Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
      Disk model: QEMU HARDDISK
      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: E399CBE4-C05A-4065-AF2A-2B043574B43D
      
      Device       Start       End   Sectors   Size Type
      /dev/sda1     2048      4095      2048     1M BIOS boot
      /dev/sda2     4096   4198399   4194304     2G Linux filesystem
      /dev/sda3  4198400 267578125 263379726 125.6G Linux filesystem
  1. 在 lvm 中拓展 Logical volume
    1. $ sudo lvdisplay
        --- Logical volume ---
        LV Path                /dev/ubuntu-vg/ubuntu-lv
        LV Name                ubuntu-lv
        VG Name                ubuntu-vg
        LV UUID                VJLtpc-Y2BH-2R9P-uxoC-f0Gg-yn7d-E4jKeC
        LV Write Access        read/write
        LV Creation host, time ubuntu-server, 2023-06-05 08:15:51 +0000
        LV Status              available
        # open                 1
        LV Size                <31.00 GiB
        Current LE             7935
        Segments               1
        Allocation             inherit
        Read ahead sectors     auto
        - currently set to     256
        Block device           253:0
      查看 lv 信息,可以看到 lv path
      $ sudo lvresize -l +100%FREE ubuntu-vg/ubuntu-lv # 将 ubuntu-vg/ubuntu-lv 扩容到剩下的所有空间
      	Size of logical volume ubuntu-vg/ubuntu-lv changed from <31.00 GiB (7935 extents) to <125.59 GiB (32150 extents).
        Logical volume ubuntu-vg/ubuntu-lv successfully resized.
  1. 使用 resize2fs 调整分区大小
    1. sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
      resize2fs 1.46.5 (30-Dec-2021)
      Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
      old_desc_blocks = 4, new_desc_blocks = 16
      The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 32921600 (4k) blocks long.
      此时 df -h 可以看到分区大小已增大
      $ df -h
      Filesystem                         Size  Used Avail Use% Mounted on
      tmpfs                              1.2G  1.2M  1.2G   1% /run
      /dev/mapper/ubuntu--vg-ubuntu--lv  124G   27G   92G  23% /
      tmpfs                              5.9G     0  5.9G   0% /dev/shm
      tmpfs                              5.0M     0  5.0M   0% /run/lock
      /dev/sda2                          2.0G  252M  1.6G  14% /boot
      tmpfs                              1.2G   16K  1.2G   1% /run/user/1000

© AlotOfBlahaj 2022 - 2025