vmware中ubuntu虚拟机扩容
-
Vmware添加磁盘空间

WX20231123-143534@2x.png
-
查看需要挂载的硬盘
[root@elk2 ~]# fdisk -l GPT PMBR size mismatch (41943039 != 52428799) will be corrected by write. Disk /dev/nvme0n1: 25 GiB, 26843545600 bytes, 52428800 sectors Disk model: VMware Virtual NVMe Disk 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: 66881C31-AF40-44F7-B83D-E31E1C2D3919 Device Start End Sectors Size Type /dev/nvme0n1p1 2048 1953791 1951744 953M EFI System /dev/nvme0n1p2 1953792 5668863 3715072 1.8G Linux filesystem /dev/nvme0n1p3 5668864 41940991 36272128 17.3G Linux filesystem Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 17 GiB, 18253611008 bytes, 35651584 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 -
可以看到增加的5G磁盘还未分区
[root@elk2 ~]# fdisk /dev/nvme0n1 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. Command (m for help): n Partition number (4-128, default 4): First sector (41940992-52428766, default 41940992): Last sector, +/-sectors or +/-size{K,M,G,T,P} (41940992-52428766, default 52428766): Created a new partition 4 of type 'Linux filesystem' and of size 5 GiB. Command (m for help): wq The partition table has been altered. Syncing disks -
查看磁盘分区情况
[root@elk2 ~]# fdisk -l Disk /dev/nvme0n1: 25 GiB, 26843545600 bytes, 52428800 sectors Disk model: VMware Virtual NVMe Disk 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: 66881C31-AF40-44F7-B83D-E31E1C2D3919 Device Start End Sectors Size Type /dev/nvme0n1p1 2048 1953791 1951744 953M EFI System /dev/nvme0n1p2 1953792 5668863 3715072 1.8G Linux filesystem /dev/nvme0n1p3 5668864 41940991 36272128 17.3G Linux filesystem /dev/nvme0n1p4 41940992 52428766 10487775 5G Linux filesystem Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 17 GiB, 18253611008 bytes, 35651584 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 -
查看LVM(Logical Volume Manager,逻辑卷管理器)中逻辑卷(Logical Volumes)的信息
[root@elk2 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ubuntu-lv ubuntu-vg -wi-ao---- 17.00g -
向LVM的卷组添加物理卷
[root@elk2 ~]# vgextend ubuntu-vg /dev/nvme0n1p4 Physical volume "/dev/nvme0n1p4" successfully created. Volume group "ubuntu-vg" successfully extended -
扩展逻辑卷
[root@elk2 ~]# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv /dev/nvme0n1p4 Size of logical volume ubuntu-vg/ubuntu-lv changed from 17.00 GiB (4352 extents) to <22.00 GiB (5631 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized. -
刷新逻辑卷
[root@elk2 ~]# 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 = 3 The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 5766144 (4k) blocks long. -
查看磁盘使用情况
[root@elk2 ~]# df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 392M 1.3M 391M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 22G 8.9G 12G 43% / tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/nvme0n1p2 1.8G 206M 1.5G 13% /boot /dev/loop0 60M 60M 0 100% /snap/core20/1627 /dev/nvme0n1p1 952M 6.0M 946M 1% /boot/efi /dev/loop1 62M 62M 0 100% /snap/lxd/22761 /dev/loop2 92M 92M 0 100% /snap/lxd/24065 /dev/loop3 36M 36M 0 100% /snap/snapd/20298 /dev/loop5 60M 60M 0 100% /snap/core20/2019 /dev/loop4 47M 47M 0 100% /snap/snapd/19459 tmpfs 392M 0 392M 0% /run/user/0