Promox VE (PVE) 调整虚拟机 (VM) 的磁盘大小

1.在PVE中选中硬盘,点击磁盘操作。

2.点击调整大小。注意:只能扩充磁盘无法缩小磁盘。

3.给分区增加空间。

root@infski:~# fdisk -l
Disk /dev/sda: 648 GiB, 695784701952 bytes, 1358954496 sectors
Disk model: QEMU HARDDISK   
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: dos
Disk identifier: 0x1581124e

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1  *     2048 629143551 629141504  300G 83 Linux

可以看到目前我的/dev/sda1只有300G,而分配的硬盘有648G。我需要给/dev/sda1扩充大小。

parted /dev/sda
root@infski:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)    

输入print,输出分区。

root@infski:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 696GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  322GB  322GB  primary  ext4         boot

(parted)       

输入resizepart 1调整1号分区,如果需要调整2号分区就输入resizepart 2。我这里只有1个分区。

root@infski:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 696GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  322GB  322GB  primary  ext4         boot

(parted) resizepart 1                                                     
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? yes   

因为我只有一个分区,而且这个分区再被使用,会提示Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No?
输入yes即可。

root@infski:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 696GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  322GB  322GB  primary  ext4         boot

(parted) resizepart 1                                                     
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? yes                                                               
End?  [322GB]?    

我需要分配所有的空间,所以我这输入100%。

root@infski:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 696GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  322GB  322GB  primary  ext4         boot

(parted) resizepart 1                                                     
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? yes                                                               
End?  [322GB]? 100%                                                       
(parted)         

输入quit退出。

root@infski:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 696GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  322GB  322GB  primary  ext4         boot

(parted) resizepart 1                                                     
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? yes                                                               
End?  [322GB]? 100%                                                       
(parted) quit                                                             
Information: You may need to update /etc/fstab.

然后需要重新计算大小。

resize2fs /dev/sda1
root@infski:~# resize2fs /dev/sda1                                        
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 38, new_desc_blocks = 81
The filesystem on /dev/sda1 is now 169869056 (4k) blocks long.

root@zinoin:~# fdisk -l
Disk /dev/sda: 648 GiB, 695784701952 bytes, 1358954496 sectors
Disk model: QEMU HARDDISK   
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: dos
Disk identifier: 0x1581124e

Device     Boot Start        End    Sectors  Size Id Type
/dev/sda1  *     2048 1358954495 1358952448  648G 83 Linux

这样硬盘扩容就完成了。