Skip to content

Instantly share code, notes, and snippets.

@Tigermouthbear
Created November 25, 2024 21:01
Show Gist options
  • Save Tigermouthbear/7c3db9b008c8b3f28b062909e19d1702 to your computer and use it in GitHub Desktop.
Save Tigermouthbear/7c3db9b008c8b3f28b062909e19d1702 to your computer and use it in GitHub Desktop.
My notes on installing Arch Linux to second drive from WSL

Installing Arch Linux to second drive from Windows using WSL

I recently wanted to install Arch Linux onto a second drive on my Windows desktop, but didn't have a flash drive around. Eventually, I figured out how to use Windows Subsystem for Linux (WSL) instead of the installation medium to install Arch Linux on my second drive with the GRUB boot loader. I could not find any information on how to do this, so I had to figure it out mostly on my own. I wrote this guide to help anyone who wishes to try this installation method too!

Preparation

Install WSL

PowerShell (Administrator):

wsl --install

Install ArchWSL (for use as installation medium)

Follow instructions at https://github.com/yuk7/ArchWSL and make sure you have an adequate environment to work in.

Mount drive for use in WSL

PowerShell (Administrator):

wmic diskdrive list brief
wsl --mount \\.\PHYSICALDRIVE1 --bare

Replace \\.\PHYSICALDRIVE1 with correct drive from first command.

Installation

Using ArchWSL and following the ArchWiki Installation Guide, start at (1.9) Partition the disks with modifications to the following sections:

(1.10) Format the partitions

Same as normal install, but you might need to install dosfstools for Fat32. This guide is for booting in UEFI mode.

(1.11) Mount the file systems

Instead of mounting to /mnt, I recommend mounting to another location such as /home/$USER/mnt to prevent confusion with WSL.

(2.2) Install essential packages

Also install grub, os-prober, a text editor, and other necessary packages like networkmanager or another network daemon.

(3.1) Fstab

You might have to genfstab outside of chroot, then copy it manually into /etc/fstab after next step.

(3.2) Chroot

Make sure to use the mounting location you selected in (1.11).

Bootloader (GRUB)

Using ArchWSL,grub-install will fail to add the EFI entry because WSL does not contain the efivarfs kernel module. To workaround this you will need to use GRUB on Windows. Additionally, the GRUB for Windows x86_64-efi kernel has a bug which prevents it from booting (https://savannah.gnu.org/bugs/?64482), so you will need to run grub-install in ArchWSL after doing so in Windows.

Close ArchWSL and shutdown WSL

PowerShell (Administrator):

wsl --shutdown

The EFI partition you created should mount in Windows and be visible in File Explorer.

GRUB for Windows

Download latest grub-for-windows binaries from https://ftp.gnu.org/gnu/grub/ and unzip.

Install GRUB to EFI partition

PowerShell (Administrator):

.\grub-install.exe --target=x86_64-efi --efi-directory=D:\\ --bootloader-id=GRUB

Make sure --efi-directory is the EFI partition you created in the previous steps and not a Windows partition.

Remount drive for use in WSL

PowerShell (Administrator):

wsl --mount \\.\PHYSICALDRIVE1 --bare

Replace \\.\PHYSICALDRIVE1 with correct drive from previous steps.

Remount the file systems and chroot into system

Use ArchWSL and follow previous recommendations in (1.11) and (3.2).

Install and configure GRUB

This will fix the bugged GRUB kernel installed under GRUB for Windows.

grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg

Make sure --efi-directory is the EFI partition you created in the previous steps and not a Windows partition.

BIOS Settings

Close everything, reboot into BIOS, and set GRUB to be the first boot priority and disable secure boot if you have not set it up. GRUB should load and boot into Arch Linux.

Add Windows GRUB entry

It is likely that GRUB was unable to add a Windows boot entry because the Windows EFI partition is not available under WSL. To fix this, boot into the system and reconfigure GRUB to use os-prober.

Enable os-prober in GRUB config

In /etc/default/grub, uncomment:

GRUB_DISABLE_OS_PROBER=false

Mount Windows EFI partition

Mount the Windows EFI partition anywhere then run:

sudo os-prober
grub-mkconfig -o /boot/grub/grub.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment