记一次virtualbox ubuntu剪贴板无法使用

发布于 2020-06-03  130 次阅读


用虚拟机过程中,忽然发现剪切板不能使用了,但拖拽文件可以使用,复制粘贴文件又不可以,挺迷的,这俩不是一个操作吗?搜索研究了下,原因没整明白,但可以使用了至少,记录于此。

首先查看确认增强功能已安装,设置中也配置了双向共享粘贴板。

因而怀疑虚拟机里面的vbox进程没跑起来,键入查看vbox相关进程:

ps -A | grep apt

看是否有以下两个进程(clipboard就是与复制粘贴相关的服务):

user  1796  0.0  0.0 132528   412 ?    S    10月09   0:00 /usr/bin/VBoxClient --clipboard
user  1797  0.0  0.0 201168  1456 ?    Sl   10月09   0:01 /usr/bin/VBoxClient --clipboard

果然,其他服务都有,粘贴板相关的这两个进程没有启动,

键入以下命令,安装virtualbox-guest-x11:

sudo apt-get install virtualbox-guest-x11

此时报错:

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

产生原因:
运行apt-get时,锁定文件将会创建于/var/lib/dpkg/、/var/lib/apt/lists/、/var/cache/apt/archives/中,有助于apt-get进程避免被其他需要使用相同文件的系统进程所打断(这个机制也存在于Windows和其他操作系统中),当apt-get进程执行完毕后,锁定文件将会自动被删除;但由于apt-get进程由于某些原因(断网、网速慢等)被不正常终止了,导致锁文件未删除,因此需要删除锁定文件来避免错误

因此,先找到并杀掉所有的apt-get和apt的进程:

ps -A | grep apt

kill相关的进程,然后删除锁定文件:

sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a
sudo apt-get update

但是又出现了问题:

Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
virtualbox-guest-x11 : Depends: xorg-video-abi-11
                    Depends: xserver-xorg-core (>= 2:1.10.99.901)
E: Unable to correct problems, you have held broken packages.

提示缺少相关的依赖。

参考其他文章安装:

sudo apt-get remove libcheese-gtk23
sudo apt-get install xserver-xorg-core

仍然不成功:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  virtualbox-guest-utils
The following NEW packages will be installed:
  virtualbox-guest-utils virtualbox-guest-x11
0 upgraded, 2 newly installed, 0 to remove and 414 not upgraded.
Need to get 1,225 kB of archives.
After this operation, 7,062 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 virtualbox-guest-utils amd64 5.2.42-dfsg-0~ubuntu1.18.04.1
  Connection failed [IP: 91.189.91.39 80]
Err:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 virtualbox-guest-x11 amd64 5.2.42-dfsg-0~ubuntu1.18.04.1
  Connection failed [IP: 91.189.91.38 80]
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/multiverse/v/virtualbox/virtualbox-guest-utils_5.2.42-dfsg-0~ubuntu1.18.04.1_amd64.deb  Connection failed [IP: 91.189.91.39 80]
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/multiverse/v/virtualbox/virtualbox-guest-x11_5.2.42-dfsg-0~ubuntu1.18.04.1_amd64.deb  Connection failed [IP: 91.189.91.38 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

于是参照其他文章,删除原有的header,更新新的header:

sudo apt-get remove dkms build-essential linux-headers-*
sudo apt-get install dkms build-essential linux-headers-$(uname -r)
sudo apt-get install linux-generic
sudo apt-get update
sudo apt-get install virtualbox-guest-x11

终于解决了问题。

如今感觉比较清晰高质的教程太少了,本文也只是记录一下遇到的问题,对于产生的原因等后续学习更多linux相关知识之后再来分析,读者若遇到同样问题可参考本文,仅此而已。

本文参考:https://askubuntu.com/questions/287205/building-the-main-guest-additions-module-fail

https://blog.csdn.net/usedaccount/article/details/95055576/

如堕五里雾中
最后更新于 2022-04-11