虚拟机磁盘空间不够,可以新添加磁盘,同时也可以采用磁盘扩容的方式。
关闭虚拟机,打开虚拟机设置,找到需要扩展的磁盘,选择“扩展”按钮。如果扩展按钮成灰色,则说明虚拟机之前存在快照,需要将快照删除。
在扩展过程中,可能会出现报错,错误信息“在部分链上无法执行所调用的函数,请打开父虚拟磁盘”。网上对此众多纷纭,因为我目前对此处了解的也不够深入,所以说不出准确的原因,但是实验过程中,总结出来通过克隆当前虚拟机,能够解决此问题。
通过对当前虚拟机进行完全克隆后,当前虚拟机或克隆后的虚拟机都可以顺利进行扩展了。
扩展空间时,磁盘空间不要写太大,这个操作是不可逆的,磁盘空间只能增加,不能减少,所以需要慎重填写。
打开虚拟机,再进行分区和格式化。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 46.2 GB, 46170898432 bytes, 90177536 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: 0x000b0983
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sda3 10487808 83886079 36699136 83 Linux
使用fdisk命令进行磁盘分区。此时创建的分区是在扩展分区里(2G),磁盘大小设置的1G。因为此时的分区是在原有磁盘的基础上进行的,所以完成后需要重启,或执行partprobe命令立即读取最新的分区表。
[root@localhost ~]# 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):
Using default response e
Selected partition 4
First sector (83886080-90177535, default 83886080):
Using default value 83886080
Last sector, +sectors or +size{K,M,G} (83886080-90177535, default 90177535): +2G
Partition 4 of type Extended and of size 2 GiB is set
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (83888128-88080383, default 83888128):
Using default value 83888128
Last sector, +sectors or +size{K,M,G} (83888128-88080383, default 88080383): +1G
Partition 5 of type Linux and of size 1 GiB is set
Command (m for help): p
Disk /dev/sda: 46.2 GB, 46170898432 bytes, 90177536 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: 0x000b0983
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sda3 10487808 83886079 36699136 83 Linux
/dev/sda4 83886080 88080383 2097152 5 Extended
/dev/sda5 83888128 85985279 1048576 83 Linux
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.
[root@localhost ~]# partprobe /dev/sda
[root@localhost ~]# fdisk -l
Disk /dev/sda: 46.2 GB, 46170898432 bytes, 90177536 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: 0x000b0983
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sda3 10487808 83886079 36699136 83 Linux
/dev/sda4 83886080 88080383 2097152 5 Extended
/dev/sda5 83888128 85985279 1048576 83 Linux
对分区进行格式化,将分区格式化为xfs类型。
[root@localhost ~]# mkfs.xfs /dev/sda5
meta-data=/dev/sda5 isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
然后对/dev/sda5进行挂载,即可使用。