CentOS上,VirtualBox初次启动虚拟机时失败,及在虚拟机内安装增强工具的问题
CentOS 安装VirtualBox启动虚拟机时遇到错误
在CentOS上安装VBox初次启动时似乎都会遇到这个问题。
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (4.18.0-193.14.2.el8_2.x86_64) or it failed to
load. Please recompile the kernel module and install it by
sudo /sbin/vboxconfig
You will not be able to start VMs until this problem is fixed.
Invalid MIT-MAGIC-COOKIE-1 keyQt WARNING: could not connect to display :22
Qt FATAL: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
Aborted
解决方法: 使用/sbin/rcvboxdrv setup
sudo /sbin/rcvboxdrv setup
- 若出现错误
vboxdrv.sh: Stopping VirtualBox services. vboxdrv.sh: Starting VirtualBox services. vboxdrv.sh: Building VirtualBox kernel modules. vboxdrv.sh: failed: Look at /var/log/vbox-setup.log to find out what went wrong.查看log文件,发现缺失一个库libelf-dev,安装相应的库重新运行
sudo /sbin/rcvboxdrv setup成功后即可正常使用Vboxvboxdrv.sh: Stopping VirtualBox services. vboxdrv.sh: Starting VirtualBox services. vboxdrv.sh: Building VirtualBox kernel modules. - 若出现下面错误
vboxdrv.sh: Stopping VirtualBox services. vboxdrv.sh: Starting VirtualBox services. vboxdrv.sh: Building VirtualBox kernel modules. This system is currently not set up to build kernel modules. Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system. The distribution packages containing the headers are probably: kernel-devel kernel-devel-4.18.0-193.el8.x86_64在CentOS下需要安装
kernel-devel kernel-devel-4.18.0-193.el8.x86_64;在Debian下则需要安装linux-headers-*,如Debian10,32位系统安装linux-headers-4.19.0-100-all-i386,重启。
虚拟机管理
虚拟机内安装增强功能
安装增强功能时遇到下面的问题,需要安装kernel header以及gcc和make,在CentOS中sudo dnf install kernel-devel gcc make在Debian系统中运行apt install
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
4.19.0-10-amd64. Please install them and execute
/sbin/rcvboxadd setup
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
调整磁盘大小
vboxmanage命令可以用于管理虚拟机,如查询虚拟磁盘信息,调整虚拟磁盘大小
# 查看磁盘test.vdi信息
#vboxmanage showhdinfo test.vdi
#UUID: 0585957d-2bad-4a68-b734-d7f7de1e9d98
#Parent UUID: base
#State: locked read
#Type: normal (base)
#Location: /home/test/vbox/test/test.vdi
#Storage format: VDI
#Format variant: dynamic default
#Capacity: 32768 MBytes
#Size on disk: 5757 MBytes
#Encryption: disabled
#Property: AllocationBlockSize=1048576
#In use by VMs: test (UUID: c49f818f-23dc-4aa8-9bd6-db12514e29be) [begin (UUID: 37ecd323-9c2f-4200-8872-ba16e2639b77)]
#Child UUIDs: e93c9620-e81a-487d-8d70-383a0895a3a0
# a8583520-87d8-4b68-9aef-8bce64e722fc
# 调整磁盘大小,以M为单位。注意需要关闭或暂停虚拟机!
vboxmanage modifymedium test.vdi --resize 51200
# 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
参考