/usr/etc/rahul/*

Dual Booting Windows 10 and Arch Linux

July 17, 2018 | Updated: November 12, 2018

Recently, I dual-booted my computer (Razer Blade 14" 2017, Intel 7700HQ - GTX1060) with Arch Linux, and I wanted to document the process here to make it easier for any others who are planning on a similar process. Note that this is for a UEFI machine that already runs Windows 10 (although the instructions may easily translate to some other setups).

Reading

Before beginning the dual boot process, I decided to first read about the boot process and Linux in general; although not strictly necessary, this reading was interesting and helped me understand all the steps involved in the dual boot process. I have listed some basic links I would recommend reading before, in order to get a clear understanding the boot process and related technologies.

Windows Preparation

First, just to be safe, it is important to completely back up any important files you have saved on your computer.

Then, open up Disk Management (open Command Prompt as Administrator and type in diskmgmt.msc) (see the figure below) and create space for the Linux installation. There should be at least 3 basic partitions: EFI System Partition, OEM, and Windows (the main partition that takes most of the space). In addition, there may be an extra recovery partition - beyond the first 3, you can choose whether or not to delete the extra partitions (consider the warranty and other aspects specific to your computer, I chose to leave my recovery partition). Choose the large Windows partition, right click it, and choose shrink - the amount by which you shrink is the amount of space you will have for your Linux installation. This new space will show up as unpartitioned space - this is what we want.

Disk Management

Now, we will prepare for the actual Linux boot process. First, turn off Windows Fast Startup. Then, hold down shift and press the restart button to open the troubleshooting menu. Choose Troubleshoot > Advanced Options > UEFI Firmware Settings. Then, on restart, the UEFI options will open. Disable Intel Fast Boot and Secure Boot (details here).

Installation Media

Download an Arch Linux ISO from the Downloads Page (verify the checksums, noting the Master Signing Keys). Then, download Rufus, a USB drive formatting utility (alternatively, you can use dd if you have a machine running Linux or MacOS). Get a USB drive that doesn't have any data you need (it will be wiped by the boot drive formatting process), and plug it in. Start up Rufus; it should automatically recognize the USB drive. After ascertaining that it has the correct drive, choose the Arch Linux ISO and start the format process (I also chose FAT32, the UEFI/GPT partition scheme, check device for bad blocks with 1 pass and unchecked quick format). Make sure to choose DD Image mode after choosing Start (see more here).

Booting Into Linux

Plug in the USB (the computer will not recognize it because of the DD formatting). Restart Windows, and press the correct key to go into the Boot Menu (on the Razer Blade, smash F12). In the Boot Menu, choose your USB (will show up as something relating to EFI USB). In the Arch Linux boot screen that shows up next, choose the first default option, "Arch Linux archiso x86_64 UEFI USB". Now, we are entered into an Arch Linux shell running off the USB - it will recognize the laptop's internal hard drive as an attached device.

Setting up for Install

Connect to WiFi

1
2
3
$ iw dev # Get WiFi interface name
$ wifi-menu # Open graphical interface to select WiFi network
$ ping google.com # Check connection, might take a few seconds

Create Partitions

Use lsblk -f or fdisk -l to identify the block devices. You should see at least two devices (the USB and the internal hard drive) - identify the name (e.g. /dev/sda or /dev/nvme0n1) of your internal hard drive. This is the device file where the hard drive is mounted.

We need to create 3 partitions for the Linux installation - the main filesystem, the boot partition, and the swap partition. We will now use gdisk to create the partitions:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
$ gdisk /dev/nvme0n1 # Open gdisk partitioning utility
$ n # Create new partition (for boot)
$  # Use default partition number
$  # Automatically starts at beginning of unallocated space
$ +200MB # Set space for the boot partition
$ 8300 # Hex code for Linux filesystem
$ n # Create new partition (for swap partition)
$  # Use default partition number
$  # Automatically starts at beginning of unallocated space
$ +8GB # Size of the swap partition (can also use 16 GB)
$ 8200 # Hex code for Linux swap partition
$ n # Create new partition (for filesystem)
$  # Use default partition number
$  # Automatically starts at beginning of unallocated space
$  # Use the rest of the space
$ 8300 # Hex code for Linux filesystem
$ w # Write changes
$ Y # Confirm

Now, use gdisk -l /dev/nvme0n1 to find the number of the swap partition.

Encrypt Filesystem

First, securely wipe the data on the machine to prepare for the encryption. We do this as follows (where X refers to the partition number of the partition(s) you wish to wipe (at minimum, do the main filesystem partition)).

1
2
3
4
$ cryptsetup open --type plain -d /dev/urandom /dev/nvme0n1pX to_be_wiped # opens a temporary crypt device
$ lsblk # Check that there is a crypt device under /dev/nvme0n1pX
$ dd if=/dev/zero of=/dev/mapper/to_be_wiped status=progress # Wipes the drive with /dev/zero
$ cryptsetup close to_be_wiped # Close the temporary crypt device

Now, we will encrypt the partition. See the related Arch wiki pages for details. We use X to refer to the partition number of the Linux root filesystem (third partition created above). Use this answer to choose encryption options.

1
2
3
4
5
$ cryptsetup benchmark # Choose your cipher settings
$ cryptsetup -y -v luksFormat --type luks2 /dev/nvme0n1pX # Set up cryptdevice on the partition
$ cryptsetup open /dev/nvme0n1pX cryptroot # Open the device as cryptroot
$ mkfs -t ext4 -L "Arch Linux" /dev/mapper/cryptroot # Make the filesystem on the encrypted device
$ mount /dev/mapper/cryptroot /mnt # Mount the filesystem to /mnt (/mnt is on the USB)

Now, check the mapping to make sure it works.

1
2
3
4
$ umount /mnt
$ cryptsetup close cryptroot
$ cryptsetup open /dev/nvme0n1pX cryptroot
$ mount /dev/mapper/cryptroot /mnt

Turn on Swap Partition

We refer to the swap partition created above as Y.

1
2
3
$ mkswap -L "Linux Swap" /dev/nvme0n1pY # Make the swap partition
$ swapon /dev/nvme0n1pY # Turn on the swap partition
$ free -m # Check whether swap is on

Create Boot Partition

We refer to the boot partition created above as Z.

1
2
3
4
5
6
$ mkfs -t ext4 /dev/nvme0n1pZ # Create boot partition filesystem
$ mkdir /mnt/boot # Create boot mount point
$ mount /dev/nvme0n1pZ /mnt/boot
$ mkdir /mnt/boot/efi # Create efi boot folder
$ gdisk -l # Find the partition number of the existing EFI partition (from Windows) - U
$ mount /dev/nvme0n1pU /mnt/boot/efi # Mount the EFI partition

Installing Arch Linux

Use pacstrap to install the basic system:

1
$ pacstrap /mnt base # Just install the basic set of packages

Configure the System

Create an fstab file for the system, using UUID naming:

1
$ genfstab -pU /mnt >> /mnt/etc/fstab

Make sure that /mnt/etc/fstab lists /boot and /boot/efi as filesystems. If it doesn't, you will have to add them manually, look that up online. Use ls -l /dev/disk/by-uuid/. Optionally, change relatime to noatime on SSD disks to reduce the wear and tear.

Boot into the Arch Install

Arch Linux is now completely installed on the system. We are ready to begin setting up the system directly. First, chroot into the newly installed system.

1
$ arch-chroot /mnt

Basic System Setup

First we setup the time system. Refer to Arch Wiki Time for more information.

1
2
$ ln -s /usr/share/zoneinfo// /etc/localtime # Set the local timezone
$ hwclock --systohc # Create /etc/adjtime to synchronize the hardware clock

Now, we set the locale. Uncomment en_US.UTF-8 UTF-8 in /etc/locale.gen and run

1
$ locale-gen

Then, set LANG=en_US.UTF-8 in /etc/locale.conf Now, we set the hostname with

1
$ echo MYHOSTNAME > /etc/hostname

and update /etc/hosts

1
2
3
127.0.0.1       localhost
::1             localhost
127.0.1.1       MYHOSTNAME.localdomain MYHOSTNAME # optional, as far as I can tell

See Arch network configuration for more information.

Finally, reset the root password:

1
$ passwd

Bootloader (GRUB) Setup and Initial Boot Configuration

Install the relevant packages:

1
pacman -Syu grub efibootmgr dosfstools

Now, we will make sure all of the partitions are properly mounted.

1
2
$ mount -a # Mount all of the partitions listed in fstab
$ lsblk # List block devices, and check that /, /boot, /boot/efi are listed

If they are properly mounted, we will edit /etc/mkinitcpio.conf to include relevant hooks and kernel parameters.

1
HOOKS = (... keymap encrypt filesystems keyboard ...)

We will now generate the initrd with

1
$ mkinitcpio -p linux

Now, we will setup GRUB by setting the following in /etc/default/grub (where is the UUID of the encrypted partition from ls -l /dev/disk/by-uuid/):

1
2
3
GRUB_CMDLINE_LINUX="cryptdevice=UUID=:cryptroot
GRUB_CMDLINE_LINUX_DEFAULT="quiet pci=nomsi"
GRUB_ENABLE_CRYPTODISK=y

Install GRUB and generate the config file with

1
2
$ grub-install --target=x86_64-efi --efi-director=/boot/efi --bootloader-id=grub
$ grub-mkconfig -o /boot/grub/grub.cfg # GRUB configuration

Now, install intel-ucode in order to enable Intel microcode.

1
2
$ pacman -S intel-ucode # Install relevant package
$ grub-mkconfig -o /boot/grub/grub.cfg # regenerate GRUB configuration to use intel-ucode

Also install os-prober so that Windows will be properly set in GRUB on reboot (alternatively, you could create a Windows entry in the GRUB config manually).

1
$ pacman -S os-prober

WiFi Setup

Before starting up the new machine, we will also install necessary packages to connect to WiFi on restart. We will use netctl to manage the WiFi connection. First, we install WPA Supplicant to manage secure WiFi connections.

1
2
3
4
$ pacman -S wpa_supplicant
$ cp /etc/netctl/examples/wireless-wpa /etc/netctl/wireless-wpa # copy the interface file
$ vim /etc/netctl/wireless-wpa # fill out the relevant fields
$ wpa_passphrase SSID passphrase # hash passphrase for network

Copy the psk field from the wpa_passphrase command as the Key in the wireless-wpa profile.

Finish up

Finally, unmount everything and reboot the system - go back into Arch.

1
2
3
$ exit # exit out of chroot back to the archiso 
$ umount -R /mnt # unmount all the devices
$ reboot

You will now boot directly into the Arch install (rather than the archiso on the USB). There is some basic setup remaining. First, run os-prober and update the GRUB config with

1
2
$ os-prober # detects the Windows installation and adds it to GRUB config
$ grub-mkconfig -p /boot/grub/grub.cfg

Then, make sure you can connect to WiFi with netctl.

1
2
$ sudo netctl start wireless-wpa # use the profile created above
$ ping google.com # may take a few moments

Finally, create a new (non-root) user for general use.

1
2
$ useradd -m -G wheel  # Create user
$ passwd  # Set password

You should also set up sudo and use visudo to allow the wheel group to use sudo.

Restart one more time, and make sure that Windows is listed as an option in the initial GRUB boot window. Choose to boot into it and make sure everything works. Notably, the clock will be off because of the hardware clock settings in Linux - to remedy this, see here. You will have to use regedit to add the DWORD

1
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal

with value 1 to the registry. In addition, turn off Internet time synchronization in Control Panel > Clock and Region > Date and Time > Internet Time. Reboot to put these changes into effect.

Check back for Part 2 to read about basic system configuration, including (but not limited to):

Rahul Yesantharao
  Cambridge, MA

Share this post