安装完Ubuntu,有时候会出席硬盘有100G,但是LVM的虚拟磁盘只分配了19G的情况。
从图中可以看出硬盘大约还有80G的空间未使用,下面介绍如何扩容LVM虚拟磁盘。
1、# 将剩余硬盘空间添加到新分区
root@lixu:/home/lixu# fdisk /dev/sda Welcome to fdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. GPT PMBR size mismatch (41943039 != 209715199) will be corrected by write. Command (m for help): n #输入“n“创建新硬盘,剩下保持默认 Partition number (4-128, default 4): First sector (41940992-209715166, default 41940992): Last sector, +/-sectors or +/-size{K,M,G,T,P} (41940992-209715166, default 209715166): Created a new partition 4 of type 'Linux filesystem' and of size 80 GiB. Command (m for help): w #保存并退出 The partition table has been altered. Syncing disks.
2、#刷新下分区状态
root@lixu:
/home/lixu
# partprobe
3、# 扩展硬盘分区添加到VG
root@lixu:/home/lixu# vgextend /dev/ubuntu-vg /dev//sda4 Physical volume "/dev//sda4" successfully created. Volume group "ubuntu-vg" successfully extended
4、# 将VG剩余空间添加到LV
root@lixu:/home/lixu# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv Size of logical volume ubuntu-vg/ubuntu-lv changed from <19.00 GiB (4863 extents) to 98.99 GiB (25342 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.
5、# 刷新分区状态
root@lixu:/home/lixu# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv resize2fs 1.45.5 (07-Jan-2020) Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 13 The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 25950208 (4k) blocks long.
6、完成之后查看调整之后的分区状态
root@lixu:/home/lixu# fdisk -l Disk /dev/loop0: 54.98 MiB, 57626624 bytes, 112552 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: 71.28 MiB, 74735616 bytes, 145968 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/loop2: 29.9 MiB, 31334400 bytes, 61200 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: 100 GiB, 107374182400 bytes, 209715200 sectors Disk model: VMware Virtual S 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: 8DD9EF68-48C7-441A-81BD-40E0953D853B 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 /dev/sda4 41940992 209715166 167774175 80G Linux filesystem Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 98.102 GiB, 106292051968 bytes, 207601664 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
PS:以上是原文中实例的情况。我遇到的情况是118G硬盘在宝塔中能看到的只有58G。在第一步将剩余空间添加到新分区的时候,新建分区只有1007KB左右,所以无法扩容了。有明白这个分区的朋友可以帮我看一下这是为什么,附上我自己的分区信息。ps我的系统是Ubuntu server20.04,安装的时候选择的是使用整个磁盘进行LVM分区。
原文:https://www.ctoclubs.com/2020/09/25/19/46/15039/ubuntu-20-4-1lvm%E7%A9%BA%E9%97%B4%E6%89%A9%E5%AE%B9.html
留言评论
暂无留言