3

在 Hyper-V VM 與 Host 間複製檔案

 2 years ago
source link: https://blog.darkthread.net/blog/copy-files-between-hyperv-vm-host/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在 Hyper-V VM 與 Host 間複製檔案

calendar.svg 2021-11-25 11:00 PM comment.svg 0 eye.svg 1,235

將 Host 檔案傳到 Hyper-V VM 對我來說一直是件麻煩事,我唯一會用的招式是設定讓 Host 跟 VM 網路相通,把 VM 當成網路上的主機,在遠端桌面登入時分享本地磁碟,或透過網路資料夾交換檔案。理論上應該有更簡單不用透過網路不必設權限的做法,但我一直沒花時間研究,就只會笨方法,今天來做個了結。

有個超簡單做法近在眼前。

Windows 8.1、Windows 2012R2 之後,Hyper-V 虛擬機器連線可支援「加強的工作階段模式 (Enhanced Session Mode)」,跟網路遠端桌面登入一樣可共用本機磁碟:

設定好連上 VM 後,在 VM 我的電腦便會出現共用的磁碟機,跟遠端桌面一樣,但優點是沒網路也能用:

然後 Enhanced Session Mode 還有一招更簡單的做法 - 複製、貼上,連磁碟機共用都省了:

【補充】共用本機資源有以下前題:

  1. Hyper-V Host 需啟用 Enhanced Session Mode
  2. VMConnect 客戶端需為 Windows 8.1/10/2012R2/2016 以上版本
  3. VM 需啟用遠端桌面服務

除了 GUI 操作,有個 PowerShell 指令 Copy-VMFile 能將本機檔案複製到 VM 的指定路徑,或將 VM 檔案複製到 Host,雖然一次只能複製一個檔案,但可由 Host 端發動是一大優點,而且一樣不需要網路,可透過程式自動化或批次執行,能解決一些特殊情境的需求:

除此之外,關閉 VM,將其 vhd 掛成 Host 的本機磁碟也勉強算是一種解法,但用起來沒那麼方便。

學會這些,以後要在 Hyper-V VM 跟 Host 間搬檔案就不用再傷腦筋了。

【參考資料】

and has 0 comments

Comments

Be the first to post a comment

Post a comment

Comment
Name Captcha 47 + 15 =

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK