PVE中虚拟机硬盘在线扩容(LVM格式)- 单硬盘扩容
Overview
[TOC]
PVE下单磁盘扩容
上篇文章,我们讨论了在PvE下通过新增硬盘的方式进行扩容的方法
这篇文章,我们简单讲讲PvE下通过单盘扩容的方式进行扩容的方法
当前,两者的前提都是基于LVM格式下进行扩容。
案例
查看现状(/dev/sda)
我有一个debian虚拟机,一开始只给了它10G的虚拟化硬盘:
1$ sudo lsblk
2NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3sda 8:0 0 30G 0 disk
4├─sda1 8:1 0 487M 0 part /boot
5├─sda2 8:2 0 1K 0 part
6└─sda5 8:5 0 29.5G 0 part
7 ├─debian--vg-root 254:0 0 28.6G 0 lvm /
8 └─debian--vg-swap_1 254:1 0 980M 0 lvm [SWAP]
9sr0 11:0 1 1024M 0 rom
sda就是30G的盘,被分成了3个分区:sda1、sd2、sda5
sda1是引导分区,sda2不知道是什么作用,sda5是一个LVM类型的分区,我们详细分析一下这个分区:
1$ df -h
2Filesystem Size Used Avail Use% Mounted on
3udev 2.0G 0 2.0G 0% /dev
4tmpfs 395M 16M 379M 5% /run
5/dev/mapper/debian--vg-root 28G 3.7G 23G 14% /
6tmpfs 2.0G 0 2.0G 0% /dev/shm
7tmpfs 5.0M 0 5.0M 0% /run/lock
8tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
9/dev/sda1 470M 83M 363M 19% /boot
可见,root那个LV被挂载到了/根目录,所以整个操作系统都在占用这个LV的空间,后续我们一旦发现硬盘耗尽,就需要对这个LV进行原地扩容即可。
扩容增加10G(/dev/sda)
进入PVE web控制台,增加10G,/dev/sda总容量增加至40G
1$ sudo fdisk -l
2Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
3Disk model: QEMU HARDDISK
4Units: sectors of 1 * 512 = 512 bytes
5Sector size (logical/physical): 512 bytes / 512 bytes
6I/O size (minimum/optimal): 512 bytes / 512 bytes
7Disklabel type: dos
8Disk identifier: 0x987f6503
9
10Device Boot Start End Sectors Size Id Type
11/dev/sda1 * 2048 999423 997376 487M 83 Linux
12/dev/sda2 1001470 62912511 61911042 29.5G 5 Extended
13/dev/sda5 1001472 62912511 61911040 29.5G 8e Linux LVM
14
15
16Disk /dev/mapper/debian--vg-root: 28.6 GiB, 30668750848 bytes, 59899904 sectors
17Units: sectors of 1 * 512 = 512 bytes
18Sector size (logical/physical): 512 bytes / 512 bytes
19I/O size (minimum/optimal): 512 bytes / 512 bytes
20
21
22Disk /dev/mapper/debian--vg-swap_1: 980 MiB, 1027604480 bytes, 2007040 sectors
23Units: sectors of 1 * 512 = 512 bytes
24Sector size (logical/physical): 512 bytes / 512 bytes
25I/O size (minimum/optimal): 512 bytes / 512 bytes
使用part进行扩容
1$ sudo parted /dev/sda
2
3GNU Parted 3.2
4Using /dev/sda
5Welcome to GNU Parted! Type 'help' to view a list of commands.
6(parted) print
7Number Start End Size Type File system Flags
8 1 1049kB 512MB 511MB primary ext2 boot
9 2 513MB 31.2GB 31.7GB extended
10 5 513MB 32.2GB 31.7GB logical lvm
11
12(parted) resizepart 2 100%
13(parted) resizepart 5 100%
14(parted) quit
15
16Information: You may need to update /etc/fstab.
至此,磁盘扩容完毕!
可以重新查看硬盘分区与容量情况
1$ sudo fdisk -l
2Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
3Disk model: QEMU HARDDISK
4Units: sectors of 1 * 512 = 512 bytes
5Sector size (logical/physical): 512 bytes / 512 bytes
6I/O size (minimum/optimal): 512 bytes / 512 bytes
7Disklabel type: dos
8Disk identifier: 0x987f6503
9
10Device Boot Start End Sectors Size Id Type
11/dev/sda1 * 2048 999423 997376 487M 83 Linux
12/dev/sda2 1001470 83886079 82884610 39.5G 5 Extended
13/dev/sda5 1001472 83886079 82884608 39.5G 8e Linux LVM
14
15
16Disk /dev/mapper/debian--vg-root: 28.6 GiB, 30668750848 bytes, 59899904 sectors
17Units: sectors of 1 * 512 = 512 bytes
18Sector size (logical/physical): 512 bytes / 512 bytes
19I/O size (minimum/optimal): 512 bytes / 512 bytes
20
21
22Disk /dev/mapper/debian--vg-swap_1: 980 MiB, 1027604480 bytes, 2007040 sectors
23Units: sectors of 1 * 512 = 512 bytes
24Sector size (logical/physical): 512 bytes / 512 bytes
25I/O size (minimum/optimal): 512 bytes / 512 bytes
/dev/sda2,/dev/sda5均已扩容到40G
后续讲讲zfs硬盘如何被多个虚拟机挂载使用