menu Chancel's blog
rss_feed
Chancel's blog
秋雨一何碧,山色倚晴空。

Linux LVM分区扩展分区大小

作者:Chancel Yang, 时间:2022 Apr 24, 阅读:73

检查磁盘大小时发现根分区仅有89G大小,物理硬盘是256G大小,于是检查一下fdisk,输出如下

➜  ~ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                                16G     0   16G   0% /dev
tmpfs                              3.2G  2.6M  3.2G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  109G   16G   89G  15% /
tmpfs                               16G     0   16G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                               16G     0   16G   0% /sys/fs/cgroup
/dev/sda2                          976M  149M  760M  17% /boot
/dev/sda1                          511M  4.4M  507M   1% /boot/efi
tmpfs                              3.2G     0  3.2G   0% /run/user/100


➜  ~ sudo fdisk -l
Disk /dev/sda: 223.6 GiB, 240057409536 bytes, 468862128 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: 5F5BD480-694D-4353-9287-71005184DC81

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   1050623   1048576   512M EFI System
/dev/sda2  1050624   3147775   2097152     1G Linux filesystem
/dev/sda3  3147776 468858879 465711104 222.1G Linux filesystem

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 111 GiB, 119223091200 bytes, 232857600 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

看到/dev/mapper分区才发现安装的时候勾选了LVM安装

使用LVM工具可以给这个逻辑卷 ubuntu--vg-ubuntu--lv 进行扩容

操作步骤

sudo lvm
    >> lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
    >> exit

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

实际操作

sudo lvm
lvm> lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv 
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <111.04 GiB (28425 extents) to <222.07 GiB (56849 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
lvm> exit
  Exiting.

➜  ~ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 14, new_desc_blocks = 28
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 58213376 (4k) blocks long.

➜  ~ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                                16G     0   16G   0% /dev
tmpfs                              3.2G  2.6M  3.2G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  219G   16G  193G   8% /
tmpfs                               16G     0   16G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                               16G     0   16G   0% /sys/fs/cgroup
/dev/sdb1                           15T   10T  3.8T  73% /mnt/a4752cae
/dev/sda2                          976M  149M  760M  17% /boot
/dev/sda1                          511M  4.4M  507M   1% /boot/efi
tmpfs                              3.2G     0  3.2G   0% /run/user/1000

[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]