sudo usermod -a -G vboxsf usernanme
通常情况下选择设备->安装增强功能再重启即可。
但是有时候已经装过一次但失败了,可以进入media目录下挂载的VBOX_GAS_XXX目录
在该目录下启动终端,执行:
sudo ./autorun.sh
如果执行也无法安装,日志中显示以下内容:
This system is currently not set up to build kernel modules. Please
install the gcc make perl packages from your distribution. VirtualBox
Guest Additions: Running kernel modules will not be replaced until
the system is restarted Press Return to close this window…
下载对应模块,再执行上述命令即可。
sudo apt-get install gcc make perl
其他情况
粘贴有用,但是无法访问共享文件夹,且启动时会有报错条目,界面无法自适应,永远是固定大小,你可能会看到以下报错信息。
例如:
VBoxClient: Failed to get display change request, rc=VERR_IO_BAD_LENGTH
或是一闪而过的:
“Failed to start Load Kernel Modules”
经过检查 systemctl --state=failed
,发现两个模块启动失败:
$ systemctl --state=failed
UNIT LOAD ACTIVE SUB DESCRIPTION
● systemd-modules-load.service loaded failed failed Load Kernel Modules
● ufw.service loaded failed failed Uncomplicated firewall
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
2 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
$ sudo systemctl status systemd-modules-load.service
● systemd-modules-load.service - Load Kernel Modules
Loaded: loaded (/lib/systemd/system/systemd-modules-load.service; static; ven
Active: failed (Result: exit-code) since 一 2020-10-19 13:14:56 CST; 3min 6s
Docs: man:systemd-modules-load.service(8)
man:modules-load.d(5)
Process: 220 ExecStart=/lib/systemd/systemd-modules-load (code=exited, status=
Main PID: 220 (code=exited, status=1/FAILURE)
Warning: Journal has been rotated since unit was started. Log output is incomple
ESC
再根据PID查询:
$ sudo journalctl -b _PID=220
-- Logs begin at 一 2020-10-19 13:14:56 CST, end at 一 2020-10-19 13:21:10 CST.
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: could not open moddep file '/lib/modules/4.15.0-120-generic/modules.dep.bin'
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: Failed to lookup alias 'lp': Function not implemented
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: could not open moddep file '/lib/modules/4.15.0-120-generic/modules.dep.bin'
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: Failed to lookup alias 'ppdev': Function not implemented
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: could not open moddep file '/lib/modules/4.15.0-120-generic/modules.dep.bin'
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: Failed to lookup alias 'parport_pc': Function not implemented
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: could not open moddep file '/lib/modules/4.15.0-120-generic/modules.dep.bin'
10月 19 13:14:56 ljl-VirtualBox systemd-modules-load[220]: Failed to lookup alias 'fuse': Function not implemented
lines 1-9/9 (END)...skipping...
~
原来是内核模块的问题,
可以尝试:sudo depmod
如果没用,那就运行这一句:
sudo apt-get install --reinstall linux-image-`uname -r`
成功解决。
如果要能在virtualbox中使用双向鼠标粘贴和共享文件夹,就必须要安装增强功能。
选择左上角 【设备】-【安装增强功能】,通常会自动开始运行安装脚本。如果没有自动开始安装,点进桌面上增添的名为VBox_GAs的虚拟光驱,启动.run文件就行。
因为是给新电脑刚安装的Ubuntu虚拟机,所以缺少模块,根据安装失败的英文提示,我下载了缺乏的 perl、gcc、make等包。
sudo apt-get install perl gcc make
随后就能安装成功了。
按理说重启以后应该没问题,但是不仅没有生效,再次点击增强功能的安装文件,会出现“未能加载虚拟光盘的错误”。
点击VBox_GAs则会出现:“Unable to Access ‘VBox_GAs_6.1.16’”错误
jhl@jhl-VirtualBox:~$ systemctl --state=failed
UNIT LOAD ACTIVE SUB DESCRIPTION
● systemd-modules-load.service loaded failed failed Load Kernel Modules
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
1 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
jhl@jhl-VirtualBox:~$ sudo systemctl status systemd-modules-load.service
● systemd-modules-load.service - Load Kernel Modules
Loaded: loaded (/lib/systemd/system/systemd-modules-load.service; static; ve
Active: failed (Result: exit-code) since Mon 2020-12-21 09:30:22 CST; 20min
Docs: man:systemd-modules-load.service(8)
man:modules-load.d(5)
Process: 281 ExecStart=/lib/systemd/systemd-modules-load (code=exited, status
Main PID: 281 (code=exited, status=1/FAILURE)
Warning: Journal has been rotated since unit was started. Log output is incompl
jhl@jhl-VirtualBox:~$ sudo journalctl -b _PID=281
-- Logs begin at Sat 2020-12-19 19:37:46 CST, end at Mon 2020-12-21 09:52:12 CS
12月 21 09:30:23 jhl-VirtualBox systemd-modules-load[281]: Failed to lookup ali
12月 21 09:30:23 jhl-VirtualBox systemd-modules-load[281]: Failed to lookup ali
12月 21 09:30:23 jhl-VirtualBox systemd-modules-load[281]: Failed to lookup ali
lines 1-4/4 (END)
检查了一下居然和上面是同样的错误。
还是这么解决的:
sudo apt-get install --reinstall linux-image-`uname -r`