如今,设置Ubuntu虚拟机既快速又简单,因此您可以在不格式化系统的情况下使用Linux 。但是,要真正充分利用您的Ubuntu虚拟机,如果主机操作可以与来宾交互,那不是很好吗?这是您可以使用VirtualBox Guest Additions(VirtualBox Guest Additions)做的事情之一,我们将向您展示如何安装它。
基本 VirtualBox 行话
在我们深入了解Guest Additions的内容之前,您需要了解一些核心概念才能理解这一切。如果您已经精通虚拟机语言,您可以直接跳到下一部分,但如果没有,请稍等片刻。
我们已经在开篇提到了两个最重要的概念:主机系统和访客系统。
主机操作系统是运行在“裸机”机器上的实际操作系统。那是实际的物理计算机。您的操作系统和计算机硬件之间没有任何关系。
来宾系统,即虚拟机,作为主机操作系统中的应用程序运行。来宾系统“认为”它在一台真实的计算机上运行,它看到了它所期望的所有“硬件”,但它都是模拟的。
按照设计,来宾系统和主机系统之间存在硬屏障。这包括在来宾系统上运行的所有应用程序。这就是为什么,例如,用虚拟机测试病毒或做其他有风险的事情是安全的。好吧,只要您没有与活动的 VM 的网络连接!
客人添加可以做什么?
顾名思义,Guest Additions 是添加到来宾操作系统中的软件,因此它(Guest) 基本上(Additions)获得(guest )了任何虚拟机都不应该拥有的令人毛骨悚然的超能力。
不开玩笑,添加来宾的主要目的是将虚拟机与主机操作系统集成,同时又不会失去两者之间的虚拟化屏障的优势。安装附加组件时,您会获得一些非常有用的功能:
- 主人和客人之间的时钟同步,以便他们始终显示相同的时间。
- 您可以在主机和来宾之间自由使用鼠标指针,而不会捕获指针。
- 共享文件夹使在主机和来宾之间安全传输文件变得简单。
- 您可以自由调整客户机窗口的大小,它会动态调整其分辨率以匹配。
- 更好的加速图形可以访问需要主机上更高级GPU功能的虚拟化应用程序。(GPU)
- 共享剪贴板,可以轻松地在两个系统之间复制和粘贴内容。
还有更多真正有用的功能。如果您想了解更多信息,请阅读VirtualBox(VirtualBox Documentation)官方文档以获取技术细节。
你有一个工作的虚拟机吗?
本文不是关于设置Ubuntu 虚拟机(Ubuntu Virtual Machine),但您需要一台正常工作且配置正确的VirtualBox Ubuntu机器才能在Ubuntu中安装(Ubuntu)VirtualBox Guest Additions。如果您需要,请前往如何使用 VirtualBox 在 Windows 上安装 Linux,(How to Install Linux on Windows With VirtualBox)并确保您以正确的方式完成了所有工作。如果您的Ubuntu 虚拟机(Ubuntu VM)正常,我们已准备好进行实际安装过程。
安装 Ubuntu 来宾添加
假设您在VirtualBox中有一个可以工作的(VirtualBox)Ubuntu VM准备就绪,您可以轻松安装来宾添加。
但是,在您这样做之前,我们建议您拍摄 VM 的快照,以防来宾添加安装出现问题。请记住,这些是安装到 VM 的驱动程序和实用程序,因此它会改变虚拟系统。
您可以通过以下两种方式之一拍摄快照。首先是按host key + T。默认情况下; 除非有人在设置中更改了此键,否则右Ctrl 键(Ctrl key)是主机键。(host key)当前主机密钥显示在虚拟机窗口的右下角。或者,只需使用Machine > Take Snapshot。
命名快照,保存它,然后返回到您的 VM。
现在,选择Devices然后Insert Guest Additions CD。
您将从Ubuntu收到此消息,选择Run。
现在,输入您的管理员密码(administrator password)并选择Authenticate。
该软件将运行并安装来宾添加。您可能会收到有关系统未设置为构建内核模块的错误,只需忽略它并按Enter即可。
你猜怎么了?这就是它的全部。现在已安装来宾(Guest)添加,您应该准备好了。虽然,您应该测试以查看安装是否正常工作。
测试访客添加
为确保来宾(Guest) 添加(Additions)按预期工作,您将尝试一些快速测试。
首先,将鼠标指针从虚拟机窗口外移到Ubuntu中的桌面图标上。(Ubuntu)他们强调吗?您可以单击桌面图标,然后将鼠标指针无缝移动到主机操作系统吗?
接下来,让我们测试一下共享文件夹是否正常工作。
首先,从虚拟机菜单中选择Devices > Shared Folders > Shared Folders Settings
现在,选择添加共享图标(add share icon)。
然后,在文件夹路径(Folder Path)下,选择其他(Other),然后浏览并选择主机计算机上要与虚拟机共享的文件夹。请务必选择自动挂载(Auto-mount),以便文件夹在来宾系统中自动分配驱动器号。
完成后,选择OK,您应该会看到您的共享文件夹列在临时文件夹(transient folders)下。请记住(Remember),我们只是在测试添加的访客是否正常工作;您可以随时返回并永久保存您的共享文件夹。
现在,再次选择OK并导航到虚拟机上的主文件夹(home folder on the virtual machine),您应该会看到该文件夹及其内容。除非您将文件夹设为只读,否则您也可以通过这种方式将文件从访客复制到主机。
有关共享文件夹的更详细指南,请查看VirtualBox 中主机和来宾操作系统之间的共享文件夹(Share Folders between Host and Guest OS in VirtualBox)。
让 Ubuntu超越虚拟机(Ubuntu Beyond Virtual Machines)
拥有一个方便的Ubuntu Linux(或任何Linux)虚拟机对于几乎任何目的都非常有用。尽管如此,您永远无法获得与裸机相同的性能或兼容性。
在VirtualBox中使用(VirtualBox)Linux后,一旦您对 Linux 感到满意,您可以考虑双引导Ubuntu和Windows。如果这太过分了,请查看我们的最佳便携式 Linux 操作系统(best portable Linux operating systems)列表。这样,您就可以在不更改计算机本身的任何内容的情况下启动Linux 。
How To Install VirtualBox Guest Additions in Ubuntu
It’s quick and easy these days to set up a Ubuntu virtual machine, so you can play around with Linux without formatting yoυr system. However, to really get the most out of your Ubuntu virtual machine, wouldn’t it be nice if the host operating could interact with the guest? That’s one of the things that you can do with VirtualBox Guest Additions, and we’re going to show you how to install it.
Essential VirtualBox Lingo
Before we get into the meat and potatoes of Guest Additions, there are a few core concepts you’ll need to know to make sense of it all. If you’re already well versed in the language of virtual machines, you can just skip to the next section, but if not, stick around for a minute.
We’ve already mentioned the two most important concepts in the opening paragraph: host and guest system.
The host operating system is the actual operating system running on the “bare metal” machine. That’s the actual physical computer. There’s nothing between your operating system and the hardware of the computer.
The guest system, the virtual machine, runs as an application within the host operating system. The guest system “thinks” it’s running on a real computer, and it sees all the “hardware” that it expects, but it’s all simulated.
By design, there’s a hard barrier between the guest and host system. That includes all the applications running on the guest system. This is why, for example, it’s safe to test viruses or do other risky things with a virtual machine. Well, as long as you don’t have a network connection to the VM active!
What Can Guest Additions Do?
The Guest Additions are, as the name suggests, software that’s added to the guest operating system so that it essentially gains spooky superpowers that no virtual machine should have.
All kidding aside, the primary purpose of guest additions is to integrate the virtual machine with the host operating system without losing the advantages of the virtualized barrier between the two. When you install the additions, you get some seriously useful features:
- Synced clocks between the host and guest so that they always show the same time.
- You can freely use the mouse pointer between host and guest without the pointer getting captured.
- Shared folders to make it simple to transfer files safely between host and guest.
- You can freely resize the guest machine’s window, and it will dynamically adjust its resolution to match.
- Better accelerated graphics can access virtualized apps that need more advanced GPU features on the host machine.
- A shared clipboard, making it easy to copy and paste things between the two systems.
There are even more really helpful features. Read the official VirtualBox Documentation for the technical details if you want to know more.
Have You Got a Working Virtual Machine?
This article isn’t about setting up an Ubuntu Virtual Machine, but you need a working and properly configured VirtualBox Ubuntu machine to install VirtualBox Guest Additions in Ubuntu. If you need to, head over to How to Install Linux on Windows With VirtualBox and make sure you’ve done everything the right way. If your Ubuntu VM is in order, we’re ready to proceed to the actual installation process.
Installing Ubuntu Guest Additions
Assuming that you have a working Ubuntu VM in VirtualBox ready to go, you can install the guest additions easily.
Before you do that, however, we recommend that you take a snapshot of your VM just in case something goes wrong with the guest addition installation. Remember that these are drivers and utilities installed to the VM, so it alters the virtual system.
You can take a snapshot in one of two ways. The first is to press the host key + T. By default; the right Ctrl key is the host key unless someone has changed this in the settings. The current host key is displayed in the bottom right corner of the virtual machine window. Alternatively, simply use Machine > Take Snapshot.
Name the snapshot, save it and then return to your VM.
Now, select Devices and then Insert Guest Additions CD.
You’ll get this message from Ubuntu, select Run.
Now, type in your administrator password and select Authenticate.
The software will run and install guest additions. You may get an error about the system not being set up to build kernel modules, just ignore it and press Enter.
Guess what? That’s all there was to it. Guest additions are now installed, and you should be ready to go. Although, you should test to see whether the installation has worked properly or not.
Testing Guest Additions
To make sure that Guest Additions is working as intended, you’re going to try a few quick tests.
First, move your mouse pointer over the desktop icons in Ubuntu from outside the virtual machine window. Do they highlight? Can you click on a desktop icon and then seamlessly move the mouse pointer to the host operating system?
Next, let’s test whether shared folders are working correctly.
First, select Devices > Shared Folders > Shared Folders Settings from the virtual machine menu.
Now, select the add share icon.
Then, under Folder Path, choose Other and then browse for and select the folder on the host computer that you want to share with the virtual machine. Be sure to choose Auto-mount so that the folder is automatically assigned a drive letter in the guest system.
When you’re done, select OK, and you should see your shared folder listed under transient folders. Remember, we’re just testing whether the guest additions are working properly; you can always go back and make your shared folder permanent.
Now, select OK again and navigate to your home folder on the virtual machine, and you should see the folder and its contents. Unless you made the folder read-only, you can copy files from the guest to the host this way as well.
For a more detailed guide to shared folders, check out Share Folders between Host and Guest OS in VirtualBox.
Taking Ubuntu Beyond Virtual Machines
Having a Ubuntu Linux (or any Linux) virtual machine handy is excellent for almost any purpose. Still, you’re never going to get the same performance or compatibility that bare metal offers.
Once you feel comfortable with Linux after playing with it in VirtualBox, you could consider dual-booting Ubuntu with Windows. If that’s too much of a commitment, have a look at our list of the best portable Linux operating systems. That way, you can boot into Linux without altering anything on the computer itself.