ubuntu扩展逻辑卷大小 (安装系统时默认只使用一半)
前言
ubuntu系统安装时,一不留神,默认的磁盘空间只利用了一半,还有一半闲置了。 我们就得扩展利用这一半。或者虚拟机增加了虚拟磁盘的大小,也需要把卷再扩展一遍。
80G的硬盘,只用了39G
ckun@u20:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 91.9M 1 loop /snap/lxd/29619
loop1 7:1 0 61.9M 1 loop /snap/core20/1376
loop2 7:2 0 67.9M 1 loop /snap/lxd/22526
loop3 7:3 0 44.3M 1 loop /snap/snapd/23258
loop4 7:4 0 63.7M 1 loop /snap/core20/2434
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1.5G 0 part /boot
└─sda3 8:3 0 78.5G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 39.3G 0 lvm /
操作步骤
确认有Free PE
root@u20:~# vgdisplay ubuntu-vg
--- 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 <78.50 GiB
PE Size 4.00 MiB
Total PE 20095
Alloc PE / Size 10047 / <39.25 GiB
Free PE / Size 10048 / 39.25 GiB
VG UUID Xqmi6V-aHaO-NTGf-K2VN-Qfdv-zmod-LoXW4M
扩展逻辑卷
root@u20:~# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <39.25 GiB (10047 extents) to <78.50 GiB (20095 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@u20:~#
root@u20:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 91.9M 1 loop /snap/lxd/29619
loop1 7:1 0 61.9M 1 loop /snap/core20/1376
loop2 7:2 0 67.9M 1 loop /snap/lxd/22526
loop3 7:3 0 44.3M 1 loop /snap/snapd/23258
loop4 7:4 0 63.7M 1 loop /snap/core20/2434
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1.5G 0 part /boot
└─sda3 8:3 0 78.5G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 78.5G 0 lvm /
root@u20:~#
root@u20:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.1G 0 3.1G 0% /dev
tmpfs 642M 1.9M 640M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 39G 19G 18G 53% /
tmpfs 3.2G 0 3.2G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 3.2G 0 3.2G 0% /sys/fs/cgroup
/dev/loop4 64M 64M 0 100% /snap/core20/2434
/dev/loop0 92M 92M 0 100% /snap/lxd/29619
/dev/loop3 45M 45M 0 100% /snap/snapd/23258
/dev/loop2 68M 68M 0 100% /snap/lxd/22526
/dev/loop1 62M 62M 0 100% /snap/core20/1376
/dev/sda2 1.5G 116M 1.3G 9% /boot
tmpfs 642M 48K 642M 1% /run/user/1000
扩展文件系统
root@u20:~# resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 10
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 20577280 (4k) blocks long.
root@u20:~#
root@u20:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.1G 0 3.1G 0% /dev
tmpfs 642M 1.9M 640M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 78G 19G 55G 26% /
tmpfs 3.2G 0 3.2G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 3.2G 0 3.2G 0% /sys/fs/cgroup
/dev/loop4 64M 64M 0 100% /snap/core20/2434
/dev/loop0 92M 92M 0 100% /snap/lxd/29619
/dev/loop3 45M 45M 0 100% /snap/snapd/23258
/dev/loop2 68M 68M 0 100% /snap/lxd/22526
/dev/loop1 62M 62M 0 100% /snap/core20/1376
/dev/sda2 1.5G 116M 1.3G 9% /boot
tmpfs 642M 48K 642M 1% /run/user/1000