1、虚拟机关机通过管理界面给磁盘扩容。
root@curtis:/home/curtis/git_code# pvdisplay
--- Physical volume ---
PV Name /dev/vda3
VG Name ubuntu-vg
PV Size <239.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 61183
Free PE 0
Allocated PE 61183
PV UUID WoCzb3-a3jy-yV23-gOau-UeiA-K62x-petsV2
2、虚拟机启动之后查看磁盘容量,并且使用gparted更新分区表。
root@curtis:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 512G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 239G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 239G 0 lvm /
root@curtis:~# parted /dev/vda
GNU Parted 3.2
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 570425344 blocks) or continue with
the current setting?
Fix/Ignore? Fix
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 550GB
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 1076MB 1074MB ext4
3 1076MB 258GB 257GB
3、cfdisk给磁盘扩容,选择到需要扩容的分区之后,选择resize,然后把所有剩余可用磁盘容量分配给目标分区。
4、使用pvresize命令给物理卷扩容,扩容完成之后可以看到卷组空闲容量增加,因为对应物理卷属于VG。
root@curtis:~# pvresize /dev/vda3
Physical volume "/dev/vda3" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
root@curtis:~# pvdisplay
--- Physical volume ---
PV Name /dev/vda3
VG Name ubuntu-vg
PV Size <511.00 GiB / not usable 16.50 KiB
Allocatable yes
PE Size 4.00 MiB
Total PE 130815
Free PE 69632
Allocated PE 61183
PV UUID WoCzb3-a3jy-yV23-gOau-UeiA-K62x-petsV2
root@curtis:~# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 8
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 <511.00 GiB
PE Size 4.00 MiB
Total PE 130815
Alloc PE / Size 61183 / <239.00 GiB
Free PE / Size 69632 / 272.00 GiB # 卷组剩余可用磁盘
VG UUID za8fRc-LJLO-RZnk-rgC7-RWzi-EdFP-b3CL94
5、将卷组全部可用的磁盘容量分配给逻辑卷。
root@curtis:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 1.1M 1.6G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 235G 202G 23G 90% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/vda2 974M 171M 736M 19% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
overlay 235G 202G 23G 90% /var/lib/docker/overlay2/87855dc438df45c79803a622f203e2d018c199462d41427c35a30a7b24fd8327/merged
overlay 235G 202G 23G 90% /var/lib/docker/overlay2/077eda580493c22cc08d5e7ab562d792498872291914e12040b35a54e52f1fde/merged
overlay 235G 202G 23G 90% /var/lib/docker/overlay2/519095e6c98bb655d0a74390704dd2091b4f3274dc9de284a085cb6b6bb8a8f4/merged
root@curtis:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv # 可以根据自己的需求分配空间
Size of logical volume ubuntu-vg/ubuntu-lv changed from <239.00 GiB (61183 extents) to <511.00 GiB (130815 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@curtis:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 1.1M 1.6G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 235G 202G 23G 90% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/vda2 974M 171M 736M 19% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
overlay 235G 202G 23G 90% /var/lib/docker/overlay2/87855dc438df45c79803a622f203e2d018c199462d41427c35a30a7b24fd8327/merged
overlay 235G 202G 23G 90% /var/lib/docker/overlay2/077eda580493c22cc08d5e7ab562d792498872291914e12040b35a54e52f1fde/merged
overlay 235G 202G 23G 90% /var/lib/docker/overlay2/519095e6c98bb655d0a74390704dd2091b4f3274dc9de284a085cb6b6bb8a8f4/merged
root@curtis:~# 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 = 30, new_desc_blocks = 64
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 133954560 (4k) blocks long.
root@curtis:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 1.1M 1.6G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 503G 202G 280G 42% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/vda2 974M 171M 736M 19% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
overlay 503G 202G 280G 42% /var/lib/docker/overlay2/87855dc438df45c79803a622f203e2d018c199462d41427c35a30a7b24fd8327/merged
overlay 503G 202G 280G 42% /var/lib/docker/overlay2/077eda580493c22cc08d5e7ab562d792498872291914e12040b35a54e52f1fde/merged
overlay 503G 202G 280G 42% /var/lib/docker/overlay2/519095e6c98bb655d0a74390704dd2091b4f3274dc9de284a085cb6b6bb8a8f4/merged
参考文档:https://packetpushers.net/blog/ubuntu-extend-your-default-lvm-space/