hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

时间:2024-03-25 07:55:27
hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

hyper-v虚拟机驱动

hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

It’s extremely convenient to access a local hard drive (be it an internal drive or an external drive) that’s connected to your Windows computer from within a virtual machine running in Hyper-V. It’s not so convenient to figure out exactly how to accomplish that end though. Read on as we walk you through it.

从Hyper-V中运行的虚拟机中访问连接到Windows计算机的本地硬盘驱动器(内部驱动器或外部驱动器)极为方便。 不过,要弄清楚如何实现这一目标并不是很方便。 继续阅读时,请继续阅读。

我为什么要这样做? (Why Do I Want To Do This?)

There are dozens of scenarios where you would want to access a physical hard drive from inside your Hyper-V virtual machine ranging from accessing and importing data, dumping data from the virtual machine into the external drive, and importing or exporting disc images.

在数十种情况下,您需要从Hyper-V虚拟机内部访问物理硬盘驱动器,包括访问和导入数据,将数据从虚拟机转储到外部驱动器以及导入或导出磁盘映像。

Whatever reason you have for wanting to access an existing local hard drive in your Hyper-V machine it’s, unfortunately, a bit complicated giving the drives access to the virtual machine. Unlike other virtualization solutions there is no easy way to just share resources between the host machine and the Hyper-V virtual machine.

无论出于何种原因想要访问Hyper-V计算机中的现有本地硬盘驱动器,不幸的是,赋予驱动器访问虚拟机的权限有点复杂。 与其他虚拟化解决方案不同,没有简单的方法可以在主机和Hyper-V虚拟机之间共享资源。

To use a drive within a Hyper-V machine you need to take the drive, while physically attached and mounted to the host machine, offline and then reroute the offline-to-the-host disk into the virtual machine. Let’s take a look at how to do that now.

要在Hyper-V计算机中使用驱动器,需要将该驱动器物理连接并安装到主机后使其脱机,然后将脱机主机磁盘重新路由到虚拟机中。 让我们看一下现在如何做。

A quick note before we proceed: this trick only works with hard drives (magnetic hard drives, solid-state hard drives, and removable USB hard drives) but does not work, alas, with removeable media like flash drives.

在我们继续之前,有个简短的注意事项:此技巧仅适用于硬盘驱动器(磁性硬盘驱动器,固态硬盘驱动器和可移动USB硬盘驱动器),但是不适用于可移动媒体(如闪存驱动器)。

在Hyper-V中进行驱动器准备和安装 (Drive Preparation and Mounting In Hyper-V)

There are two primary steps to the procedure. First we need to manage the disk from within Windows on the host machine to bring it offline (but still powered and attached to the host computer) and then we need to tell Hyper-V to take control of the now-offline disk.

该过程有两个主要步骤。 首先,我们需要在主机上的Windows中管理磁盘以使其脱机(但仍处于供电状态并已连接到主机),然后我们需要告知Hyper-V来控制现在离线的磁盘。

准备驱动器 (Preparing the Drive)

The first step is to bring the disk offline. To do so open up the Disk Management application by searching for the application name or typing “diskmgmt.msc” in the search box and running the app. Within Disk Management look for the drive you wish to pass through to the virtual machine.

第一步是使磁盘脱机。 为此,通过搜索应用程序名称或在搜索框中键入“ diskmgmt.msc”并运行该应用程序来打开“磁盘管理”应用程序。 在“磁盘管理”中,查找要传递给虚拟机的驱动器。

Although it’s probably safe to assume, since you’re playing around with Hyper-V and concerned with matters like physical-disk-passthrough, that you’re already familiar with Disk Management it would be remiss of us not to issue a standard warning: Disk Management is a powerful tool and you can do terrible things to your system by mucking about within the management system. Double check each step and make sure you’re working with the right disk(s).

尽管可以假设是安全的,但是由于您正在使用Hyper-V并关心诸如物理磁盘直通之类的问题,因此您已经熟悉了磁盘管理,因此不发出标准警告是我们的错:磁盘管理是一个功能强大的工具,您可以通过在管理系统中随意处理来对系统进行可怕的处理。 仔细检查每个步骤,并确保您使用的磁盘正确。

hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

In our case we want to pass Disk 10, a USB backup HDD, through to the virtual machine so we can dump some backup files from our virtual machine onto the disk. To prepare the disk we must first locate it in the list of drives within Disk Management, right click on it, and select “Offline” from the right-click context menu as seen in the screenshot above.

在本例中,我们希望将磁盘10(USB备份HDD)传递到虚拟机,以便可以将虚拟机中的一些备份文件转储到磁盘上。 要准备磁盘,我们必须首先在“磁盘管理”中的驱动器列表中找到它,右键单击它,然后从右键单击上下文菜单中选择“脱机”,如上面的屏幕快照所示。

hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

Confirm the disk is offline. If you wish to bring the disk back online, after you’re done using it within the virtual machine, simply return to this menu, right click on the disk, and select “Online” to bring the disk back online for the host operating system.

确认磁盘离线。 如果要使磁盘恢复联机,请在虚拟机中使用完磁盘后,只需返回此菜单,右键单击磁盘,然后选择“联机”以使磁盘恢复为主机操作系统的联机状态。 。

将驱动器添加到虚拟机 (Adding the Drive to the Virtual Machine)

Once the disk is offline to the host operating system it’s time to add the disk to the virtual machine within Hyper-V. Launch Hyper-V and, from your Virtual Machines list, select the machine you wish to pass the hard disk through to.

一旦磁盘脱离主机操作系统,就可以将磁盘添加到Hyper-V中的虚拟机了。 启动Hyper-V,然后从“虚拟机”列表中选择要将硬盘传递到的计算机。

hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

Right click on the machine and select “Settings…”

右键单击机器,然后选择“设置…”

hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

From within the Settings menu for that specific virtual machine, select “SCSI Controller” from the left hand navigation pane. Select “Hard Drive” and click the “Add” button.

从该特定虚拟机的“设置”菜单中,从左侧导航窗格中选择“ SCSI控制器”。 选择“硬盘驱动器”,然后单击“添加”按钮。

Note: We’ve presumed you wish to pass the hard drive through to the virtualized operating system which means you already have a SCSI controller and virtual disk for the OS. If you do not yet have a SCSI controller you will need to first select “Add Hardware” at the top of the navigation pane and add a “SCSI Controller” to your virtual machine.

注意:我们假设您希望将硬盘驱动器传递给虚拟化操作系统,这意味着您已经具有用于操作系统的SCSI控制器和虚拟磁盘。 如果您还没有SCSI控制器,则需要首先选择导航窗格顶部的“添加硬件”,然后将“ SCSI控制器”添加到您的虚拟机。

hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

Select “Physical hard disk” and then, from the drop down menu, select the disk you brought offline in the previous section of the tutorial. Don’t worry there’s no chance you’ll accidentally select a disk from the host machine that you didn’t intend to use. The only disks you can select in the physical hard disk menu are disks that are powered and attached to the host machine but in an offline state. If you didn’t put it offline it isn’t even an option.

选择“物理硬盘”,然后从下拉菜单中选择您在本教程的上一节中脱机的磁盘。 不用担心,您不会从主机上意外选择不打算使用的磁盘。 您只能在物理硬盘菜单中选择的磁盘是已通电并已连接到主机处于脱机状态的磁盘。 如果您不将其置于离线状态,则什至无法选择。

Confirm the disk selected is the disk you want. Press the “Apply” button and then “OK”. Boot up your virtual machine.

确认选择的磁盘是所需的磁盘。 按“应用”按钮,然后按“确定”。 启动您的虚拟机。

访问直通硬盘 (Accessing Your Passthrough Hard Disk)

In the vast majority of cases the disk should be automatically detected by the host operating system as if it was simply a physical disk attached to the real machine the virtual machine is emulating.

在大多数情况下,主机操作系统应自动检测磁盘,就好像它只是虚拟机正在模拟的连接到真实计算机的物理磁盘一样。

You can see in the case of the screenshot below we booted up into a virtual machine to test an image restore procedure using Windows PE and Macrium Reflect. Windows PE automatically detected and mounted the disk without a hitch.

您可以在下面的屏幕截图中看到我们已启动到虚拟机中,以使用Windows PE和Macrium Reflect测试映像还原过程。 Windows PE会自动检测并顺利安装磁盘。

hyper-v虚拟机驱动_如何在Hyper-V虚拟机中访问本地和USB硬盘驱动器

If the disk isn’t immediately accessible to the virtual machine operating system you may need to open up, in the case of Windows, Disk Management and bring the disk online. When using other operating systems you’ll need to perform an equivalent action to access the disk through the virtual OS.

如果虚拟机操作系统无法立即访问该磁盘,则可能需要打开(对于Windows,是磁盘管理)并使磁盘联机。 使用其他操作系统时,您需要执行等效操作才能通过虚拟OS访问磁盘。

A very important word of caution here. The OS in the virtual machine has no idea that this disk actually belongs to your host machine and it will act upon the disk however you tell it to act upon the disk. If the disk does not automatically mount in your virtual machine OS you need to use a mounting procedure (refer to documentation for the particular OS in question) to mount the disk in the non-destructive way so that it can be returned to the host operating system later on.

这里非常重要的警告。 虚拟机中的OS并不知道此磁盘实际上属于您的主机,并且它将作用于磁盘,但是您告诉它作用于磁盘。 如果磁盘没有自动安装在虚拟机操作系统中,则需要使用安装过程(请参阅有关特定操作系统的文档)以非破坏性的方式安装磁盘,以便可以将其返回给主机系统稍后。

When you no longer need the disk in the virtual machine simply boot down the virtual machine. Do not attempt to make changes to the drive state via the host machine until you’ve turned off the virtual machine the drive is connected to.

当您不再需要虚拟机中的磁盘时,只需启动虚拟机即可。 在关闭驱动器连接到的虚拟机之前,请勿尝试通过主机更改驱动器状态。

You can outright remove the hard drive from the virtual SCSI controller in your virtual machine if you aren’t going to use it again or you can leave the entry. Any time the physical drive is disconnected from the host machine or you’ve made it online for the host operating system the drive will simply appear as unavailable to the virtual machine.

如果您不想再次使用它,则可以从虚拟机中的虚拟SCSI控制器中直接删除硬盘驱动器,或者可以保留该条目。 每当物理驱动器与主机断开连接,或者您已将其在线连接到主机操作系统时,该驱动器对于虚拟机将仅显示为不可用。

翻译自: https://www.howtogeek.com/223193/how-to-access-local-and-usb-hard-drives-in-your-hyper-v-virtual-machine/

hyper-v虚拟机驱动