Install Arch Linux on Windows 10 Hyper-V

Requirements

  • download latest Archlinux ISO Image
  • VT-x/AMD-v virtualization must be enabled in BIOS (requires machine restart)
  • Enable Hyper-V go to Windows features On or Off, you will see dialog box with a list of Windows features as shown below. Navigate to the Hyper-V section and enable it (requires machine restart).
mmc.exe virtmgmt.msc
  • Get a list of the network adapters in the host. In 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 change your -NetAdapterName to interface connected to internet.
New-VMSwitch -name ExternalSwitch  -NetAdapterName "Ethernet 3"  -AllowManagementOS $true
  • Set VM Name, Switch Name, and Installation Media Path.
  • Define Power Shell 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
Add-VMDvdDrive -VMName $VMName -ControllerNumber 0 -ControllerLocation 1 -Path $HOME\Downloads\$InstallMedia
  • Mount Installation Media
$DVDDrive = Get-VMDvdDrive -VMName $VMName
  • Configure Virtual Machine to Boot from DVD
Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive
  • Start VM
Start-VM -Name $VMName
  • Connect to the virtual machine by using Virtual Machine Connection (VMConnect).
VMConnect $HOSTNAME $VMName

Arch Linux Installation

Hyper-V is not allowing clipboard COPY/PASTE for this we will use ssh into the VM. Latest Windows 10 Fall Creators Update includes ssh client that can be installed following guide from How-To Geek.

  • Add root password
passwd
  • Allow remote ssh
systemctl start sshd
  • Find IP to connect from remote
ip a show dev eth0 | grep -w inet
  • SSH into VM from Power Shell
ssh root@IP
  • Verify if installation supports EFI
ls -la /sys/firmware/efi
  • Generate mirror list to improve installation speed
  • Visit [mirrorlist generator](https://www.archlinux.org/mirrorlist/) in the browser or another computer, generate mirrorlist
  • 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
  • Backup default mirrorlist
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bk
  • Add mirrorlist generated to /etc/pacman.d/mirrorlist
nano /etc/pacman.d/mirrorlist
  • Optional automatically scan for best mirror NOTE: this take considerable amount of time to scan all mirrors
sed -i ‘s/^#Server/Server/’ /etc/pacman.d/mirrorlist.bk
rankmirrors -n 6 /etc/pacman.d/mirrorlist.bk > /etc/pacman.d/mirrorlist
  • Example results after run
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
  • Verify the available disks
dmesg | grep sda
lsblk
  • Partition EFI
gdisk /dev/sda
  • Clear partitions
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y
  • Create EFI 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 EFI partition
mkfs.fat -F32 /dev/sda1
  • Format root partition
mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
  • Update system clock
timedatectl set-ntp true
  • Install base system
pacstrap /mnt base base-devel openssh
  • Generate fstab file
genfstab -U /mnt >> /mnt/etc/fstab
  • Chroot into newly deploy arch
arch-chroot /mnt
  • Install boot loader
bootctl install
nano /boot/loader/loader.confdefault arch
timeout 3
editor 0
  • Find /dev/sda2 root partition UUID
blkid -s PARTUUID -o value /dev/sda2
  • Note down PARTUUID nr Ex. 55523bad-38db-4e00–8cdb-d498e47f0b05
  • Optional copy configuration
cp /usr/share/systemd/bootctl/arch.conf /boot/loader/entries/nano /boot/loader/entries/arch.conftitle Arch Linux
linux /vmlinux-linux
initrd /initramfs-linux.img
options root=PARTUUID=8444d6ba-32af-415b-b148-cf4f20a04ac9 rw
  • Or you can update arch.conf
echo “options root=PARTUUID=$(blkid -s PARTUUID -o value /dev/sda2) rw” >> /boot/loader/entries/arch.conf
  • Last step is to update bootloader
bootctl update
bootctl

Arch Linux post installation configuration

  • Set shell locale(uncomment en_US.UTF-8 UTF-8)
nano /etc/locale.genen_US.UTF-8 UTF-8
  • Generate locale
locale-gen
  • Check locale setup
locale -a
localedef — list-archive
localectl list-locales
  • Edit setting for the LANG system locale
nano /etc/locale.confLANG=en_US.UTF-8
  • Or just run
localectl set-locale LANG=en_US.UTF-8
  • Time zone
ls -la /usr/share/zoneinfo/
ln -sf /usr/share/zoneinfo/Asia/Singapore /etc/localtime
hwclock — systohc
  • Set hostname
hostnamectl set-hostname Arch
  • Allow root login add the entry PermitRootLogin yes /etc/ssh/sshd_config
nano /etc/ssh/sshd_configPermitRootLogin yes
  • Enable sshd service
systemctl enable sshd.service
  • Create root login password
passwd
  • Create swap file:
fallocate -l 1G /swapfile 
chmod 600 /swapfile
mkswap /swapfile
echo ‘/swapfile none swap sw 0 0’ | tee -a /etc/fstab
  • Check swap
swapon -s
  • Check network config
ip a show
ip route show
  • use DHCP IP allocation at startup
systemctl start dhcpcd
systemctl enable dhcpcd
  • Or you can use network manager in case you want to use static ip or even dhcp
  • Use 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 static ip Ex. your Ip can be different 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
  • Check resolver configuration
cat /etc/resolv.conf
cat /run/systemd/resolve/resolv.conf
  • Add time sync systemd service
timedatectl set-ntp true 
timedatectl status
  • Exit and reboot
exit
shutdown now

Post Install VM cleanup

In Power Shell as (Administrator)

  • Change boot order for VM
$getb2 = Get-VMFirmware $VMName
$gen2.BootOrder
$gen2file = $gen2.BootOrder[0]
echo $gen2file
Set-VMFirmware -VMName $VMName -FirstBootDevice $gen2file
Get-VMFirmware $VMName
  • Remove DVD from VM with same SCSI as HDD
Get-VMDvdDrive -VMName $VMName -ControllerNumber 0 | Remove-VMDvdDrive
  • Remove DVD Scsi controler from VM
Get-VMScsiController -VMName $VMName -ControllerNumber 1 | Remove-VMScsiController
  • Start Arch VM
$VMName = ‘ArchLinux’
Start-VM -Name $VMName
  • Connect to the virtual machine by using Virtual Machine Connection (VMConnect).
VMConnect $HOSTNAME $VMName
  • Ssh into Arch VM
  • link resolver to resolv.conf
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
  • Add entry into hosts file
nano /etc/hosts127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
127.0.0.1 arch.localdomain arch
  • Install useful tools
pacman -Syyupacman -S p7zip unzip pygmentize docker vim htop git jq rsync tmux bash-completion keychain mlocate
  • Start docker daemon
systemctl enable docker 
systemctl start docker
  • Create new user
useradd -m -g users -G wheel,storage,power,docker -s /bin/bash your_userpasswd your_uservisudo%wheel ALL=(ALL) NOPASSWD: ALL
  • Add AUR package manager
nano /etc/pacman.conf[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch
pacman -Sy
  • Install yaourt tool to manage AUR packages
pacman -S yaourt
su - your_user
yaourt -Syyua
  • Install pacaur as better AUR package manager
gpg - recv-key 1EB2638FF56C0C53 
yaourt -S pacaur
pacaur -Syyua
  • Remove root ssh
sed -i ‘s/^PermitRootLogin yes/#PermitRootLogin yes/’ /etc/ssh/sshd_config
  • 1st share in Windows 10 one folder and add all needed permissions
  • On Arch Linux install SAMBA client
pacman -S cifs-utils smbclient
mkdir /etc/samba /mnt/Hyper-V
touch /etc/samba/smb.conf
  • Test connectivity
ping -c 3 $(nmblookup YOUR_PC_NAME | head -n 1 | cut -d ‘ ‘ -f 1)
  • As root user
vim ~/.credentialsusername=your_windows_login
password=windows_password
chmod 600 ~/.credentialsmount -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)”
  • Switch Network Wi-Fi/Ethernet vs Ethernet/Wi-Fi
$Switch = ‘ExternalSwitch’
Get-VMSwitch -SwitchType External
Get-NetAdapter
Set-VMSwitch $Switch -NetAdapterName “Wi-Fi”
  • Or back to Ethernet
Set-VMSwitch $Switch -NetAdapterName “Ethernet 3”

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ion Mudreac

Ion Mudreac

Bank CTO at Advance Intelligence Group