VirtualBox 6.1 扩容VDI磁盘容量
确保对应的虚拟机已经关机!!!
Host的VirtualBox端
- 从工具栏管理->虚拟介质管理->虚拟硬盘,找到要修改的硬盘,从下面的大小滑动条修改磁盘大小
根据VirtualBox官网文档的描述,修改完这里之后,对应虚拟机中的容量修改还没生效,需要根据VM中的方式修改,但是官网没给出方式
VM中centos7(linux)的修改
找到你要扩容的物理分区,这里是/dev/sda为例,(文章中内容使用多次扩容结果作为说明,容量暂无法对齐,步骤正确)
- parted /dev/sda 修改物理分区的大小
通过parted工具的print 命令找到要扩容的disk编号,并用
resizepart 2 100%
命令进行扩容,然后查看是不是扩容成功
[root@localhost langchain-chat]# parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 32.2GB 31.1GB primary lvm
(parted) resizepart 2 100%
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 85.9GB 84.8GB primary lvm
(parted) quit
Information: You may need to update /etc/fstab.
- 通过lsblk和df命令可以看到,已经扩容到sda disk上了,但是还没有到PV卷上
[root@localhost langchain-chat]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 79G 0 part
├─centos-root 253:0 0 26G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
sr0 11:0 1 58.3M 0 rom /run/media/bpp/VBox_GAs_6.1.18
[root@localhost langchain-chat]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 9.5M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 26G 12G 15G 46% /
/dev/sda1 xfs 1014M 240M 775M 24% /boot
vmshare vboxsf 932G 202G 731G 22% /mnt/vfs
tmpfs tmpfs 783M 16K 783M 1% /run/user/1000
/dev/sr0 iso9660 59M 59M 0 100% /run/media/bpp/VBox_GAs_6.1.18
- 通过pvresize /dev/sda2对pv卷进行扩容
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <199.00 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 50943
Free PE 0
Allocated PE 50943
PV UUID RkxoQ9-akzt-nTQt-9IzR-P8Nl-WCTp-NLcGgW
[root@localhost ~]# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <299.00 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 76543
Free PE 25600
Allocated PE 50943
PV UUID RkxoQ9-akzt-nTQt-9IzR-P8Nl-WCTp-NLcGgW
[root@localhost ~]#
- 通过lvextend给lvm扩容,扩容后通过df命令可以看到根分区容量已经到我们需要的大小
[root@localhost ~]# lvextend -l +100%FREE --resizefs /dev/mapper/centos-root
Size of logical volume centos/root changed from <196.00 GiB (50175 extents) to <296.00 GiB (75775 extents).
Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=512 agcount=31, agsize=1703680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=51379200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3327, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 51379200 to 77593600
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 300G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 299G 0 part
├─centos-root 253:0 0 296G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
sr0 11:0 1 58.3M 0 rom /run/media/bpp/VBox_GAs_6.1.18
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 9.5M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 296G 59G 238G 20% /
/dev/sda1 xfs 1014M 240M 775M 24% /boot
vmshare vboxsf 932G 291G 642G 32% /mnt/vfs
tmpfs tmpfs 783M 16K 783M 1% /run/user/1000
/dev/sr0 iso9660 59M 59M 0 100% /run/media/bpp/VBox_GAs_6.1.18
[root@localhost ~]#