参考:
https://www.cnblogs.com/zendwang/p/6560737.html
https://www.cnblogs.com/xueweihan/p/5923937.html
我这边执行的操作:
-
关机查看虚拟硬盘分配方式,我的为动态,故后续参考为动态分配:
-
卸载vdi:
-
虚拟机备份(名称不同),直接使用windows的右击复制功能备份即可;
-
使用everything 搜索vboxmanage ,打开路径:C:\Program Files\Oracle\VirtualBox(virtualbox 安装路径不同,vboxmanage 的位置可能不同),直接在路径栏cmd,进入命令行窗口。
-
命令行窗口执行:vboxmanage modifyhd /location-of-your-virtual-disk --resize size-in-MB,例如: vboxmanage modifyhd F:\virtualbox\ubuntu\qemu\qemu.vdi --resize 716800 扩容到70G;使用vboxmanage list hdds 查看是hdd 容量
-
然后再重新添加vdi , 可以看到硬盘空间已经变化了,启动虚拟机。
-
虚拟机内部进行配置:
a. df -h 发现磁盘空间并未变化:
b. fdisk /dev/sda 后执行如下, :
[root@10 ~]# df -l
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 924068 0 924068 0% /dev
tmpfs 940964 0 940964 0% /dev/shm
tmpfs 940964 9188 931776 1% /run
tmpfs 940964 0 940964 0% /sys/fs/cgroup
/dev/mapper/centos-root 39827456 34050928 5776528 86% / --扩容并未真正加载
/dev/sda1 1038336 171324 867012 17% /boot
tmpfs 188196 0 188196 0% /run/user/0
[root@10 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
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 type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
Selected partition 4
First sector (83886080-146800639, default 83886080):
Using default value 83886080
Last sector, +sectors or +size{K,M,G} (83886080-146800639, default 146800639):
Using default value 146800639
Partition 4 of type Linux and of size 30 GiB is set
Command (m for help): t
Partition number (1-4, default 4):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 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
Disk label type: dos
Disk identifier: 0x000ed93d
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
/dev/sda3 20971520 83886079 31457280 8e Linux LVM
/dev/sda4 83886080 146800639 31457280 8e Linux LVM
Disk /dev/mapper/centos-root: 40.8 GB, 40793800704 bytes, 79675392 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
Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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
[root@10 ~]# vgdisplay
--- Volume group ---
VG Name centos ----后续会需要
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 38.99 GiB
PE Size 4.00 MiB
Total PE 9982
Alloc PE / Size 9982 / 38.99 GiB
Free PE / Size 0 / 0
VG UUID hB2N4k-ag7k-Fx5y-dpls-qrPq-Yopd-hiB8aw
[root@10 ~]# lvscan
ACTIVE '/dev/centos/swap' [1.00 GiB] inherit
ACTIVE '/dev/centos/root' [37.99 GiB] inherit --后续会需要
[root@10 ~]# pvcreate /dev/sda4
Device /dev/sda4 not found. ---需重启生效
[root@10 ~]# reboot
在这里插入代码片
重启后继续执行
Physical volume "/dev/sda4" successfully created.
[root@10 ~]# vgextend centos /dev/sda4
Volume group "centos" successfully extended
[root@10 ~]# lvextend /dev/centos/root /dev/sda4
Size of logical volume centos/root changed from 37.99 GiB (9726 extents) to <67.99 GiB (17405 extents).
Logical volume centos/root successfully resized.
[root@10 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=20, agsize=524032 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9959424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9959424 to 17822720
[root@10 ~]# lvscan
ACTIVE '/dev/centos/swap' [1.00 GiB] inherit
ACTIVE '/dev/centos/root' [<67.99 GiB] inherit
[root@10 ~]#
可能遇见问题:
- 执行vgextend 时出现 couldn’t create temporary achieve name 。原因: 扩容VG无足够空间供建档使用,故扩容失败
解决: 清理出300M的空间即可(删除非必须文件夹),可用du -sh * 查看某目录下文件夹空间大小 - 执行resize2fs时出现:resize2fs: Bad magic number in super-block while trying to open,
可能原因: 前使用df -T确定文件系统格式,xfs 需使用xfs_growfs /dev/XXX/root.