Skip to content

Instantly share code, notes, and snippets.

@chrisloweau
Last active September 21, 2017 02:56
Show Gist options
  • Save chrisloweau/a69a0e60f9bc70098bcd94ef728a14a2 to your computer and use it in GitHub Desktop.
Save chrisloweau/a69a0e60f9bc70098bcd94ef728a14a2 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Creates a Hyper-V Virtual Machine suitable for running Raspbian x86.
.DESCRIPTION
This PowerShell script creates a new Hyper-V Generation 2 Virtual Machine
that is suitable for installing and running Raspbian x86. The default
hardware configuration set by this script is as follows:
- 4 Processor Cores
- 896MB Static Memory
- 128MB RemoteFX 3D Video Adapter
- 32GB Dynamic Hard Disk
- 1 Network Adapter
In addition, a virtual DVD device is added for to the Raspbian x86
installation ISO file. Secure Boot is also disabled.
.NOTES
File Name : Raspbian_x86_Hyper-V.ps1
Author : Chris Lowe
Prerequisite : PowerShell V2
.LINK
http://www.lowefamily.com.au
http://downloads.raspberrypi.org/rpd_x86/images/
.EXAMPLE
Raspbian_Hyper-V.ps1
#>
# Adjust the following variable values as required
$VM_Name = "Raspbian-x86"
$VM_ISO = "C:\ISO\2017-06-22-rpd-x86-jessie.iso"
$VM_ProcessorCores = 4
$VM_MemorySize = 896MB
$VM_VideoSize = 128MB
$VM_DiskSize = 32GB
$VM_DiskPath = (Get-VMHost).VirtualHardDiskPath
$VM_Adapter = (Get-NetAdapter -Physical | Where-Object {$_.Status -eq 'Up'} | Sort-Object $_.LinkSpeed | Select-Object -First 1).Name
If (((Get-VMSwitch -SwitchType External).Name) -eq $null) {New-VMSwitch -Name 'External' -NetAdapterName $VM_Adapter -AllowManagementOS $true -Notes 'External Switch'}
$VM_Switch = (Get-VMSwitch -SwitchType External).Name
# Create a new Virtual Hard Disk using 1MB Block Size as per Microsoft's Recommendations
# https://technet.microsoft.com/en-us/library/dn720239.aspx
New-VHD -Path $VM_DiskPath\$VM_Name.vhdx -SizeBytes $VM_DiskSize –Dynamic –BlockSizeBytes 1MB
# Create a new Virtual Machine
New-VM -Name $VM_Name -Generation 2 -VHDPath $VM_DiskPath\$VM_Name.vhdx -SwitchName $VM_Switch
Set-VM -VMName $VM_Name -ProcessorCount $VM_ProcessorCores -StaticMemory -MemoryStartupBytes $VM_MemorySize -Notes "$VM_Name`r`nCreated:`t$((Get-Date).ToString())`r`nSource:`t$(Split-Path $VM_ISO -Leaf)"
# Add a RemoteFx 3D Video Adapter - required for GUI to start
Add-VMRemoteFx3dVideoAdapter -VMName $VM_Name
Set-VMRemoteFx3dVideoAdapter -VMName $VM_Name -VRAMSizeBytes $VM_VideoSize -MaximumResolution 1920x1200 -MonitorCount 1
# Add a virtual DVD device for the installation ISO
Add-VMDvdDrive -VMName $VM_Name -Path $VM_ISO
# Configure UEFI Firmware to disable "Secure Boot" and "Boot from DVD"
Set-VMFirmware -VMName $VM_Name -EnableSecureBoot Off -FirstBootDevice (Get-VMDvdDrive -VMName $VM_Name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment