Run Linux on Windows using Hyper-V

Create a linux VM on windows using hyper-v

view on github

Create a Linux Debian virtual machine using Windows Hyper-V

Table of contents

  1. Hyper-V configuration
  2. Debian VM installation
  3. Configure SSH access
  4. Install additional software

Hyper-V virtual machine configuration

Create a new virtual hard disk

  • Create a dynamic vhdx file to use as a block device in linux.
  • As per the official microsoft recommendations :
    • BlockSizeBytes at disk creation should be 1MiB (from the default 32MiB).
    • The root partition for the linux host should be created using ext4.
    • The number of block groups should be set to 4096: mkfs.ext4 -G 4096 /dev/sdb.
New-VHD -Path "D:\myDebianHost\myBlockDevice.vhdx" -SizeBytes 20GB -Dynamic -BlockSizeBytes 1MB

Create a new virtual machine

  • Create a new virtual machine in the Hyper-V manager.
  • Select the following values when prompted during the virtual machine creation :
setting value
Name myDebianHost
Directory D:\myDebianHost\myVirtualMachine
Generation Generation 2 for UEFI boot support
Ram 2048 MiB static memory
Networking localSwitch to connect to same subnet as the host
Hard disk Select existing D:\myDebianHost\myBlockDevice.vhdx

Set virtual machine options

  • Once created, right click on myDebianHost, select "properties" and configure as folows :
property action
Hardware / security Disable secure boot
Hardware / processor Allocate 2 vCPUs
Hardware / SCSI controller Add a virtual DVD player
Hardware / BIOS Boot from virtual DVD player
Management / checkpoints Disable checkpoints
Management / auto start Disable auto
Management / auto stop Save VM state in memory
  • Download the Debian ISO installer: debian-13.0.0-amd64-netinst.iso.
  • Make sure the host system architecture (amd64 here) matches the downloaded installer.
  • Edit virtual machine properties and set up the virtual DVD player to use the ISO installer.
  • The other options can be left as default.

Debian VM installation

  • The newly created VM can now be started to proceed with the installation.
  • At startup, select "Advanced options / expert install" and choose the following options when prompted :

Choose language

  • Select language : English.
  • Select location : Other / Europe / France.
  • Configure locales : en_US.UTF-8, ignore additional locales.

Configure the keyboard

  • Keymap to use : french.

Detect and mount installation media

  • Validate installer detection and continue.

Load installer components from installation media

  • Leave defaults and continue.

Detect network hardware

  • Auto-performs detection.

Configure the network

  • Select "auto-configuration" and enter a timeout for network detection.
  • Once detected, enter the following values :
    • hostname : mydebianhost.
    • domain name : my.domain.

Set up users and passwords

  • Allow login as root : no.
  • New user full name : My Admin User.
  • New user username : myadminuser.
  • New user password : password.

Configure the clock

  • Set the clock using NTP.
  • Leave default NTP server: 0.debian.pool.ntp.org.
  • Select time zone : Europe/Paris.

Detect disks

  • Auto-performs detection.

Partition disks

  • Choose "Guided - use entire disk".
  • Select detected disk : SCSI1 (0,0,0) (sda) - 21.5 GB Msft Virtual Disk.
  • Select "All files in one partition".
  • Validate the results, then write changes to disk :
SCSI1 (0,0,0) (sda) - 21.5 GB Msft Virtual Disk
               1.0 MB      FREE SPACE
      #1       1.0 GB  f   ESP             /boot/efi
      #2      19.3 GB  f   ext4            /
      #3       1.1 GB  f   swap            swap
               1.0 MB      FREE SPACE

Install the base system

  • Auto-installs core packages.
  • Kernel to install : linux-image-6.12.38+deb13-amd64 (can very depending on host architecture).
  • Drivers to include in initrd : only include drivers needed for that system.

Configure the package manager

  • Skip scanning additional media.
  • Continue without a network mirror : no.
  • Protocol for file downloads : HTTP.
  • Debian archive mirror country : France.
  • Debian archive mirror : deb.debian.org.
  • HTTP proxy information : leave blank.
  • Use non-free firmware : yes.
  • Use non-free software : yes.
  • Enable source repositories in apt : yes.
  • Services to use : "security updates" and "release updates".

Select and install software

  • Updates management : no automatic updates.
  • Participate in the user package survey : no.
  • Choose software to install :
    • SSH server.
    • Standard system utilities.

Install the GRUB boot loader

  • Force GRUB installation to the EFI removable media path : yes.
  • Update NVRAM variables to automatically boot into Debian : yes.
  • Run os-prober automatically to detect and boot other OSes : no.

Finish the installation

  • Is the system clock set to UTC : yes.
  • Installation is now complete and the system can be rebooted.

Configure SSH access

  • Create a key pair using a supported public key algorithm.
  • Use ssh-copy-id to copy the public key to the VM and authorize it for SSH access :
# open a session on the new system using ssh
ssh myadminuser@192.168.1.11

# copy file to remote SSH server
scp ~/test.txt myadminuser@192.168.1.11:/home/myadminuser/test.txt.copied

# copy and authorize user public key to access new host
ssh-copy-id -i ~/.ssh/myadminuser.pub myadminuser@192.168.1.11
  • Optionally, SSH password-based authentication can now be disabled for added security.

Install additional software

  • Install packages that are always useful to have on a linux system :
# policy management
# system monitoring (most to least relevant)
# git
# network utilities
# encryption
# archive management
# shell utilities
# editors
# man pages
# shell linter
# miscellaneous (plus cool stuff)

sudo apt-get install --no-install-recommends \
polkitd pkexec \
procps htop iftop psmisc time iotop sysstat \
git \
iproute2 nmap mtr wget curl \
pgpdump \
zip unzip \
bash-completion tree tmux dos2unix \
vim vim-common vim-runtime \
man-db \
shellcheck \
jq cowsay cowsay-off display-dhammapada

  • You now have a minimal but complete Linux host running in the windows hypervisor, which makes wsl irrelevant.