How to install OpenWRT on Hyper-v Virtual Machine

How to install OpenWRT on Hyper-v Virtual Machine

Yes, you can install OpenWrt on a Hyper-V virtual machine by creating a virtual disk, setting up a virtual machine, and installing the OpenWrt x86/64 image onto the virtual diskThe process involves creating the VM, attaching the virtual disk to it, configuring the necessary virtual network adapters for internet access, and then booting the VM to complete the installation. 

You need Hyper-v vm disk in VHDX format for openwrt router. We will download openwrt file for x86-64 system(if you have x86-64 system) specially openwrt-x86-64-generic-ext4-combined-efi.img.gz from OpenWRT website which is in .img format. Download file from this link. Then we need to convert it to VHDX disk format.

How to convert .img file to vhdx format disk:

There’s a program called Qemu to convert .img to vhdx and is available for Windows, Linux, and macOS. You can download from here if you are using Windows to convert.

  • Install Qemu on Windows
  • Open Powershell or Command Prompt and Run as Administrator.
  • Change directory to qemu’s directory (i.e; c:\program files\qemu)
  • Run the following command (if you are in command prompt):

qemu-img convert -p -f raw -O vhdx -o subformat=dynamic path…/file-to-convert.img path…/file-to-save.vhdx

Explanation:
-f raw: Specifies the input format. Since .img files are often raw disk images, raw is a common and usually correct format to specify for the input.

-O vhdx: Specifies the output format as VHDX.

input.img: The name of your source .img file.

output.vhdx: The desired name for your converted VHDX file.

Optional considerations:

Subformat (dynamic/fixed): You can also specify the subformat for VHDX (dynamic or fixed) using the -o option:

qemu-img convert -f raw -O vhdx -o subformat=dynamic input.img output.vhdx

This creates a dynamically expanding VHDX. Change dynamic to fixed for a fixed-size VHDX.

Input format inference: If you omit the -f flag, qemu-img will attempt to infer the input format, but explicitly stating it is generally recommended for clarity and reliability.

Here are the general steps to install OpenWrt on a Hyper-V VM: 
  1. 1. Prepare the Virtual Disk:
    • Use Hyper-V PowerShell to create a new virtual disk (e.g., New-VHD -SizeBytes 1GB E:\VMs\OpenWrt.vhdx). 
    • Alternatively, you can use the dd command to write an OpenWrt x86/64 image directly to this VHDX file. 
  2. 2. Create the Virtual Machine:
    • In Hyper-V Manager, create a new virtual machine. 
    • Use Generation 2 for modern OpenWrt images, which support UEFI, and disable dynamic memory. 
    • Connect the primary virtual network adapter to your desired LAN virtual switch. 
  3. 3. Configure Network Adapters:
    • Add a second network adapterfor the WAN connection and connect it to an appropriate virtual switch that provides internet access. 
    • For each network adapter in the VM settings, go to Advanced Features and enable MAC Address Spoofing. 
    • Disable Secure Bootin the VM’s settings. 
  4. 4. Install OpenWrt:
    • Start the new virtual machine. 
    • If prompted, follow the on-screen instructions to complete the OpenWrt installation from the virtual disk you prepared. 
  5. 5. Access OpenWrt:
    • Once installed, you can connect to the OpenWrt router’s web interface (LuCI) via its IP address (e.g., http://192.168.1.1) or SSH into the virtual machine to configure it further. 

Leave a Reply

0
    0
    Your Cart
    Your cart is emptyReturn to Shop