如何在 Windows 10 中设置 Ubuntu 虚拟机
Linux Windows Hyper-V
![](/data/attachment/album/202010/03/114551tnlr0guvn0vlnsg0.jpg)


如果你想尝试在 Windows 10 中设置一个或多个 Ubuntu 虚拟机进行自己的实验，请按照以下步骤进行。


### 1、启用 Hyper-V 平台


所有 64 位 Windows 10 专业版、企业版和教育版都内置了这个<ruby> 管理程序 <rp>  （ </rp> <rt>  hypervisor </rt> <rp>  ） </rp></ruby>，但默认情况下并没有启用。在在旧电脑上启用该功能之前，你可能需要打开一些固件选项。有关完整说明，请参阅“[Windows 10：如何启用 Hyper-V 并创建虚拟机](https://www.zdnet.com/article/windows-10-tip-how-to-enable-hyper-v-and-create-virtual-machines/)”。


### 2、使用快速创建工具来下载并安装 Ubuntu 虚拟机


Hyper-V 提供了两种创建新虚拟机的方法。老式的方法是通过一个繁琐的多步骤向导来点击。更简单的解决方案是使用 Hyper-V 的“快速创建”工具。你可以在 Hyper-V 管理器的右侧窗格中找到一个快捷方式，或者你可以直接在 Windows 10 搜索框搜索 `Vmcreate.exe` 命令打开它。


从左侧的陈列栏中选择一个 Ubuntu 版本，然后点击“创建虚拟机”按钮。这将需要下载 1.6GB（18.04.3 LTS）到 2GB（更近的版本）。下载完成后，该“快速创建”功能会提取镜像、配置虚拟机，然后显示一个对话框，告诉你虚拟机已成功创建。


 


### 3、调整一些设置


虽然你可以通过点击“连接”立即开始，但如果你的 Windows 10 主机上有足够的资源，我建议你点击“编辑设置”，以便你可以先进行一些调整。


![](/data/attachment/album/202010/03/112217zw8enlyfekwdl570.jpg)


*我建议你在第一次运行虚拟机之前编辑一些设置*


从新虚拟机的硬件列表中选择“内存”，然后将分配的 RAM 从其默认值 2048 改为 4096，这应该会带来更好的性能。如果你想要一个固定数量的虚拟内存，你也可以禁用动态内存。你可能还希望将系统磁盘的大小从其默认的 12GB 提升到更多。单击“硬盘驱动器”，然后单击“编辑”，并按照提示操作，直到进行到“扩展”命令那一步。


![](/data/attachment/album/202010/03/112747gbpcictiqcioz6uk.jpg)


*根据需要调整分配给你的 Linux 虚拟机的内存*


最后，在“管理”标题下，单击“检查点”，然后清除“使用自动检查点”框。（如果你希望能够回滚更改，可以随时手动创建检查点。）


这些调整完毕后，可以关闭“设置”对话框，并首次打开虚拟机。


### 4、设置你的用户账户


运行 Ubuntu 的系统配置，选择你的默认语言、时区等。当你进入创建登录凭证的界面时，将默认设置保留在“需要我的密码才能登录”。


虽然听起来很方便，但不要启用自动登录功能。如果你选择此选项，将无法使用增强型会话登录，并且你的虚拟机将被迫在一个相对较小的窗口中运行，其默认分辨率无法轻松更改。


这也是运行“系统更新管理器”应用程序并获取最新 Ubuntu 更新的好时机。（点击左下角的 Ubuntu 图标，使用搜索框找到该应用。）


### 5、使用增强版会话登录


如果你在“虚拟机连接”窗口中看到这个对话框，你就会知道已经启动了一个增强的会话：


![](/data/attachment/album/202010/03/113335lyfsypf8sfaaaa8p.jpg)


*将该滑块移至最右侧，以全屏方式运行虚拟机*


滑动开关来选择你的显示分辨率。我喜欢将滑块向右移动，到全屏位置。如果你有多个显示器，并希望虚拟机跨越它们，请选择 “使用所有我的显示器”复选框。单击“连接”继续，打开 Xrdp 登录对话框，如图所示：


![](/data/attachment/album/202010/03/113335l7f9ce1ffw3trwf7.jpg)


*登录到 Xrdp 以启动增强型 Hyper-V 会话*


输入你在创建 Ubuntu Linux 账户时设置的用户名和密码，然后点击“确定”。假设大神们没有生气，你就会登录到你的虚拟机上，可以开始工作了。如果你还没有在你要连接的会话上登录，可能需要第二次输入密码。（如果你得到一个黑屏，尝试按回车键。）


如果你使用 18.04.3 LTS 虚拟机，所有这些都应该可以正常工作。如果你使用的是 Ubuntu 19.10，你可能要经历我所做的同样令人沮丧的一次次重启，然后一切才能正常工作。


对于 Ubuntu 20.04 来说，在基本会话中一切都很正常，但是在我编辑 `/etc/xrdp` 中的 `Xrdp.ini` 文件之前，运行增强会话的选项是不可用的。这是一个受保护的位置，所以我不得不用管理员的凭证打开一个编辑器，这个任务既不直观也不容易。


我必须修改 ini 文件中的两行内容。首先，把 `port=3389` 改为 `port=vsock://-1:3389`。然后把 `use_vsock=true` 改为 `use_vsock=false`。关闭虚拟机连接窗口并再次连接到虚拟机，你应该可以启动增强型会话。但你可能还需要召唤一些小神灵，烧一些香。毕竟，这是 Linux。


（正如我之前所提到的，Canonical/微软团队将在 20.04.1 更新中对该镜像进行修复，所以到时候 xrdp.ini 文件不需要编辑了。）


而你现在就只能靠自己了。你必须找到能让你完成实际工作的生产力软件。如果你像我一样，主要使用微软的服务，准备好接受一大堆的挫折吧。


微软目前没有任何适用于 Linux 的 Office 应用程序，所以你需要从 Web 浏览器访问你的文件。(是的，有 Linux 的 Office 克 隆版，包括 LibreOffice 套件，它是微软 Office 2007 的忠实克隆版。它……勉强够用。)


在 Ubuntu Linux 20.04 中，我可以直接连接 Google Drive，这样那些云端备份的文件就直接出现在文件应用中。还可以使用一个易于安装的 Dropbox 应用。但是 OneDrive 呢？那就不一定了。有一个开源的第三方同步客户端，但安装时需要半打以上的依赖包，我没有耐心也没有信心完成这个过程。


Ubuntu Linux 中的默认浏览器是 Mozilla Firefox，它在 18.04.3 LTS 版本上工作得足够好，但在 20.04 版本中却很卡顿。微软表示，它计划为 Linux 发布基于 Chromium 的新 Edge，但到目前为止，这还只是一个排期。从好的方面来看，有一个做得非常好的微软 Teams 客户端，它可以提供一个原生的 .deb 包来安装。


虽然整体体验出乎意料的流畅，但有太多的时刻，运行 Linux 对我来说感觉略显磕磕绊绊。比如在 20.04 版本中，Firefox 会将包文件下载到一个临时文件夹，在那里无法正常打开。当我弄清楚我必须把这些文件移到下载目录下，一切都好了。（请注意， Google Chrome 浏览器的下载会默认到正确的位置。）


另一方面，如果你的工作日是在谷歌生态系统中度过的，Linux 可能会感到非常舒适。在安装 Chrome 浏览器和设置 G Suite 之后，这个虚拟机基本上就是一个略显廉价的 Chromebook。


我是不是要改用 Linux 作为主要操作系统？呃，不会。但我会让这些虚拟机继续服务，并定期检查。因为你永远不知道会……




---


via: <https://www.zdnet.com/article/microsoft-helped-me-install-ubuntu-linux-on-my-windows-10-pc-and-its-actually-pretty-good/> 


作者：[Ed Bott](https://www.zdnet.com/meet-the-team/us/ed-bott/) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](/article-12677-1.html) 荣誉推出


OK
# Microsoft helped me install Ubuntu Linux on my Windows 10 PC, and it's actually pretty good

![ed-bott](https://www.zdnet.com/a/img/resize/53ea6d95ba2f62d612a514d19551a13b56941f68/2022/08/05/e98b0a76-a96a-4fbb-be02-00807405874e/ed-bott.jpg?auto=webp&fit=crop&frame=1&height=192&width=192)

If you've ever suffered through a painful Windows update or watched in disbelief as your MacBook decided to slow to a crawl and switch its fan into jumbo-jet-at-takeoff mode, you know that there's one and only one answer to your woes: "Switch to Linux."

I kid, of course, but you'll find that advice offered in earnest if you scroll through the comments here at *ZDNet*, where an army of open source evangelists regularly preaches the Gospel of Saint Linus in response to even the most vaguely related bit of news about other platforms.

**Also: ****Open source's Eric Raymond: Windows 10 will soon be just an emulation layer on Linux kernel**** **

And you know what? I think those commenters have a legitimate point. Anyone who aspires to understand the modern computing landscape should have some experience with platforms other than the one they use regularly because a lot of what you see in Windows, MacOS, and Linux today comes from the same DNA.

In the interest of keeping up with what's new in Linux, I go through this exercise myself every year or two. So, imagine my surprise when this year I was able to build a functional Ubuntu Linux machine in minutes, without disturbing my current Windows 10 setup. Even more surprising: Microsoft did most of the work.

The magic that made all this possible is the Hyper-V virtualization software included with every PC running Windows 10 Pro or Enterprise. (Sorry, Windows 10 Home users, you're going to have to upgrade if you want to play along.) Hyper-V's Quick Create gallery, which can build a new virtual machine in just a few clicks, includes not one but three separate Ubuntu images, including the new Ubuntu 20.04 version.

The Hyper-V Quick Create utility includes three Ubunutu Linux versions

Best of all, these custom images are capable of running in a Hyper-V *enhanced session*, which means you can choose a custom display resolution or run in a full screen, even spanning multiple monitors, with a performance that's close to what you'd get running on bare metal. In an enhanced session, your virtual machine can share the Windows Clipboard, local storage, and audio hardware on the host machine.

Once you get everything working, you can fire up that Ubuntu VM in full-screen mode and work with it just as if the Windows 10 host machine weren't there.

**Must read:**

[Microsoft: Linux GUI apps coming to Windows 10 WSL along with GPU access](https://www.zdnet.com/article/microsoft-linux-gui-apps-coming-to-windows-10-wsl-along-with-gpu-access/)[Desktop Linux: Why open source is heading for a new breakthrough](https://www.techrepublic.com/article/desktop-linux-why-open-source-is-heading-for-a-new-breakthrough/)**TechRepublic**[Linux-based Windows makes perfect sense](https://www.zdnet.com/article/linux-based-windows-makes-perfect-sense/)

Alas, that part about getting everything working isn't just a figure of speech. The good news is that the two-year-old [Ubuntu 18.04.3 Long Term Support (LTS)](https://www.zdnet.com/article/linux-on-windows-10-running-ubuntu-vms-just-got-a-lot-easier-says-microsoft/) version worked perfectly, with no futzing required. But the two newer releases had me tearing my hair out. I needed to manually edit a protected Linux configuration file before I could get an enhanced session to work in the latest [Ubuntu release (20.04), ](https://www.zdnet.com/article/ubuntu-20-04-arrives-with-linux-5-4-kernel-and-wireguard-vpn/)and the version 19.10 VM hung several times and required at least a dozen restarts (including a few hard resets) before it worked as expected.

Still, after all was said and done, I had three working virtual machines, giving me a pretty decent overview of what's new in Ubuntu Linux.

*Update, June 5, 2020: Via Twitter, Hayden Barnes, Developer Advocate for Ubuntu on WSL and Hyper-V at @Canonical, says, "We know about the xrdp bug in 19.10 and 20.04. The 20.04 image will be patched in the upcoming 20.04.1 LTS update. 19.10 is nearing EOL and will be dropped."*

*Update 2, October 1, 2020: The 20.04.1 LTS desktop Ubuntu image was released on July 31, 2020, but as of October 1 it has not yet been integrated into the Quick Create image in Hyper-V. *

*Also, as my colleague Mary Branscombe notes, all editions of Windows 10, including Home, offer access to the Windows Subsystem for Linux, which runs the Linux kernel in a lightweight virtual machine and has been freshly updated to WSL2 as of Windows 10 version 2004. As the WSL2 documentation makes clear, this is not a traditional VM experience and it's best suited for developers who want a command line experience and the ability to run Bash shell scripts and GNU/Linux command-line applications. The ability to run graphical apps in the WSL2 environment is on Microsoft's roadmap and should be available for testing by Windows Insiders in late 2020 or early 2021.*

If you'd like to try setting up one or more Ubuntu VMs in Windows 10 for your own experimentation, follow these steps.

### 1. Enable the Hyper-V Platform

This hypervisor is built into all 64-bit Windows 10 Pro, Enterprise, and Education editions, but it's not enabled by default. You might need to turn on some firmware options on older PCs before you can enable the feature. For full instructions, see ["Windows 10: How to enable Hyper-V and create virtual machines."](https://www.zdnet.com/article/windows-10-tip-how-to-enable-hyper-v-and-create-virtual-machines/)

### 2. Use Quick Create to download and install the Ubuntu VM

Hyper-V offers two ways to create a new virtual machine. The old fashioned way is to click your way through a tedious multi-step wizard. The much easier solution is to use the Hyper-V Quick Create utility. You'll find a shortcut in the right pane in Hyper-V Manager, or you can open it directly using the Vmcreate.exe command in the Windows 10 search box.

Choose an Ubuntu version from the gallery on the left, then click the Create Virtual Machine button. That kicks off a download of between 1.6GB (18.04.3 LTS) and 2GB (more recent versions). After the download is complete, the Quick Create utility extracts the image, configures the VM, and then displays a dialog box telling you your virtual machine was created successfully.

I recommend you edit a few settings before running the VN for the first time.

### 3. Tweak a few settings

Although you can get started immediately by clicking Connect, if you have sufficient resources on your Windows 10 host machine, I recommend that you click Edit Settings instead, so you can make a few adjustments first.

Choose Memory from the hardware list for your new VM, and then change the assigned RAM from its default value of 2048 to 4096, which should result in better performance. You can also disable dynamic memory if you want a fixed amount of virtual RAM. You might also want to increase the size of the system disk from its default 12GB. Click Hard Drive, then click Edit, and follow the prompts till you reach the Expand command.

Feel free to tweak the memory assigned to your Linux VM

Finally, under the Management heading, click Checkpoints and then clear the Use Automatic Checkpoints box. (You can always create a checkpoint manually if you want the ability to roll back changes.)

With those adjustments out of the way, you can close the Settings dialog box and open the VM for the first time.

### 4. Set up your user account

Run through the system configuration for Ubuntu, choosing your default language, time zone, and so on. When you get to the screen where you create your login credentials, leave the default setting at **Require my password to log in**.

Although it sounds convenient, do not enable the auto-login feature. If you choose this option, you won't be able to sign in using an enhanced session, and your VM will be forced to run in a relatively small window with a default resolution that you can't easily change.

This is also a good time to run the Software Updater app and get the latest Ubuntu updates. (Click the waffle icon in the lower-left corner and use the search box to find the app.)

### 5. Sign in using an enhanced session

You'll know you've started an enhanced session if you see this dialog box in the VM Connect window.

Move that slider to the far right to run your VM in a full screen

Slide the switch to choose your display resolution. I prefer to move the slider to the right, to the Full Screen position. If you have multiple monitors and you want your VM to span across them, select the Use All My Monitors checkbox. Click Connect to continue, which opens the Xrdp sign-in dialog box, shown here.

Sign in to Xrdp to launch your enhanced Hyper-V session

Enter the username and password you set up when creating your Ubuntu Linux account and click OK. Assuming the gods are not angry, you'll sign in to your VM and can get to work. You might have to enter your password a second time if you're not already signed in on the session that you're connecting to. (If you get a black screen, try pressing Enter.)

All of that should work just fine if you started with an 18.04.3 LTS VM. If you're using Ubuntu 19.10, you might have to go through the same frustrating sequence of restarts that I did before everything works properly.

### Linux

For Ubuntu 20.04, everything worked just fine in a basic session, but the option to run an enhanced session wasn't available until I edited the Xrdp.ini file in /etc/xrdp. This is a protected location, so I had to open an editor with an administrator's credentials, a task which is neither intuitive nor easy.

I had to change two lines in that ini file. First, change port=3389 to port=vsock://-1:3389. Then change use_vsock=true to use_vsock=false. Close the Vmconnect window and connect to the VM again and you should be able to start an enhanced session. But you might also be required to invoke some minor deities and burn some incense. It's Linux, after all.

(As I noted earlier, the Canonical/Microsoft team will have a fix for that image with the 20.04.1 update, so the xrdp.ini file won't require editing.)

And you're now on your own. You'll have to find productivity software that allows you to get actual work done. If you're like me and use mostly Microsoft services, prepare for a heaping helping of frustration.

Microsoft doesn't currently have any Office apps for Linux, so you'll need to access your files from a web browser. (Yes, there are Office clones for Linux, including the LibreOffice suite, which is a faithful clone of Microsoft Office 2007. It's... barely adequate.)

**Must read:**

[Look what's inside Linus Torvalds' latest Linux development PC](https://www.zdnet.com/article/look-whats-inside-linus-torvalds-latest-linux-development-pc/)[New fuzzing tool finds 26 USB bugs in Linux, Windows, macOS, and FreeBSD](https://www.zdnet.com/article/new-fuzzing-tool-finds-26-usb-bugs-in-linux-windows-macos-and-freebsd/)[Microsoft's Windows Package Manager: This command-line tool can install all your apps](https://www.zdnet.com/article/microsofts-windows-package-manager-this-command-line-tool-can-install-all-your-apps/)

In Ubuntu Linux 20.04, I was able to connect Google Drive directly, so that those cloud-backed files appeared directly in the Files app. An easy-to-install Dropbox app was also available. But OneDrive? Not so much. There's an open source third-party sync client, but the installation required more than a half-dozen dependent packages, and I didn't have the patience or the confidence to complete the process.

The default browser in Ubuntu Linux is Mozilla Firefox, which worked well enough on the 18.04.3 LTS version but was jerky in the 20.04 release. Microsoft says it plans to release its new Chromium-based Edge for Linux, but so far that's just a pipe dream. On the plus side, there's a very well done [Microsoft Teams client](https://www.zdnet.com/article/microsoft-teams-for-linux-now-available-in-public-preview/) that installs as a native .deb package.

Although the overall experience is surprisingly smooth, there were too many moments when running Linux felt slightly janky for me. In the 20.04 release, for example, Firefox downloads package files to a temp folder, where they won't open properly. Once I figured out that I had to move those files to the Downloads directory, everything was fine. (Note that Google Chrome downloads go to the correct location by default.)

If, on the other hand, your workday is spent in the Google ecosystem, Linux will probably feel very comfortable. After installing Chrome and setting up G Suite, this VM is basically a slightly snooty Chromebook.

Am I going to switch to Linux as my primary operating system? Uh, no. But I will keep these VMs in service and check in regularly. Because you never know...

#### Windows

[Editorial standards](/editorial-guidelines/)