Windows 10 + Arch Linux: a non-crappy dev environment

Enabling Hyper-V

From Turn Windows features on and off enable the Hyper-V & NFS features. NFS is used for mounting a directory from the VM later to Windows itself, to allow for editing Linux files from Windows.

Creating an Internal network switch

Ripping instructions from ArchWiki:

# Create the internal switch with a name of VM-Internal-Switch
PS C:\WINDOWS\system32> New-VMSwitch -Name "VM-Internal-Switch" -SwitchType Internal

# Verify that the internal switch was created
PS C:\WINDOWS\system32> Get-VMSwitch

# Get the ifIndex of the newly created internal switch, usually named 'vEthernet (name)'
PS C:\WINDOWS\system32> Get-NetAdapter

# Set the IP address of the internal switch, noting the ifIndex retrieved from the previous command.
# In this example, the network address of the internal switch is 192.168.56.0/24, and the ifIndex is 50.
PS C:\WINDOWS\system32> New-NetIPAddress -IPAddress 192.168.56.1 -PrefixLength 24 -InterfaceIndex 50

# The VMs using the internal switch must use static IP addresses, such as 192.168.56.2/24.
# Support for DHCP in internal switches is not included in current Windows versions (as of Version 1703, OS Build 15063).

Now, by inspecting get-netadapter you should see a new Internal switch named VM-Internal-Switch, or whatever else you chose to name it.

Setting up Internal NAT

More ripping:

# Create the NAT with IP address of the internal switch
PS C:\WINDOWS\system32> New-NetNat -Name "VM-NAT-Network" -InternalIPInterfaceAddressPrefix 192.168.56.1/24

# Verify that the NAT was created
PS C:\WINDOWS\system32> Get-NetNat

Creating your VM

I'm not going to detail this step much, basically get an ArchLinux ISO and attach the VM to the newly created Internal switch.

Installing Arch

Network

Within Live Install, the return of ifconfig will be something like:

arch-network-before-1

You'll need to statically assign an IP address to eth0 by running:

ip addr add 192.168.56.2/24 broadcast + dev eth0

Once a static IP has been assigned, you'll notice that internet connectivity still doesn't work. You need to also add a default route:

ip route add 0.0.0.0/0 via 192.168.56.1 dev eth0

Lastly, you'll also need to add a nameserver to query any domain names against:

echo "nameserver 1.1.1.1" >> /etc/resolv.conf

If all went well, you now have network connectivity:

arch-network-after

Partitioning your Disk

Partition your new disk, ensure that you have at least:

  • a swap partition
  • a data partition

Create and size these appropriately using fdisk /dev/sda. Afterwards, your configuration should look something like:

arch-disk

Assuming that your swap is /dev/sda1 and your main disk is /dev/sda2, format your disk as so:

mkfs.ext4 /dev/sda2
mkswap /dev/sda1
swapon /dev/sda1
mount /dev/sda2 /mnt

Initialize the base system

During this step, we'll bootstrap the Arch install and chroot into the install:

pacstrap /mnt base
genfstab -p /mnt >> /mnt/etc/fstab
arch-chroot /mnt

Configuring the hostname

Configure the VM's hostname:

echo "hostname.domain.tld > /etc/hostname

Configuring the timezone

Configure the VM's timezone:

ln -sf /usr/share/zoneinfo/Australia/Sydney /etc/localtime

Configuring locales

Enable en_US as a locale:

sed -i 's/#en_US/en_US/g' /etc/locale.gen
locale-gen
echo LANG=en_us.UTF-8 > /etc/locale.conf

Create init cpio & set root passwd

mkinitcpio -p linux
passwd

Install GRUB and configure boot options

pacman -Syu grub
grub-install --target=i386-pc --recheck --debug /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

Reboot your VM and, if everything went well, you should boot into Arch linux! If not, Google is your friend!

Configuring Arch

Setting up netctl

First, figure out what the interface the Hyper-V NIC is attached to. In most cases, it should be eth0.

Paste the follow config inside:

Description='Hyper-V Static NAT'
Interface=eth0
Connection=ethernet
IP=static
Address=('192.168.56.2/24')
Routes=('192.168.56.0/24 via 192.168.56.1' '0.0.0.0/0 via 192.168.56.1')
Gateway='192.168.56.1'
DNS=('1.1.1.1')

And enable it:

netctl enable eth0

Caveat emptor: For some reason I haven't been able to figure out yet, on boot the link doesn't come up, nor does the default route appear. You need to enable the link manually on boot, or through /etc/rc.local or something. Enabling the link and adding the route:

ip s l dev eth0 up
ip r a default via 192.168.56.1