DEV Community

Ava Parker
Ava Parker

Posted on

Venture into a World of Dual Operating Systems: Arch Linux and Windows 10 Unite on Hyper-V Virtualization

Recently, I treated myself to a sleek Microsoft Surface Book 2, packed with impressive features, including a detachable screen. As my previous laptop and current desktop both run Arch Linux as their primary operating system, I'm accustomed to the flexibility it offers. The majority of my work takes place within the IDE Visual Studio Code or shell. Although VCS functions flawlessly on Windows 10, I'm reluctant to invest excessive time in PowerShell and WSL, which doesn't provide the ideal working environment for me.

I decided to set up Arch Linux on a Windows Hyper-V virtual machine to cater to my bash needs, as I'm still undecided about completely replacing Windows as the main desktop on my Surface Book 2. I'm particularly fond of the detachable screen and Windows 10's face authentication, as well as the VR kit. Perhaps, in the near future, I'll embark on a dual-boot adventure, running Arch Linux alongside Windows 10 on Hyper-V, as seen in this comprehensive guide: https://t8tech.com/it/coding/embark-on-a-dual-boot-adventure-running-arch-linux-alongside-windows-10-on-hyper-v/.

This in-depth guide will walk you through the process of installing Arch Linux on Windows 10.

Preliminary Requirements

  • Download the latest Archlinux ISO Image to $HOME\Downloads\
  • VT-x/AMD-v virtualization must be enabled in BIOS (requires machine restart)
  • Enable Hyper-V: navigate to Windows features On or Off, and you'll see a dialog box with a list of Windows features, as shown below. Proceed to the Hyper-V section and enable it (requires machine restart).Image title

Hyper-V Installation

Hyper-V has been an integral part of Windows since Windows Server 2008, as well as Windows 8, 8.1, and 10 in the Pro versions. It can be enabled from the Control Panel at “Turn Windows features on or off” under “Programs and Features.” Activate the “Hyper-V” checkbox, apply the change, and follow the on-screen instructions.

Network Configuration

First, you must configure a new virtual switch to enable your virtual machine to connect to the Internet. Once Hyper-V is enabled, launch the Hyper-V Manager.

Configuration can be done via the GUI by opening Power Shell as Administrator and running Hyper-V Manager:

mmc.exe virtmgmt.msc

Alternatively, we can leverage PowerShell exclusively for the remainder of the configurations.

Configuring External Switch

Using PowerShell (run as Administrator)

  • Obtain a list of the network adapters in the host. On a laptop, you should typically see “Ethernet” and “Wi-Fi.”
Get-NetAdapter
  • Create the external switch with a name of VM-External-Switch, bound to the network adapter named Wi-Fi retrieved from the previous command. You may need to modify your -NetAdapterName to interface connected to the internet.
New-VMSwitch -name ExternalSwitch  -NetAdapterName "Ethernet 3"  -AllowManagementOS $true

Creating Virtual Machine in Hyper-V

  • Specify VM Name, Switch Name, and Installation Media Path.
  • Define PowerShell variables
$VMName = ‘ArchLinux’
$Switch = ‘ExternalSwitch’
$InstallMedia = ‘archlinux-2018.05.01-x86_64.iso’
$VMPath = ‘C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\’
$HOSTNAME = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
  • Create New Virtual Machine
New-VM -Name $VMName -MemoryStartupBytes 4GB -Generation 2 -NewVHDPath “$VMPath\$VMName.vhdx” -NewVHDSizeBytes 128GB -Path “$VMPath” -SwitchName $Switch
  • Optional Disable Hyper-V checkpoint
Set-VM -Name $VMName -CheckpointType $false
  • Add additional CPU to created VM
Set-VMProcessor $VMName -Count 4
  • Disable Dynamic RAM allocation in Hyper V
Set-VMMemory $VMName -DynamicMemoryEnabled $false
  • Disable secure boot functionality on the virtual machine
Set-VMFirmware $VMName -EnableSecureBoot Off
  • Add DVD Drive to existing SCSI Controller
Mount-VirtualDVDDrive -VirtualMachineName $VMName -ControllerNumber 0 -ControllerLocation 1 -Path $HOME\Downloads\$InstallMedia
  • Mount the Installation Media Disk
$DVDDrive = Get-VirtualDVDDrive -VirtualMachineName $VMName
  • Configure the Virtual Machine to Boot from the DVD Drive
Set-VMFirmware -VirtualMachineName $VMName -FirstBootDevice $DVDDrive
  • Launch the Virtual Machine
Start-VM -Name $VMName
  • Establish a Connection to the Virtual Machine using Virtual Machine Connection (VMConnect)
VMConnect $HOSTNAME $VMName

Arch Linux Installation Process

Since Hyper-V does not allow clipboard copying and pasting, we will utilize a Secure Shell (SSH) to access the VM. The latest Windows 10 Fall Creators Update includes an SSH client that can be installed by following the guide from How-To Geek.

Once in the Hyper-V Arch shell,

  • Assign a Root Password for Security
passwd
  • Enable Remote SSH Access for Convenience
systemctl start sshd
  • Determine the IP Address for Remote Connection
ip a show dev eth0 | grep -w inet
  • Establish an SSH Connection to the VM from PowerShell
ssh root@IP

Arch Installation Check and Initial Configuration

  • Verify EFI Installation Support for Compatibility
ls -la /sys/firmware/efi
  • Generate a Mirror List to Enhance Installation Speed
  • Visit the mirrorlist generator in a browser or another computer; generate a mirror list.
  • Example mirrors in Singapore:
Server = http://mirror.nus.edu.sg/archlinux/$repo/os/$arch
Server = https://mirror.0x.sg/archlinux/$repo/os/$arch
Server = https://download.nus.edu.sg/mirror/arch/$repo/os/$arch
Server = https://sgp.mirror.pkgbuild.com/$repo/os/$arch
Server = http://download.nus.edu.sg/mirror/arch/$repo/os/$arch
Server = http://mirror.0x.sg/archlinux/$repo/os/$arch
  • Preserve a duplicate of the default mirrorlist
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bk
  • Integrate the generated mirrorlist into /etc/pacman.d/mirrorlist
nano /etc/pacman.d/mirrorlist
  • Optional: automatically locate the optimal mirror. Note: this process consumes a considerable amount of time to scan all mirrors.
sed -i ‘s/^#Server/Server/’ /etc/pacman.d/mirrorlist.bkrankmirrors -n 6 /etc/pacman.d/mirrorlist.bk > /etc/pacman.d/mirrorlist
  • Example results after execution:
Server = http://mirror.0x.sg/archlinux/$repo/os/$arch
Server = http://download.nus.edu.sg/mirror/arch/$repo/os/$arch
Server = http://mirror.nus.edu.sg/archlinux/$repo/os/$arch
Server = http://mirrors.evowise.com/archlinux/$repo/os/$arch
Server = http://f.archlinuxvn.org/archlinux/$repo/os/$arch
Server = http://mirror2.totbb.net/archlinux/$repo/os/$arch

Configuring Storage

  • Verify the availability of disk drives
dmesg | grep sdalsblk
  • Partition the EFI system
gdisk /dev/sda
  • Remove existing partitions
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y
  • Create an EFI system partition
Command (? for help): n
Partition number (1–128, default 1):
First sector (34–268435422, default = 2048) or {+-}size{KMGTP}:
Last sector (2048–268435422, default = 268435422) or {+-}size{KMGTP}: +512M
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300): EF00
Changed type of partition to ‘EFI System’
  • Create root partition
Command (? for help): n
Partition number (2–128, default 2):
First sector (34–268435422, default = 1050624) or {+-}size{KMGTP}:
Last sector (1050624–268435422, default = 268435422) or {+-}size{KMGTP}:
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to ‘Linux filesystem’
  • Verify partitions before writing
Command (? for help): p
Disk /dev/sda: 268435456 sectors, 128.0 GiB
Model: Virtual Disk
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 7A0873FE-EA25–4CC1–8543–1559F4861C2B
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 268435422
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number Start (sector) End (sector) Size       Code  Name
1      2048           1050623      512.0 MiB  EF00  EFI System
2      1050624        268435422    127.5 GiB  8300  Linux filesystem
  • Write to the disk changes
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.

Format Partitions

  • Format EFI partition
mkfs.fat -F32 /dev/sda1
  • Format root partition
mkfs.ext4 /dev/sda2

Mounting the Partition

mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot

Initiating the Installation Process

  • Synchronizing the System Clock
timedatectl set-ntp true
  • Deploying the Base System
pacstrap /mnt base base-devel openssh
  • Generating the Filesystem Table
genfstab -U /mnt >> /mnt/etc/fstab
  • Changing Root into the Newly Deployed Arch
arch-chroot /mnt
  • Installing the Boot Loader
bootctl install

Configuring the bootctl Loader

nano /boot/loader/loader.conf

default arch
timeout 3
editor 0
  • Identifying the /dev/sda2 Root Partition UUID
blkid -s PARTUUID -o value /dev/sda2

Note down the PARTUUID number, e.g., 55523bad-38db-4e00–8cdb-d498e47f0b05

  • Optional Configuration Duplication
cp /usr/share/systemd/bootctl/arch.conf /boot/loader/entries/


nano /boot/loader/entries/arch.conf

title Arch Linux
linux /vmlinux-linux
initrd /initramfs-linux.img
options root=PARTUUID=8444d6ba-32af-415b-b148-cf4f20a04ac9 rw
  • Alternatively, Updating arch.conf
echo “options root=PARTUUID=$(blkid -s PARTUUID -o value /dev/sda2) rw” >> /boot/loader/entries/arch.conf
  • The Final Step: Updating the Bootloader
bootctl update
bootctl

Post-Installation Configuration for Arch Linux

  • Setting the Shell Locale (Uncomment en_US.UTF-8 UTF-8)
nano /etc/locale.gen

en_US.UTF-8 UTF-8
  • Generating the Locale
locale-gen
  • Verifying the Locale Setup
locale -a
localedef — list-archive
localectl list-locales
  • Editing the LANG System Locale Settings
nano /etc/locale.conf

LANG=en_US.UTF-8
  • Alternatively, you can simply execute
localectl set-locale LANG=en_US.UTF-8
  • Configuring the time zone
ls -la /usr/share/zoneinfo/
ln -sf /usr/share/zoneinfo/Asia/Singapore /etc/localtime
hwclock — systohc
  • Defining the hostname
hostnamectl set-hostname Arch
  • Enabling root login by adding the entry PermitRootLogin yes to /etc/ssh/sshd_config
nano /etc/ssh/sshd_config

PermitRootLogin yes
  • Activating the SSHD service
systemctl enable sshd.service
  • Setting a root login password
passwd
  • Creating a swap file:
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
echo ‘/swapfile none swap sw 0 0’ | tee -a /etc/fstab
  • Verifying swap configuration
swapon -s
  • Examining network configuration
ip a show
ip route show
  • Enabling DHCP IP allocation at system startup
systemctl start dhcpcd
systemctl enable dhcpcd
  • Alternatively, you can utilize network manager for static IP or DHCP setup
  • Configuring network manager with DHCP or static IP setup
nano /etc/systemd/network/20-wired.network

[Match]
Name=eth0
[Network]
DHCP=ipv4

systemctl enable systemd-networkd
  • Or, with a static IP, your IP address may differ from the one shown by ip a show
nano /etc/systemd/network/20-wired.network

[Match]
Name=eth0
[Network]
Address=192.168.1.21/24
Gateway=192.168.1.1
DNS=1.1.1.1
DNS=1.0.0.1

systemctl enable systemd-networkd
systemctl enable systemd-resolved
  • Configuring the resolver
cat /etc/resolv.conf
cat /run/systemd/resolve/resolv.conf
  • Configure time synchronization using systemd service
timedatectl set-ntp true
timedatectl status
  • Exit and reboot the system
exit
shutdown now

Post-Installation VM Cleanup

In PowerShell, as an Administrator:

  • Modify the boot order for the virtual machine
$getb2 = Get-VMFirmware $VMName
$gen2.BootOrder
$gen2file = $gen2.BootOrder[0]
echo $gen2file
Set-VMFirmware -VMName $VMName -FirstBootDevice $gen2file
Get-VMFirmware $VMName
  • Remove the DVD drive from the VM with the same SCSI as the HDD
Get-VMDvdDrive -VMName $VMName -ControllerNumber 0 | Remove-VMDvdDrive
  • Remove the DVD SCSI controller from the VM
Get-VMScsiController -VMName $VMName -ControllerNumber 1 | Remove-VMScsiController

Final Touches for Arch Linux

Let’s initiate our new Arch Linux and install some essential tools:

  • Start the Arch VM
$VMName = ‘ArchLinux’
Start-VM -Name $VMName
  • Connect to the virtual machine using Virtual Machine Connection (VMConnect)
VMConnect $HOSTNAME $VMName

Establish an SSH connection to the Arch VM:

  • Link the resolver to resolv.conf
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
  • Add an entry to the hosts file
nano /etc/hosts

127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
127.0.0.1 arch.localdomain arch
  • Install essential tools
pacman -Syyu
pacman -S p7zip unzip pygmentize docker vim htop git jq rsync tmux bash-completion keychain mlocate
  • Launch the Docker daemon
systemctl enable docker
systemctl start docker
  • Set up a new user profile
useradd -m -g users -G wheel,storage,power,docker -s /bin/bash your_user
passwd your_user
visudo
%wheel ALL=(ALL) NOPASSWD: ALL
  • Integrate the AUR package manager
nano /etc/pacman.conf

[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch

pacman -Sy
  • Install the yaourt tool for AUR package management
pacman -S yaourt
su - your_user
yaourt -Syyua
  • Install pacaur as a superior AUR package manager
gpg - recv-key 1EB2638FF56C0C53
yaourt -S pacaur
pacaur -Syyua

Disable root SSH access

sed -i ‘s/^PermitRootLogin yes/#PermitRootLogin yes/’ /etc/ssh/sshd_config

Share folders and files between VM and host OS

  • Initially, share a folder in Windows 10 and assign necessary permissions
  • On Arch Linux, install the SAMBA client
pacman -S cifs-utils smbclient
mkdir /etc/samba /mnt/Hyper-V
touch /etc/samba/smb.conf
  • Verify connectivity
ping -c 3 $(nmblookup YOUR_PC_NAME | head -n 1 | cut -d ‘ ‘ -f 1)
  • As the root user:
vim ~/.credentials
username=your_windows_login
password=windows_password
chmod 600 ~/.credentials
mount -t cifs //YOUR_PC_NAME/Hyper-V-Share /mnt/Hyper-V -o credentials=~/.credentials,ip=”$(nmblookup YOUR_PC_NAME | head -n 1 | cut -d ‘ ‘ -f 1)”

In certain scenarios, when using Windows Ethernet and WiFi, your VM needs to be aware.

In PowerShell as (Administrator):

  • Toggle the Network Wi-Fi/Ethernet vs Ethernet/Wi-Fi
$NetworkToggle = ‘PeripheralSwitch’
Get-VMSwitch -SwitchType Peripheral
Get-NetAdapter
Set-VMSwitch $NetworkToggle -NetAdapterName “Wireless”
  • Alternatively, revert to a wired connection
Set-VMSwitch $NetworkToggle -NetAdapterName “Ethernet 3”

In my ideal setup, I utilize custom-configured files, including .bashrc, vimrc, and .tmux.conf, which are carefully tailored to meet my specific requirements. These can be accessed on GitHub.

Top comments (0)