virtual
参考:blogs./zendwang/p/6560737.html blogs./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 -lFilesystem 1K-blocks Used Available Use% Mounted ondevtmpfs 924068 0 924068 0% /devtmpfs 940964 0 940964 0% /dev/shmtmpfs 940964 9188 931776 1% /runtmpfs 940964 0 940964 0% /sys/fs/cgroup/dev/mapper/centos-root 39827456 34050928 5776528 86% / --扩容并未真正加载/dev/sda1 1038336 171324 867012 17% /boottmpfs 188196 0 188196 0% /run/user/0[root@10 ~]# fdisk /dev/sda Wele 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 mand.Command (m for help): nPartition type:p primary (3 primary, 0 extended, 1 free)e extendedSelect (default e): pSelected partition 4First sector (83886080-146800639, default 83886080): Using default value 83886080Last sector, +sectors or +size{K,M,G} (83886080-146800639, default 146800639): Using default value 146800639Partition 4 of type Linux and of size 30 GiB is setCommand (m for help): tPartition number (1-4, default 4): Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'Command (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000ed93dDevice 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 LVMDisk /dev/mapper/centos-root: 40.8 GB, 40793800704 bytes, 79675392 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes[root@10 ~]# vgdisplay --- Volume group ---VG Name centos----后续会需要System ID Format lvm2Metadata Areas 2Metadata Sequence No 5VG Aess read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 2Act PV 2VG Size 38.99 GiBPE Size 4.00 MiBTotal PE 9982Alloc PE / Size 9982 / 38.99 GiBFree PE / Size 0 / 0 VG UUID hB2N4k-ag7k-Fx5y-dpls-qrPq-Yopd-hiB8aw[root@10 ~]# lvscan ACTIVE '/dev/centos/swap' [1.00 GiB] inheritACTIVE '/dev/centos/root' [37.99 GiB] inherit --后续会需要[root@10 ~]# pvcreate /dev/sda4Device /dev/sda4 not found. ---需重启生效[root@10 ~]# reboot在这里插入代码片重启后继续执行
Physical volume "/dev/sda4" suessfully created.[root@10 ~]# vgextend centos /dev/sda4Volume group "centos" suessfully extended[root@10 ~]# lvextend /dev/centos/root /dev/sda4Size of logical volume centos/root changed from 37.99 GiB (9726 extents) to <67.99 GiB (17405 extents).Logical volume centos/root suessfully 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=0data = bsize=4096 blocks=9959424, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 9959424 to 17822720[root@10 ~]# lvscan ACTIVE '/dev/centos/swap' [1.00 GiB] inheritACTIVE '/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.virtual