Skip to content

Instantly share code, notes, and snippets.

@addohm
Forked from shimeoki/dual-boot.md
Created June 6, 2025 04:16
Show Gist options
  • Select an option

  • Save addohm/d740ec1b3508bce08c1327c6fc1cdadf to your computer and use it in GitHub Desktop.

Select an option

Save addohm/d740ec1b3508bce08c1327c6fc1cdadf to your computer and use it in GitHub Desktop.

Revisions

  1. @shimeoki shimeoki revised this gist Feb 23, 2025. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    [This gist](https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6) was very helpful to me and I wanted to write my own version with a dual-boot setup.

    - **Full title:** Windows 11 + Arch Linux dual-boot (systemd-boot) installation guide with encrypted partitions (BitLocker and LUKS respectively) and Secure Boot (UEFI)
    - **Version:** 2.1.2 (2024-12-05)
    - **Version:** 2.1.3

    The previous version (let's call it as v1.1.0 or just v1) was written by me a long time ago. I wanted to follow my own guide to check it's integrity and validity, and rewrite it along the way.

    @@ -139,7 +139,7 @@ This setup:
    >
    > Check your device for any operating system compatibility issues. It could be anything, but usually drivers.
    In my case, I'm using a "HUAWEI MateBook D 15 BoM-WFQ9" laptop, and sound from speakers or wired headphones doesn't work under Linux (Windows works fine). It seems that the kernel doesn't support the audio card.
    In my case, I'm using a "HUAWEI MateBook D 15 BoM-WFQ9" laptop. At one point, the speakers didn't work under Linux (Windows was fine), and only Bluetooth headphones worked. Everything is fine now.

    If possible, it's better to check for these problems beforehand, as this dual-boot setup is not so quick to deploy.

  2. @shimeoki shimeoki revised this gist Dec 5, 2024. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    [This gist](https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6) was very helpful to me and I wanted to write my own version with a dual-boot setup.

    - **Full title:** Windows 11 + Arch Linux dual-boot (systemd-boot) installation guide with encrypted partitions (BitLocker and LUKS respectively) and Secure Boot (UEFI)
    - **Version:** v2.1.1 (2024-10-26)
    - **Version:** 2.1.2 (2024-12-05)

    The previous version (let's call it as v1.1.0 or just v1) was written by me a long time ago. I wanted to follow my own guide to check it's integrity and validity, and rewrite it along the way.

    @@ -985,7 +985,7 @@ mount "$MAPPED_ROOT" "$ROOT_MOUNT"
    ```sh
    umount "$ROOT_MOUNT"
    cryptsetup close "$LINUX_ROOT"
    cryptsetup open "$PART_LINUX" "$LINUX_ROOT"
    cryptsetup open "$PART_LUKS" "$LINUX_ROOT"
    mount "$MAPPED_ROOT" "$ROOT_MOUNT"
    ```
    @@ -1001,7 +1001,7 @@ export PART_ESP="$DISK"p1
    mount --mkdir "$PART_ESP" "$ROOT_MOUNT"/boot
    # same as
    mount --mkdir /dev/nvme0n1p5 /mnt/boot
    mount --mkdir /dev/nvme0n1p1 /mnt/boot
    ```
    ## Continue with the normal installation
    @@ -1072,7 +1072,7 @@ export FSTAB="$ROOT_MOUNT"/etc/fstab
    genfstab -U "$ROOT_MOUNT" >> "$FSTAB"
    # same as
    genfstab -U /mnt/etc >> /mnt/etc/fstab
    genfstab -U /mnt >> /mnt/etc/fstab
    ```
    Check the result:
  3. @shimeoki shimeoki revised this gist Oct 26, 2024. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    [This gist](https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6) was very helpful to me and I wanted to write my own version with a dual-boot setup.

    - **Full title:** Windows 11 + Arch Linux dual-boot (systemd-boot) installation guide with encrypted partitions (BitLocker and LUKS respectively) and Secure Boot (UEFI)
    - **Version:** v2.1.0 (2024-10-26)
    - **Version:** v2.1.1 (2024-10-26)

    The previous version (let's call it as v1.1.0 or just v1) was written by me a long time ago. I wanted to follow my own guide to check it's integrity and validity, and rewrite it along the way.

    @@ -609,6 +609,8 @@ You can also click "Continue with limited setup" to skip the Microsoft login.
    > ```
    >
    > This will reboot the system, and then you will be able to continue with limited setup.
    >
    > Credit: https://github.com/kaubu
    ### Normal installation once again
  4. @shimeoki shimeoki revised this gist Oct 26, 2024. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    [This gist](https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6) was very helpful to me and I wanted to write my own version with a dual-boot setup.

    - **Full title:** Windows 11 + Arch Linux dual-boot (systemd-boot) installation guide with encrypted partitions (BitLocker and LUKS respectively) and Secure Boot (UEFI)
    - **Version:** v2.0.0 (2024-09-16)
    - **Version:** v2.1.0 (2024-10-26)

    The previous version (let's call it as v1.1.0 or just v1) was written by me a long time ago. I wanted to follow my own guide to check it's integrity and validity, and rewrite it along the way.

    @@ -598,6 +598,18 @@ I recommend clicking on "I don't have internet" after setting up the layouts. Th

    You can also click "Continue with limited setup" to skip the Microsoft login.

    > [!tip]
    >
    > Sometimes this won't show, so you have to do this manually.
    >
    > Press `Shift + F10` to open a command prompt and run:
    >
    > ```powershell
    > OOBE\BYPASSNRO
    > ```
    >
    > This will reboot the system, and then you will be able to continue with limited setup.
    ### Normal installation once again
    Nothing unusual here. User, password, security questions and privacy checks. You can turn these off if you want.
  5. @shimeoki shimeoki revised this gist Sep 16, 2024. 1 changed file with 1396 additions and 333 deletions.
    1,729 changes: 1,396 additions & 333 deletions dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -1,558 +1,1621 @@
    # My Windows 11 + Arch Linux dual-boot installation
    [This gist](https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6#installing-secure-boot) was very helpful to me and I wanted to write my own version with a dual-boot setup.
    > ### Warning!
    > All actions are at your own risk!

    > [!caution]
    >
    > **All actions are at your own risk!** This has been tested by me, but does not guarantee your success.
    >
    > Read everything at least once before actually following the guide. If something goes wrong, stop immediately. Consider starting from the beginning.
    # About the guide

    [This gist](https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6) was very helpful to me and I wanted to write my own version with a dual-boot setup.

    - **Full title:** Windows 11 + Arch Linux dual-boot (systemd-boot) installation guide with encrypted partitions (BitLocker and LUKS respectively) and Secure Boot (UEFI)
    - **Version:** v2.0.0 (2024-09-16)

    The previous version (let's call it as v1.1.0 or just v1) was written by me a long time ago. I wanted to follow my own guide to check it's integrity and validity, and rewrite it along the way.

    > [!note]
    >
    > It's not recommended to follow v1, but if you want to, you can check this version - the first 3 revisions of the gist.
    This guide is more like a list of actions, and does not go into detail about the installation (although it does explain some things in general). If you want to read more, I leave reference links throughout the guide, and there are [resources](#resources) at the end.

    If you have any problems or questions, feel free to write a comment.

    # Description

    This setup:

    - Set on a laptop
    - Has **Arch Linux** installed
    - With the **LUKS** encrypted container
    - With the **zen-kernel**
    - Has **Windows 11** installed
    - With the **BitLocker** encryption
    - Uses **systemd-boot**
    - Boot partition is *not* encrypted
    - Uses **ext4** as Linux file system
    - Has *no* swap file
    - Does *not* configure the TPM module

    > [!tip]
    >
    > Skip to the parts you need in the [Table of Contents](#table-of-contents), but keep in mind that everything is done with these goals in mind.
    # Table of Contents
    - [Table of Contents](#Table-of-Contents)
    - [Hardware](#Hardware)
    - [Pre-installation](#Pre-installation)
    - [Disabling Secure Boot](#Disabling-Secure-Boot)
    - [Cleaning NVMe drive](#Cleaning-NVMe-drive)
    - [Check drives](#Check-drives)
    - [Check the available formatting methods](#Check-the-available-formatting-methods)
    - [Perform a block erase](#Perform-a-block-erase)
    - [Check completion](#Check-completion)
    - [Verify cleaning](#Verify-cleaning)
    - [Partition the disk](#Partition-the-disk)
    - [Check current partitions](#Check-current-partitions)
    - [Proceed with `fdisk`](#Proceed-with-fdisk)
    - [Create MSR partition](#Create-MSR-partition)
    - [Create root partitions](#Create-root-partitions)
    - [Change partition types](#Change-partition-types)
    - [Write changes and check](#Write-changes-and-check)
    - [Format ESP](#Format-ESP)
    - [Windows 11 installation and configuration](#Windows-11-installation-and-configuration)
    - [Install Windows 11 from .iso file](#Install-Windows-11-from-iso-file)
    - [Install browser](#Install-browser)
    - [Activate your system](#Activate-your-system)
    - [Clean your system with `winutil`](#Clean-your-system-with-winutil)
    - [Set up BitLocker](#Set-up-BitLocker)
    - [Disable fast startup and hibernation](#Disable-fast-startup-and-hibernation)
    - [Change Windows time to UTC](#Change-Windows-time-to-UTC)
    - [Connect Bluetooth devices](#Connect-Bluetooth-devices)
    - [Arch Linux installation and configuration](#Arch-Linux-installation-and-configuration)
    - [Set up LUKS on a partition](#Set-up-LUKS-on-a-partition)
    - [Open LUKS partition](#Open-LUKS-partition)
    - [Create filesystem](#Create-filesystem)
    - [Check the mapping works as intended](#Check-the-mapping-works-as-intended)
    - [Mount ESP](#Mount-ESP)
    - [Continue with normal installation](#Continue-with-normal-installation)
    - [Connect to the internet](#Connect-to-the-internet)
    - [Install essential packages](#Install-essential-packages)
    - [Generate fstab](#Generate-fstab)
    - [Change root](#Change-root)
    - [Change timezone](#Change-timezone)
    - [Generate locales](#Generate-locales)
    - [Set hostname](#Set-hostname)
    - [Set root password](#Set-root-password)
    - [Configure mkinitcpio](#Configure-mkinitcpio)
    - [Install microcode](#Install-microcode)
    - [Install boot loader](#Install-boot-loader)
    - [Configure boot loader](#Configure-boot-loader)
    - [Create Arch Linux boot entry](#Create-Arch-Linux-boot-entry)
    - [Configuration](#Configuration)
    - [Set up network](#Set-up-network)
    - [Add user](#Add-user)
    - [Install desktop environment](#Install-desktop-environment)
    - [Install `TLP`](#Install-TLP)
    - [Enabling Secure Boot](#Enabling-Secure-Boot)
    - [Bluetooth dual-boot configuration](#Bluetooth-dual-boot-configuration)
    - [Configure audio](#Configure-audio)
    - [Sync keys](#Sync-keys)
    - [Ending](#Ending)

    # Hardware
    ### HUAWEI MateBook D 15 BoM-WFQ9
    - AMD Ryzen 5 5500U
    - 16GB DDR4
    - 512GB SSD
    > ### Warning!
    > Sound from speakers or wired headphones under Linux doesn't work on this laptop. Bluetooth headphones will, however. Windows works fine.

    - [Prerequisites](#prerequisites)
    - [Required](#required)
    - [Hardware](#hardware)
    - [Software](#software)
    - [Pre-installation](#pre-installation)
    - [Quick guide for the CLI](#quick-guide-for-the-cli)
    - [Shell](#shell)
    - [Shell environment variables](#shell-environment-variables)
    - [nano](#nano)
    - [less](#less)
    - [Battery capacity](#battery-capacity)
    - [Secure Boot](#secure-boot)
    - [Preparing the disk](#preparing-the-disk)
    - [Erasing](#erasing)
    - [Check the drive name](#check-the-drive-name)
    - [Check available formatting methods](#check-available-formatting-methods)
    - [Perform a block erase](#perform-a-block-erase)
    - [Check completion](#check-completion)
    - [Verify the erase](#verify-the-erase)
    - [Partitioning](#partitioning)
    - [The plan](#the-plan)
    - [Create new table](#create-new-table)
    - [Create the partitions](#create-the-partitions)
    - [Change the partition types](#change-the-partition-types)
    - [Save and check](#save-and-check)
    - [Formatting](#formatting)
    - [Reboot](#reboot)
    - [Windows 11](#windows-11)
    - [Installation](#installation)
    - [Less bloatware](#less-bloatware)
    - [Normal installation](#normal-installation)
    - [Select the partition](#select-the-partition)
    - [Proceed with the normal installation](#proceed-with-the-normal-installation)
    - [Don't connect to the network](#dont-connect-to-the-network)
    - [Normal installation once again](#normal-installation-once-again)
    - [Configuration](#configuration)
    - [Drivers](#drivers)
    - [Activation](#activation)
    - [winutil](#winutil)
    - [Fast startup and hibernation](#fast-startup-and-hibernation)
    - [Time to UTC](#time-to-utc)
    - [Bluetooth on Windows](#bluetooth-on-windows)
    - [BitLocker](#bitlocker)
    - [Turn off](#turn-off)
    - [Arch Linux](#arch-linux)
    - [Boot from the flash drive](#boot-from-the-flash-drive)
    - [LUKS on a partition](#luks-on-a-partition)
    - [Create the LUKS container](#create-the-luks-container)
    - [Open LUKS partition](#open-luks-partition)
    - [Create filesystem](#create-filesystem)
    - [Mount root](#mount-root)
    - [Check the mapping works as intended](#check-the-mapping-works-as-intended)
    - [Mount ESP](#mount-esp)
    - [Continue with the normal installation](#continue-with-the-normal-installation)
    - [Connect to the internet](#connect-to-the-internet)
    - [Install essential packages](#install-essential-packages)
    - [Generate fstab](#generate-fstab)
    - [Change root](#change-root)
    - [Change timezone](#change-timezone)
    - [Generate locales](#generate-locales)
    - [Set hostname](#set-hostname)
    - [Set root password](#set-root-password)
    - [Configure mkinitcpio](#configure-mkinitcpio)
    - [Install boot loader](#install-boot-loader)
    - [Configure boot loader](#configure-boot-loader)
    - [Create boot entries](#create-boot-entries)
    - [Reboot](#reboot)
    - [Configuration](#configuration)
    - [Network](#network)
    - [Add user](#add-user)
    - [Secure Boot](#secure-boot)
    - [Bluetooth on Arch](#bluetooth-on-arch)
    - [Connect the devices](#connect-the-devices)
    - [Mount the USB](#mount-the-usb)
    - [Sync keys](#sync-keys)
    - [Everything else](#everything-else)
    - [Resources](#resources)

    # Prerequisites

    ## Required

    - The device you want to install on
    - The device you want to read the guide from
    - Flash drive with at least 8 GB of memory
    - Internet connection
    - Phone with a camera

    ## Hardware

    > [!warning]
    >
    > Check your device for any operating system compatibility issues. It could be anything, but usually drivers.
    In my case, I'm using a "HUAWEI MateBook D 15 BoM-WFQ9" laptop, and sound from speakers or wired headphones doesn't work under Linux (Windows works fine). It seems that the kernel doesn't support the audio card.

    If possible, it's better to check for these problems beforehand, as this dual-boot setup is not so quick to deploy.

    > [!important]
    >
    > My laptop has an AMD APU (CPU with integrated graphics), NVMe and everything else hardware specific. I will warn you in the sections where it is important not to just copy and paste.
    ## Software

    *First,* you need to **get the `.iso` files of Arch Linux and Windows 11.**

    - The preferred method of downloading Arch `.iso` is using a BitTorrent client. [Arch Linux downloads](https://archlinux.org/download/).
    - The Windows image can be created using the Media Creation Tool or downloaded directly. [Windows 11 downloads](https://www.microsoft.com/en-us/software-download/windows11/).

    In my case both images together in size are about 6 GB, so an 8+ GB flash drive is recommended.

    *Second,* you need to **create a bootable USB flash drive.**

    > [!warning]
    >
    > **Backup your data on the USB before that!**
    I use [Ventoy](https://www.ventoy.net/en/index.html). Just download the program, extract, open `Ventoy2Disk` and proceed to install Ventoy on the drive.

    > [!note]
    >
    > Ventoy can create MBR or GPT disks as you wish. It is hidden in the "Option" menu at the top. Documentation has a [dedicated page](https://www.ventoy.net/en/doc_mbr_vs_gpt.html) on this topic.
    >
    > Previously, I used MBR, and now GPT - everything is fine in both cases.
    >
    > I also recommend that you *enable* "Secure Boot Support" (should be enabled by default, just in case).
    After installation, just copy the images to the root of the flash drive.

    # Pre-installation
    #### Required:
    - PC or laptop with stable power supply
    - Ventoy flash drive with Windows 11 and Arch Linux .iso files
    - Internet (Wi-Fi)
    - Free time

    ## Disabling Secure Boot
    Simply go into your UEFI and disable Secure Boot. Otherwise you won't be able to boot from the flash drive. We'll enable it after installation.
    In my case, I have to press F2 after turning on my laptop to get into [InsydeH2O](https://en.wikipedia.org/wiki/Insyde_Software#InsydeH2O_UEFI_BIOS).
    ## Quick guide for the CLI

    ### Shell

    ## Cleaning NVMe drive
    > Documentation: [Memory cell clearing - ArchWiki](https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#NVMe_drive)
    1. To autocomplete the name of a directory, a file or a command, press Tab.
    2. To enter previous commands, press down arrow key multiple times.
    3. Ctrl + L - clear terminal.
    4. Ctrl + C - cancel the current command.
    5. Ctrl + U (at least in zsh) - cut everything before the cursor.

    Boot from your flash drive, select your Arch Linux .iso file and boot it in normal mode.
    ### Shell environment variables

    > If you see the "Perform MOK Management" window, simply select "Enroll key from disk" and select the appropriate key. You can read more [here](https://www.ventoy.net/en/doc_secure.html).
    ```sh
    export VAR=value
    # make an environment variable

    ### Check drives
    echo "$VAR"
    # print this variable to the console
    # you can use "$VAR" anywhere to shorten commands
    # you can omit the double quotes, but it's safer to do so

    # example:
    export PART_LUKS=/dev/nvme0n1p5
    cryptsetup -v luksFormat "$PART_LUKS"
    ```
    nvme list

    ### nano

    In `nano` you can move the cursor with the arrow keys and enter text like in Windows Notepad. No "Insert mode" like in Vi or Vim.

    There are other keybinds at the bottom. The most important are:

    - Ctrl + S - save
    - Ctrl + X - exit
    - Ctrl + F - search

    ### less

    Very useful terminal pager.

    Binds:

    - j / arrow down - down
    - k / arrow up - up
    - q - quit

    To view the output of the command in `less`, do the following:

    ```sh
    <command> | less
    ```
    In my case I have `/dev/nvme0`. I'll use this name in future commands.

    ### Check the available formatting methods
    ### Battery capacity

    To check the battery capacity, you can run

    ```sh
    cat /sys/class/power_supply/"$BAT"/capacity
    ```
    nvme id-ctrl /dev/nvme0 -H | grep "Format \|Crypto Erase\|Sanitize"
    ```
    In my case I have `[1:1] : 0x1 Block Erase Sanitize Operation Supported`. `Crypto Erase Sanitize` or `Overwrite Erase Sanitize` are not available for me.

    ### Perform a block erase
    > ### Warning!
    > This operation will erase all information on the drive.
    where `$BAT` is the battery directory. Usually it's `BAT0`, but but in my case it was `BAT1`.

    ## Secure Boot

    **Disable it** before installation.

    Some UEFIs have a tendency to turn it back on periodically, so I recommend *checking it every time you reboot*.

    In my case ([InsydeH20 UEFI](https://en.wikipedia.org/wiki/Insyde_Software#InsydeH2O_UEFI_BIOS)) I have to press F2 on boot to start the "Setup Utility". "Secure Boot" is in the "Security Settings" category, but this varies from UEFI to UEFI.

    ## Preparing the disk

    At this point you need to **boot from the Arch Linux image** to access the shell.

    My `systemd-boot` from the previous installation doesn't allow me to use other bootable devices except configured boot entries, so I just disabled my both entries as bootable.

    > [!warning]
    >
    > While I was booting the flash drive, I ran into [this problem](https://github.com/ventoy/Ventoy/issues/2825). It is a Ventoy bug with the Arch image, so be careful.
    >
    > I tried to use the old version of Ventoy (1.0.94) with the normal boot mode and the screen appeared. On the new version (1.0.99) the iso works in normal mode, but someone in the comments said that it's still broken.
    >
    > In any case, make sure you have the latest versions of everything, or boot in grub2 mode (I haven't tested this).
    ### Erasing

    > [!warning]
    >
    > You will have to erase your data on the device to continue. **Backup anything you might need.**
    My laptop has an NVMe drive, so I will use [nvme-cli](https://github.com/linux-nvme/nvme-cli).

    > [!note]
    >
    > Documentation: [Solid state drive/Memory cell clearing - ArchWiki](https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#NVMe_drive)
    #### Check the drive name

    ```sh
    nvme list
    ```
    nvme sanitize /dev/nvme0 -a 0x02

    > [!important]
    >
    > If you are using only one drive, it will most likely be shown as `/dev/nvme0` or `/dev/nvme0xx`. Do *not* use the `/dev/nvme0xx` syntax for the variable, only `/dev/nvme0`.
    >
    > 1. `/dev/nvme0` - drive (device) name
    > 2. `/dev/nvme0xx` - disk name (will be needed later)
    >
    ```sh
    export DRIVE=/dev/nvme0
    ```
    ### Check completion

    You can choose not to use the variable.

    #### Check available formatting methods

    ```sh
    nvme id-ctrl "$DRIVE" -H | grep -E 'Format |Crypto Erase|Sanitize'
    ```
    nvme sanitize-log /dev/nvme0

    > [!note]
    >
    > *v1* command:
    >
    > ```sh
    > nvme id-ctrl "$DRIVE" -H | grep "Format \|Crypto Erase\|Sanitize"
    > ```
    >
    > It works, but incorrectly. It doesn't show all the entries.
    If you have the
    ```sh
    [1:1] : 0x1 Block Erase Sanitize Operation Supported
    ```
    you can proceed with this operation.
    #### Perform a block erase
    > [!warning]
    >
    > **All data will be erased.**
    ```sh
    nvme sanitize "$DRIVE" -a start-block-erase
    # or
    nvme sanitize "$DRIVE" -a 0x02
    ```
    #### Check completion
    ```sh
    nvme sanitize-log "$DRIVE"
    # you can spam this command
    ```
    If the command prints
    ```sh
    Sanitize Progress (SPROG) : 65535
    Sanitize Status (SSTAT) : 0x101
    ```
    In my case it took 5-10 seconds, but [ArchWiki](https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#Sanitize_command) says that it can take for 2-3 hours. When you'll see `Sanitize Status ... 0x101` you're ready to proceed.
    ### Verify cleaning
    ```
    dd if=/dev/nvme0n1 bs=8192 status=progress | hexdump
    you are good to go. "Sanitize Status" should be equal to `0x101`.
    > [!warning]
    >
    > As [ArchWiki](https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#Sanitize_command) says, it can take a long time (2-3 hours), but in my case it took about 5-10 seconds. Still, be prepared.
    #### Verify the erase
    ```sh
    export DISK="$DRIVE"n1
    # it is probably n1, but still check
    ```
    ```sh
    dd if="$DISK" bs=8192 status=progress | hexdump
    # this command prints the contents of the drive bytes into the console
    ```
    I recommend waiting for this command to run for about 30 seconds, and if all you see is
    ```sh
    0000000 0000 0000 0000 0000 0000 0000 0000 0000
    *
    ...
    ```
    If you see ***only*** zeros, you can press Ctrl+C and you are done. If not, repeat the steps above.
    ## Partition the disk
    that's a successful sanitize.
    You can cancel the command and continue.
    ### Partitioning
    > [!note]
    >
    > Documentation: [fdisk - ArchWiki](https://wiki.archlinux.org/title/fdisk)
    ### Check current partitions
    ```
    fdisk -l /dev/nvme0n1
    ```
    As we have cleaned the drive, there should be nothing left.
    ### Proceed with `fdisk`
    ```
    fdisk /dev/nvme0n1
    ```
    ```sh
    # as a remainder:
    # DISK=/dev/nvme0n1
    fdisk -l "$DISK"
    ```
    > g # Create new GPT.
    > n # Create new partition.
    # Then skip until `Last sector,...` and enter:
    If the disk is present and is empty, we can proceed:

    > +1G # Size 1G for our EFI system partition.
    ```sh
    fdisk "$DISK"
    ```
    You can check the current partitioning with `p`.

    ### Create MSR partition
    Repeat steps above for `16M` partition.
    You can type

    ### Create root partitions
    I won't add a swap partition and will split my drive 50%/50%.
    ```sh
    m
    ```
    # Math time.
    476.94 * 1024 = 488386.56 (total MB on drive)
    488386.56 - 1016 = 487370.56 (remaining MB on drive)
    487370.56 / 2 = 243685.28 (splitted partitions in MB)
    243685.28 / 1024 = 237.97... (splitted partitions in GB)

    to view help.

    > [!note]
    >
    > Any changes you make in this program will not take effect until you save them manually with `w`. You are free to experiment as you wish.
    #### The plan

    My partitioning scheme:

    1. **EFI system partition** (ESP): *1G* (less is not recommended, but possible)
    2. **MSR partition**: *16M* (required for Windows)
    3. **Windows root partition**: ?G
    4. **Linux root partition**: ?G

    Important points:

    1. I won't use the swap partition.
    2. I will only use one partition per system. No separate one for "home".
    3. You can split the root partitions however you like. My choice is 50/50.
    4. When enabling BitLocker, Windows will automatically create the "Windows Recovery Environment" partition. You can also do this manually, but I haven't tested this.

    #### Create new table

    ```sh
    g
    # create a new empty GPT partition table
    ```
    So I'm going to divide by `238G`.
    Repeat the steps in [Proceed with `fdisk`](#Proceed-with-fdisk), but specify the size of the partitions. One will be Windows root and the other will be Arch Linux root. Create the first partition and for the second partition enter the last sector on the drive instead of the size.

    ### Change partition types
    #### Create the partitions

    Primary flow:

    ```sh
    n # create new partition
    # skip until "Last sector", defaults are ok

    # make sure that you can select one of 128 partitions,
    # otherwise you forgot to create the GPT.
    # don't ask me how I know that

    +<size> # use your needed sizes for the partitions
    ```
    > t
    > 1 # Select the first partition.
    > 1 # Change type to ESP (EFI System Partition).

    I will use the sizes in cursive from the plan as `<size>`.

    All partitions will be of type "Linux". We will configure them later.

    > [!tip]
    >
    > For the last partition, don't use the `+<size>` syntax, but just use the second number in the "Last sector" line.
    You can check the current partitions with

    ```sh
    p
    ```

    #### Change the partition types

    ```sh
    # ESP
    t
    1 # first partition
    1 # type to "EFI System"
    ```
    > t
    > 2 # Select the second partition.
    > 10 # Change type to MSR partition.

    ```sh
    # MSR
    t
    2 # second partition
    10 # type to "Microsoft reserved"
    ```

    ```sh
    # Windows root
    t
    3 # third partition
    11 # type to "Windows basic data"
    ```
    > t
    > 3 # Select the third partition.
    > 11 # Change type to Windows Basic Data.

    ```sh
    # Linux root (optional, default value is also fine)
    t
    4 # fourth partition
    23 # type to "Linux root (x86-64)"
    ```
    Last partition for Linux root can be left untouched.

    ### Write changes and check

    > [!tip]
    >
    > You can list all types with
    >
    > ```sh
    > L
    > ```
    >
    > to view with `less`.
    #### Save and check
    ```sh
    w # save and quit fdisk
    ```
    > w
    ```sh
    fdisk -l "$DISK"
    ```

    The disklabel type should be GPT and all partitions should be of the required types.

    ### Formatting

    I'm doing it just in case for the ESP, it's not necessary.

    ```sh
    mkfs.fat -F 32 /dev/nvme0n1p1
    ```
    fdisk -l /dev/nvme0n1

    The other partitions will be formatted later:

    1. Windows partitions will be formatted by the Windows installer.
    2. Linux partitions will be formatted after the Windows installation because of the LUKS encryption container.

    ## Reboot

    ```sh
    reboot
    # or
    poweroff # and boot manually
    ```
    ### Format ESP

    # Windows 11

    > [!tip]
    >
    > I recommend to **install Windows first** and Linux second.
    ## Installation

    After rebooting, select your Windows 11 `.iso` file and boot it in normal mode.

    ### Less bloatware

    > [!important]
    >
    > On the first screen select **"English (World)"** under "Time and currency format".
    You will get an `OOBEREGION` error later. It skips the region selection and the Microsoft account creation/authorization.

    If you get an "infinite" (it just takes a few minutes) loading wheel after rebooting - you got it.

    Hopefully it hasn't been patched yet.

    ### Normal installation

    > [!warning]
    >
    > I don't encourage piracy, so everything in this guide is for educational purposes only.
    Next steps:

    1. "I don't have a product key".
    2. In my case I select "Windows 11 Pro" and click "Next".
    3. Read and accept the terms to continue.

    > [!tip]
    >
    > If your mouse or touchpad doesn't work, you can use:
    >
    > - Alt + underlined key
    > - The spacebar
    > - The Tab key
    > - Shift + Tab
    > - The arrow keys
    >
    ### Select the partition

    **Most important part:**

    1. Select **"Custom: Install Windows only (advanced)"**
    2. Select your Windows root partition and click "Next"

    You should now see all your defined partitions. The Linux root partition will have 0.0 MB of "Free space" because Windows doesn't work with this type of partition.

    In my case I need the third partition. In fact, I can't select any other partitions because their types are incompatible with the installation.

    ### Proceed with the normal installation

    After a few reboots, you'll be greeted by a white screen with the Windows 11 logo.

    And if you did the trick from the [Less bloatware](#less-bloatware) chapter, you will be greeted by the spinning wheel. Wait for a bit, it's "intended" behaviour.

    After the `OOBEREGION` error, click 'Skip'.

    ### Don't connect to the network

    I recommend clicking on "I don't have internet" after setting up the layouts. The installation will be faster (as I believe) this way.

    You can also click "Continue with limited setup" to skip the Microsoft login.

    ### Normal installation once again

    Nothing unusual here. User, password, security questions and privacy checks. You can turn these off if you want.

    ## Configuration

    After a successful installation, we can configure it on the spot to avoid multiple reboots.

    ### Drivers

    Connect to the internet and use Windows Update to install the latest updates. The sound didn't work in my case without them.

    > [!important]
    >
    > I got the `0x80248007` error a couple of times. It's OK, it'll fix itself later. Just don't install failed updates.
    ### Activation

    I will use [Microsoft Activation Scripts](https://github.com/massgravel/Microsoft-Activation-Scripts).

    Run PowerShell as an administrator. The easiest way to do this is to find PowerShell in the Start menu (press the Windows/Super key) and run it as an administrator.

    ```powershell
    irm "https://get.activated.win" | iex
    ```
    mkfs.fat -F 32 /dev/nvme0n1p1

    Then follow the on-screen instructions. Just typing `1`, any key after activation and `0` to exit is fine.

    ### winutil

    In the same PowerShell instance we can run [winutil](https://github.com/ChrisTitusTech/winutil).

    ```powershell
    irm "https://christitus.com/win" | iex
    ```
    This is not necessary, but I did it anyway.

    # Windows 11 installation and configuration
    ## Install Windows 11 from .iso file
    Select your Windows 11 .iso file and boot it in normal mode.
    > If you want to get less bloatware, select `Time and currency format: English (World)` on the first screen. If you try to do this, you will get an `OOBEREGION` error later. Just skip it.
    > [!tip]
    >
    > In the "Install" section I usually install Firefox and 7-Zip: click corresponding checkboxes and "Install/Upgrade Selected". Wait until "Installation Done" at the top.
    Just do a normal install, choose custom partitioning and select the third partition. Don't do anything else on this screen, because we've done everything we need to do in [Partition the disk](#Partition-the-disk).
    Go to "Tweaks".

    ## Install browser
    After installing Windows, don't forget to install your preferred browser. In my case, I'm going to install Firefox. Just go to Microsoft Edge, skip everything, install and continue.
    I select all the "Essential Tweaks" except "Set Hibernation as default" and "Run Disk Cleanup". Also select these "Advanced Tweaks":

    ## Activate your system
    > [Microsoft Activation Scripts](https://github.com/massgravel/Microsoft-Activation-Scripts)
    - Disable Microsoft Copilot
    - Set Display for Performance
    - Set Time to UTC (Dual Boot)
    - Remove Microsoft Edge
    - Remove OneDrive

    Run Powershell as administrator:
    ```
    irm https://massgrave.dev/get | iex
    > [!caution]
    >
    > Don't remove Microsoft Edge without a new browser!
    Then "Run Tweaks" at the bottom.

    You can select all the preferences you need after the "Tweaks finished".

    > [!tip]
    >
    > In the "Config" I select the following:
    >
    > - HyperV Virtualization
    > - Disable Search Box Web Suggestions in Registry
    >
    > It's a very good program itself, so I suggest you check out the features and documentation.
    At this point, you are finished with this script. Close the PowerShell instance (not the script window).

    ### Fast startup and hibernation

    > [!note]
    >
    > Documentation: [Dual boot with Windows - ArchWiki](https://wiki.archlinux.org/title/Dual_boot_with_Windows#Windows_settings).
    You need to disable this. From the ArchWiki (sourced from superuser website):

    > Data loss can occur if Windows hibernates and you dual boot into another OS and make changes to files on a filesystem (such as NTFS) that can be read and written to by Windows and Linux, and that has been mounted by Windows. Similarly, data loss can occur if Linux hibernates, and you dual boot into another OS etc.
    > [!tip]
    >
    > `winutil` already does this, so you can skip it if you have done the necessary tweaks in the [previous chapter](#winutil).
    To do this manually:

    1. Go to "Control Panel" (Windows search)
    2. Change "View by:" to "Large icons"
    3. Go to "Power Options"
    4. Click "Choose what the power button does"
    5. Click "Change settings that are currently unavailable"
    6. Untick "Turn on fast startup" and "Hibernate"
    7. Click "Save changes"

    In my case I didn't even have these ticks, because the hibernation is disabled with `winutil` in the registry. You can check this with

    ```powershell
    powercfg /availablesleepstates
    ```

    in PowerShell.

    > [!tip]
    >
    > In the "Choose what the power button does" screen you can also change the behaviour of "When I press the power button", which is useful.
    ### Time to UTC

    > [!note]
    >
    > Documentation: [System time - ArchWiki](https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows)
    ArchWiki:

    > If multiple operating systems are installed on a machine, they will all derive the current time from the same hardware clock: it is recommended to set it to UTC to avoid conflicts across systems.
    > [!tip]
    >
    > `winutil` does this too.
    However, the manual way:

    First, you can do it with just one command:

    ```powershell
    reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal /d 1 /t REG_DWORD /f
    ```
    > 1 # Permanent HWID activation.
    > 0
    > 0

    Secondly, you can edit the registry manually:

    1. Open `regedit`
    2. `HKEY_LOCAL_MACHINE`
    3. `SYSTEM`
    4. `CurrentControlSet`
    5. `Control`
    6. `TimeZoneInformation`
    1. If `RealTimeIsUniversal` *is present,* it should be a `REG_DWORD` with data equal to `0x00000001 (1)`.
    2. *If not,* create this file by yourself with the right mouse button (RMB).

    ### Bluetooth on Windows

    > [!note]
    >
    > Documentation: [Dual boot pairing - ArchWiki](https://wiki.archlinux.org/title/Bluetooth#Dual_boot_pairing)
    It is important, because:

    > To pair devices on dual boot setups you need to change the pairing keys on your Linux install so that they are consistent with what Windows or macOS is using.
    In total, you will need to boot the system two or three times:

    1. Pair in Windows, reboot, pair in Arch and change Arch keys to the Windows keys.
    2. Pair in Windows, reboot, pair in Arch, reboot and change Windows keys to the Arch keys.

    The second method is used if the device only supports one pairing at a time. For example, my GK61XS wireless keyboard: it maps one key (as a pairing slot) to one device.

    Anyway, here is the way to manually extract the keys from Windows.

    Download [PsExec](https://learn.microsoft.com/en-us/sysinternals/downloads/psexec) and extract it to a folder of your choice.

    Copy the path of the folder in the explorer and `cd` into it:

    ```powershell
    cd C:\Users\d\Downloads\PSTools
    ```

    ## Clean your system with [winutil](https://github.com/ChrisTitusTech/winutil)
    Run Powershell as administrator:
    Run PSExec:

    ```powershell
    .\PsExec64.exe -s -i regedit.exe
    # read and agree to the terms
    ```
    irm https://christitus.com/win | iex

    > [!note]
    >
    > No, you can't just run `regedit` without PsExec. "The registry key containing the link keys may only be accessed by the [SYSTEM account](https://docs.microsoft.com/en-us/windows/security/identity-protection/access-control/local-accounts#system), which cannot be logged into." , and PsExec does this with the `-s` flag.
    In the `regedit` window, search for:

    ```powershell
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys
    ```
    Powershell will ask you to install Chocolatey. Accept and continue. Select 'Tweaks', select the profile you want and tick 'Remove Microsoft Edge' and click 'Run Tweaks'. You can now close everything.

    ## Set up BitLocker
    In Search, find "Manage BitLocker" and follow the steps to encrypt used disk space.
    You'll need a flash drive to store the recovery key file. Wait for the system to encrypt the entire system partition.
    > The system will prompt you for your BitLocker recovery key when you restart, so don't lose it!
    Select the required Bluetooth adapter. It will probably be the only one.

    All paired devices will be placed in the adapter folder.

    Pair the required device and export the key:

    1. RMB on the adapter key (folder).
    2. Export to a folder of your choice.

    > [!tip]
    >
    > I prefer to name it appropriately and move it to the flash drive. I have created a `bluetooth` folder for this purpose.
    >
    > You can pair the next device (if necessary) and do the same. Just make sure you update the registry: open the "Keys" entry and the adapter folder again.
    >
    > It's not as convenient (if you sync more than 2 devices), but it's possible to distinguish multiple devices if you save the registry file on each iteration.
    >
    > Or you can just export the hex of the keys with the MAC addresses one at a time, that works as well.
    ## Disable fast startup and hibernation
    > Documentation: [ArchWiki](https://wiki.archlinux.org/title/Dual_boot_with_Windows#Windows_settings).
    These keys will be necessary later.

    Go to "Control panel" => Change "View by:" to "Large icons" => "Power options" => "Choose what the power button does" => "Change settings that are currently unavailable" => Remove ticks on "Turn on fast startup" and "Hibernate" => "Save changes".
    ### BitLocker

    ## Change Windows time to UTC
    > Documentation: [ArchWiki](https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows).
    In Search, find "Manage BitLocker" and follow the steps to encrypt used disk space:

    You have two ways:
    1. Execute `regedit` and find `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal`. Add `DWORD` value with hexadecimal value `1`.
    2. Simply type `reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal /d 1 /t REG_DWORD /f` in Command Prompt as administrator.
    > After restarting, change the time zone and region to yours in Settings.
    1. "Turn on BitLocker"
    2. Skip until the recovery key back up
    3. Save the key to the flash drive (e.g. make the `bitlocker` folder)
    4. "Encrypt used disk space only ..."
    5. "New encryption mode ..."
    6. You can decide to not select "Run BitLocker system check". Otherwise you will have to reboot.
    7. Wait until the "BitLocker Encrypting" changes to "BitLocker on"

    ## Connect Bluetooth devices
    If you plan to use a Bluetooth headphones (as in my case), pair it now and check the sound. We'll need it later.

    # Arch Linux installation and configuration
    ## Set up LUKS on a partition
    > [!warning]
    >
    > Store the key in a place where you can read it externally. Flash drive, another computer, etc..
    >
    > Every time you update `systemd-boot` (whether it's the first time, a manual update, or a `pacman` hook - it doesn't matter), BitLocker will ask you for the encryption key.
    >
    > For this reason, I decided to only update the boot loader manually from time to time, and keep the BitLocker key on my flash drive. Less safe, but it is what it is.
    >
    > Thanks to https://github.com/Delta18-Git for heads up.
    ### Turn off

    After that, you are basically done with Windows. Reboot the device or turn it off and take a break.

    # Arch Linux

    ## Boot from the flash drive

    > [!important]
    >
    > By this point, Windows should have re-enabled the drive on the device as bootable, so manually disable it to boot from the flash drive.
    ## LUKS on a partition

    > [!note]
    >
    > Documentation: [LUKS on a partition - ArchWiki](https://wiki.archlinux.org/title/dm-crypt/Encrypting_an_entire_system#LUKS_on_a_partition).
    By this time, Windows should have created the Windows Recovery Environment partition. You can check this with:
    ```
    fdisk -l /dev/nvme0n1
    ```
    In my case `/dev/nvme0n1p5` is `Linux Filesystem` because 4th partition is now `Windows Recovery Environment`.
    Once the Arch Linux installation media is booted again, we are ready to proceed with the installation of the second operating system. This time we need to setup the encrypted root.

    Basically, you are changing the type of the Linux root partition to the crypto container, and then only this container will have the Linux root partition, which you will see as `/`.

    To create the container you have to format the partition with `cryptsetup`. After that, the system knows nothing about the internals of the container.

    To get access to the container, you need to `open` it. As it should be, each `open` is followed by a `close`, so you'll have to do that too if you don't want access anymore.

    After opening and mapping (assigning the root in the container), you can continue with the installation as normal.

    ### Create the LUKS container

    At this point, Windows should have created the Windows Recovery Environment partition. You can check this with:

    ```sh
    export DISK=/dev/nvme0n1

    fdisk -l "$DISK"
    ```
    cryptsetup -y -v luksFormat /dev/nvme0n1p5
    > YES

    Windows should have allocated some space for the "Windows Recovery Environment" by shrinking it's own root partition.

    In my case `/dev/nvme0n1p5` is now `Linux root (x86-64)` because the4th partition is now `Windows Recovery Environment`.

    ```sh
    export PART_LUKS="$DISK"p5
    ```
    Then enter your passphrase twice.

    ### Open LUKS partition
    Then you need to create a new LUKS container. The defaults are OK and you can just enable the verbose output.

    ```sh
    cryptsetup -v luksFormat "$PART_LUKS"
    ```
    cryptsetup luksOpen /dev/nvme0n1p5 root
    mount /dev/mapper/root /mnt

    > [!note]
    >
    > You can find default options and other options [right here](https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#Encryption_options_for_LUKS_mode).
    Then type

    ```
    You can check encryption with:
    YES
    ```
    cryptsetup luksDump /dev/nvme0n1p5

    and enter your passphrase twice.

    You can change the passphrase (or create multiple passphrases) later, but it's a good idea to choose a strong password from the start.

    Also, don't forget or lose the passphrase!

    > [!important]
    >
    > Immediately after formatting, you can save the headers. You'll need this to be able to decrypt the drive in case of corruption or simple loss of the passphrase.
    >
    > In the guide I did this [near the end](#mount-the-usb), when I remembered how to manually mount a USB drive.
    >
    > The actions are as follows:
    >
    > ```sh
    > cryptsetup luksDump "$PART_LUKS"
    > # check header presence
    >
    > mount --mkdir /dev/sda1 /usb
    > # check if /dev/sda1 is your usb device. not ventoy partition
    >
    > mkdir /usb/luks
    > # will get an error without that
    >
    > export HEADER_BACKUP=/usb/luks/header.img
    > cryptsetup luksHeaderBackup "$PART_LUKS" --header-backup-file "$HEADER_BACKUP"
    >
    > umount /usb
    >
    > rm -rf /usb
    > # be careful
    > ```
    >
    > Even if you want to do it manually with the GUI later, don't forget to do it. It's important.
    ### Open LUKS partition
    Next, create a LUKS partition in the container.
    ```sh
    export LINUX_ROOT=root # select preferred name for the root partition name
    cryptsetup open "$PART_LUKS" "$LINUX_ROOT"
    ```
    > [!note]
    >
    > v1 way:
    >
    > ```sh
    > cryptsetup luksOpen "$PART_LUKS" "$LINUX_ROOT"
    > ```
    >
    > It's the old syntax of the command. Remains for the compatibility. Thanks to https://github.com/enkvadrat for heads up.
    ### Create filesystem
    ```
    I will use Ext4:
    ```sh
    export MAPPED_ROOT=/dev/mapper/"$LINUX_ROOT"
    mkfs.ext4 "$MAPPED_ROOT"
    # same as
    mkfs.ext4 /dev/mapper/root
    # it that's more clear
    ```
    ### Check the mapping works as intended
    ```
    umount /mnt
    cryptsetup luksClose root
    cryptsetup luksOpen /dev/nvme0n1p5 root
    mount /dev/mapper/root /mnt
    ### Mount root
    ```sh
    export ROOT_MOUNT=/mnt
    mount "$MAPPED_ROOT" "$ROOT_MOUNT"
    ```
    ## Mount ESP
    ### Check the mapping works as intended
    > [!note]
    >
    > Not a necessary step, but it's better to check.
    ```sh
    umount "$ROOT_MOUNT"
    cryptsetup close "$LINUX_ROOT"
    cryptsetup open "$PART_LINUX" "$LINUX_ROOT"
    mount "$MAPPED_ROOT" "$ROOT_MOUNT"
    ```
    mount --mkdir /dev/nvme0n1p1 /mnt/boot
    > [!tip]
    >
    > You can check the partitions at any time with `lsblk` or `lsblk -f`.
    ### Mount ESP
    ```sh
    export PART_ESP="$DISK"p1
    mount --mkdir "$PART_ESP" "$ROOT_MOUNT"/boot
    # same as
    mount --mkdir /dev/nvme0n1p5 /mnt/boot
    ```
    ## Continue with normal installation
    ## Continue with the normal installation
    > [!note]
    >
    > Documentation: [Installation guide - ArchWiki](https://wiki.archlinux.org/title/installation_guide)
    ### Connect to the internet
    ```
    ip link # Check network interface.
    rfkill # "unblocked"
    ```sh
    ip link # check network interfaces
    rfkill # should be "unblocked"
    iwctl
    device list # In my case I have "wlan0".
    device list # in my case I have "wlan0"
    station wlan0 scan
    station wlan0 get-networks # Find your SSID.
    station wlan0 get-networks # find the ssid of your network
    station wlan0 connect <ssid>
    > ... # Enter passphrase.
    > ... # enter the passphrase for the network
    exit
    ```
    Check connection:
    ```
    ping archlinux.org # Ctrl+C to cancel.
    Check the connection:
    ```sh
    ping archlinux.org # ctrl + c to cancel
    ```
    ### Install essential packages
    > [!warning]
    >
    > 1. I am installing an AMD microcode package. If you have an Intel CPU, install the `intel-ucode` package instead!
    > 2. Also, I am installing `linux-zen` kernel. If you want to use the default kernel, consider installing `linux`. Next time I will refer to the kernel as `<kernel>`.
    ```sh
    pacstrap -K "$ROOT_MOUNT" base base-devel linux-zen linux-firmware amd-ucode sudo networkmanager cryptsetup nano man-db man-pages sbctl
    ```
    Package list, separated by newlines:
    ```sh
    base
    base-devel
    linux-zen
    linux-firmware
    amd-ucode
    sudo
    networkmanager
    cryptsetup
    nano
    man-db
    man-pages
    sbctl
    ```
    pacstrap /mnt base base-devel linux linux-firmware sudo nano networkmanager
    You can use the following:
    ```sh
    export KERNEL=linux-zen
    export MICROCODE=amd-ucode
    ```
    ### Generate fstab
    ```sh
    export FSTAB="$ROOT_MOUNT"/etc/fstab
    genfstab -U "$ROOT_MOUNT" >> "$FSTAB"
    # same as
    genfstab -U /mnt/etc >> /mnt/etc/fstab
    ```
    genfstab -U /mnt >> /mnt/etc/fstab
    nano /mnt/etc/fstab
    Check the result:
    ```sh
    nano "$FSTAB"
    ```
    If your `MAPPED_ROOT (/dev/mapper/root)` is present, as well as the boot mount, everything is OK.
    ### Change root
    ```
    arch-chroot /mnt
    ```sh
    arch-chroot "$ROOT_MOUNT"
    ```
    ### Change timezone
    ```
    ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime # Enter your "Region/City".
    ```sh
    export REGION=Europe
    export CITY=Moscow
    # set your region and city
    ln -sf /usr/share/zoneinfo/"$REGION"/"$CITY" /etc/localtime
    # set time zone
    hwclock --systohc
    # set hardware clock to utc
    ```
    ### Generate locales
    ```
    ```sh
    nano /etc/locale.gen
    ```
    Uncomment the required locales, save and exit.
    ```sh
    # in my case
    en_US.UTF-8 UTF-8
    ru_RU.UTF-8 UTF-8
    ```
    Generate uncommented locales:
    ```sh
    locale-gen
    nano /etc/locale.conf
    ```
    Set main locale:
    ```sh
    nano /etc/locale.conf
    ```
    Set main language:
    ```sh
    # the file only has this one line:
    LANG=en_US.UTF-8
    ```
    Save and exit.
    ### Set hostname
    ```
    ```sh
    nano /etc/hostname
    ```
    ```
    BOM-WFQ9
    ```sh
    arch # set as you wish
    ```
    ### Set root password
    ```
    ```sh
    passwd
    ```
    ### Configure mkinitcpio
    Open current mkinitcpio:
    ```
    Open current default config:
    ```sh
    nano /etc/mkinitcpio.conf
    ```
    Change `HOOKS` line to:
    ```
    HOOKS=(base systemd autodetect modconf kms keyboard block sd-encrypt filesystems fsck)
    > [!warning]
    >
    > If you have an AMD GPU (or APU), set the `MODULES` line to:
    >
    > ```sh
    > MODULES=(amdgpu)
    > ```
    >
    > I still get an `AMD SECUREDISPLAY` error on boot, but it's harmless.
    Change the `HOOKS` line to:
    ```sh
    HOOKS=(base systemd keyboard autodetect microcode modconf kms sd-vconsole block sd-encrypt filesystems fsck)
    ```
    and `MODULES` line to:
    Create `/etc/vconsole.conf`:
    ```sh
    nano /etc/vconsole.conf
    ```
    MODULES=(amdgpu)
    ```sh
    # file contents
    FONT=Lat2-Terminus16
    FONT_MAP=8859-2
    ```
    > Only if you have an AMD GPU.
    > [!note]
    >
    > You can select any font you want from `/usr/share/kbd/consolefonts`. Enter the file name without the file extension as `FONT`.
    Regenerate:
    ```
    mkinitcpio -p linux
    ```
    ### Install microcode
    ```
    pacman -S amd-ucode # intel-ucode for Intel
    ```sh
    mkinitcpio -p "$KERNEL"
    ```
    ### Install boot loader
    Check UEFI variables:
    ```
    ```sh
    ls /sys/firmware/efi/efivars
    ```
    > I'll use `systemd-boot`.
    ```
    If you see a long list of variables - you are ready to go.
    Install `systemd-boot`:
    ```sh
    bootctl install
    ```
    > I had bad timing and caught a [bug](https://bugs.archlinux.org/task/79619):
    ```
    Failed to get device path for 259:1: Bad file descriptor
    ```
    > To fix it, just downgrade systemd:
    ```
    pacman -U https://archive.archlinux.org/packages/s/systemd/systemd-254.1-1-x86_64.pkg.tar.zst
    ```
    > [!note]
    >
    > Last time I had bad timing and caught a [bug](https://bugs.archlinux.org/task/79619):
    >
    > ```sh
    > Failed to get device path for 259:1: Bad file descriptor
    > ```
    >
    > To fix this, I downgraded `systemd`:
    >
    > ```sh
    > pacman -U https://archive.archlinux.org/packages/s/systemd/systemd-254.1-1-x86_64.pkg.tar.zst
    > ```
    ### Configure boot loader
    ```
    ```sh
    nano /boot/loader/loader.conf
    ```
    ```
    ```sh
    timeout 5
    console-mode auto
    editor no
    ```
    ### Create Arch Linux boot entry
    > [!note]
    >
    > On other `console-mode` values (for example, `max`) the resolution will be stretched.
    ### Create boot entries
    With this command
    ```sh
    blkid
    ```
    you can get all the UUIDs of all the partitions in the GPT.
    Find the `PART_LUKS` entry with `TYPE=crypto_LUKS` and take a picture of that UUID. You need the `UUID`, not the `PARTUUID`.
    You will need to use this when editing the entries:
    ```sh
    nano /boot/loader/entries/arch.conf
    ```
    Common form of the file:
    ```sh
    title Arch Linux
    linux /vmlinuz-<kernel>
    initrd /<microcode>.img
    initrd /initramfs-<kernel>.img
    options rd.luks.name=<luks-part-uuid>=root root=<mapped-root>
    ```
    Example of the default kernel entry:
    ```sh
    title Arch Linux
    linux /vmlinuz-linux
    initrd /amd-ucode.img
    initrd /initramfs-linux.img
    options rd.luks.name=<luks-partition-uuid>=root root=/dev/mapper/root
    options rd.luks.name=<uuid>=root root=/dev/mapper/root
    ```
    My entries are as follows:
    ```sh
    # arch.conf
    title Arch Linux (Zen)
    linux /vmlinuz-linux-zen
    initrd /amd-ucode.img
    initrd /initramfs-linux-zen.img
    options rd.luks.name=<luks-part-uuid>=root root=/dev/mapper/root
    ```
    > I recommend finding the UUID with `lsblk -f` and taking a picture. You need the UUID of the `crypto_LUKS` partition, not the `root`!
    ```sh
    # arch-fallback.conf
    title Arch Linux Fallback (Zen)
    linux /vmlinuz-linux-zen
    initrd /amd-ucode.img
    initrd /initramfs-linux-zen-fallback.img
    options rd.luks.name=<luks-part-uuid>=root root=/dev/mapper/root
    ```
    > [!important]
    >
    > Don't forget to make the "Fallback" entry! It's the same as main entry (you can `cp` this file), but with different initramfs image.
    ### Reboot
    ```sh
    exit # exit chroot
    umount -R /mnt # ummount just in case
    reboot # or poweroff and boot manually
    ```
    Eject the flash drive and boot up the device. You don't need it right now.
    At the bootI enabled both devices in the UEFI.
    You can now restart.
    > [!note]
    >
    > If you get stuck on the load (the system does not prompt you for the passphrase), you probably entered the LUKS partition UUID incorrectly.
    >
    > Insert the flash drive, go into UEFI and deselect all devices as bootable except the USB flash drive.
    >
    > Launch the Arch installation medium. Open the LUKS container with `cryptsetup open`. Mount the mapped root and ESP, change the root into the `/mnt`:
    >
    > ```sh
    > mount /dev/mapper/root /mnt
    > mount /dev/nvme0n1p1 /mnt/boot
    > arch-chroot /mnt
    > ```
    >
    > Then correct the boot entries with the correct UUID from the `blkid`. Reboot and check.
    ## Configuration
    > Do this after booting to a fresh operating system.
    ### Set up network
    ```
    After booting, select your main Arch entry and enter your password to get to the login screen.
    If everything is OK, the system will prompt you for the LUKS partition passphrase. Enter it.
    Login as `root` with your password from `passwd`.
    ### Network
    ```sh
    # you can use the variables
    # but it is probably faster to not do so
    systemctl enable NetworkManager.service
    systemctl start NetworkManager.service
    # enable networkmanager
    systemctl disable systemd-resolved.service
    systemctl stop systemd-resolved.service
    # disable other systemd network service
    # just in case
    nmcli device wifi connect <ssid> password <wifi-password>
    # connect to the wifi
    ping archlinux.org
    # check connection
    ```
    ### Add user
    ```
    ```sh
    useradd -m -G wheel <username>
    # dont' forget to add the password:
    passwd <username>
    ```
    > If you get an error that the 'wheel' or 'users' group doesn't exist, just add it with `groupadd <groupname>`
    ```
    > [!tip]
    >
    > If you get an error that the "wheel" or "users" group doesn't exist, just add it with `groupadd <groupname>`.
    ```sh
    EDITOR=nano visudo
    ```
    ```
    # Uncomment this line:
    ```sh
    # Uncomment to allow members of group wheel to execute any command
    %wheel ALL=(ALL) ALL
    ```
    ### Install desktop environment
    > I'll use [GNOME](https://wiki.archlinux.org/title/GNOME):
    ```
    pacman -S gnome
    systemctl enable gdm.service
    ```
    Save and exit.
    ### Install [TLP](https://wiki.archlinux.org/title/TLP)
    > Only for laptops.
    ```
    pacman -S tlp
    systemctl enable tlp.service
    ```
    ### Secure Boot
    ## Enabling Secure Boot
    > [!note]
    >
    > Documentation: [ArchWiki](https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot), [comment on Reddit](https://www.reddit.com/r/archlinux/comments/ug9pu0/comment/i72v541) and [sbctl wiki](https://github.com/Foxboron/sbctl/wiki/Linux-Windows-Dual-Boot-with-Windows-Bitlocker).
    > Do it as `root`, otherwise you'll have to use `sudo`.
    ```
    pacman -S sbctl
    ```
    ```
    ```sh
    sbctl status
    # Installed: sbctl is not installed
    # Setup Mode: Enabled
    # Secure Boot: Disabled
    # Vendor Keys: none
    ```
    ```sh
    # expected output 1
    Installed: sbctl is not installed
    Setup Mode: Enabled
    Secure Boot: Disabled
    Vendor Keys: none
    ```
    > [!caution]
    >
    > Before continuing, read carefully the ArchWiki page. It's a dangerous operation for some vendors, and can "brick" your device.
    Create and enroll the keys:
    ```sh
    sbctl create-keys
    sbctl enroll-keys -m
    ```
    ```
    ```sh
    sbctl status
    # Installed: sbctl is installed
    # Owner GUID: ...
    # Setup Mode: Disabled
    # Secure Boot: Disabled
    # Vendor Keys: microsoft
    ```
    ```sh
    # expected output 2
    Installed: sbctl is installed
    Owner GUID: ...
    Setup Mode: Disabled
    Secure Boot: Disabled
    Vendor Keys: microsoft
    ```
    ```sh
    sbctl verify
    # A lot of lines, but we only need to sign 6 files.
    ```
    # a long list of files to verify
    ```
    sbctl sign -s /boot/vmlinuz-linux
    sbctl sign -s /boot/EFI/Boot/bootx64.efi
    sbctl sign -s /boot/EFI/systemd/systemd-bootx64.efi
    sbctl sign -s /EFI/Microsoft/Boot/bootmgfw.efi
    sbctl sign -s /EFI/Microsoft/Boot/bootmgr.efi
    sbctl sign -s /EFI/Microsoft/Boot/memtest.efi
    > [!note]
    >
    > You can verify all the files (manually or with a script/command), but we don't need them all. In my scenario, only the 6 files below are needed.
    ```sh
    export SIGN="sbctl sign -s"
    export MS_EFI=/boot/EFI/Microsoft/Boot/
    "$SIGN" /boot/vmlinuz-"$KERNEL"
    # kernel
    # example:
    # sbctl sign -s /boot/vmlinuz-linux
    # other files:
    "$SIGN" /boot/EFI/Boot/bootx64.efi
    "$SIGN" /boot/EFI/systemd/systemd-bootx64.efi
    # systemd-boot
    "$SIGN" "$MS_EFI"bootmgfw.efi
    "$SIGN" "$MS_EFI"bootmgr.efi
    "$SIGN" "$MS_EFI"memtest.efi
    # windows
    ```
    Verify:
    ```
    ```sh
    sbctl list-files
    # They should be listed.
    # signed files should be here
    ```
    ```
    pacman -S linux
    # Ensure that the string "Signing EFI binaries..." appears.
    ```
    Reboot, and before booting into Windows or Arch Linux, enable Secure Boot in UEFI. Make sure that Windows and Arch Linux boot correctly. In the Arch Linux console you can check `sbctl status`. You should see `Secure Boot: Enabled`.
    ## Bluetooth dual-boot configuration
    ### Configure audio
    > I recommend doing all commands as `root`.
    ```
    pacman -S pipewire
    pacman -S pipewire-pulse
    # Replace conflicting packages
    ```
    ```sh
    pacman -S "$KERNEL"
    # force package manager to update the kernel
    # "pacman -Syu" doesn't necessarily work
    # ensure that the strings
    # "Running post hook: [sbctl]"
    # and
    # "Signing EFI binaries..."
    # appear
    ```
    pacman -S bluez
    Reboot, and before booting into Windows or Arch Linux, enable Secure Boot in UEFI. It enabled itself automatically in my case.
    Make sure that Windows and Arch Linux boot correctly.
    In the Arch Linux console you can type `sbctl status` once again. You should see `Secure Boot: Enabled`.
    ### Bluetooth on Arch
    > [!important]
    >
    > Check the [Windows chapter on this topic](#bluetooth-on-windows) before proceeding.
    Install `bluez` and enable the service:
    ```sh
    pacman -S bluez bluez-utils
    systemctl enable bluetooth.service
    systemctl start bluetooth.service
    ```
    ### Sync keys
    I only connect one Bluetooth 5.0 device. Actions may be different.
    > [!warning]
    >
    > If you haven't installed the package and enabled the service, you won't have a `/var/lib/bluetooth` folder!
    > Documentation: [Dual boot pairing - ArchWiki](https://wiki.archlinux.org/title/Bluetooth#Dual_boot_pairing)
    #### Connect the devices
    Since we have paired the Bluetooth device with Windows, we should get the pairing key from Windows and replace the current key in Arch Linux with it.
    Download [PsExec](https://learn.microsoft.com/en-us/sysinternals/downloads/psexec) and extract it to a folder of your choice. Run Powershell or Command Prompt as an administrator and run `regedit`:
    ```
    .\PsExec64.exe -s -i regedit.exe
    ```sh
    bluetoothctl
    scan on
    pair <device-mac-address>
    # for every needed device
    devices Paired
    # to check
    ```
    In the `regedit` window, search for `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys` and select the required Bluetooth adapter. RMB on the key and export it as a .reg file in to a location of your choice. Then go to that file, open it with Notepad and take a picture of the hex key.
    Boot into Arch Linux and follow the steps below:
    1. As `root` run:
    #### Mount the USB
    I stored the Bluetooth keys on my USB flash drive, so I have mounted the flash drive to access them:
    ```sh
    mount --mkdir /dev/sda1 /usb
    # after all operations do
    # umount /usb
    # rm -rf /usb
    ```
    #### Sync keys
    ```sh
    cd /var/lib/bluetooth
    ```
    2. Get your `<bt-adapter-mac-address>` with `dir` and run `cd <bt-adapter-mac-address>` (you can enter first symbol and press Tab).
    3. Check desired device with `dir` and run `cd <device-mac-address`.
    4. Edit `info` file:
    ```
    Then, `cd` into the needed controller. Probably, it's the only one.
    For every device you need to do the following:
    Go into the device folder and edit `info` file:
    ```sh
    nano info
    ```
    5. Swap `Key=...` with your key from Windows. For example: `hex:69,27,6d,20,67,6f,6e,6e,61,20,6b,6d,73` is `69276D20676F6E6E61206B6D73`.
    6. Save, exit and restart Bluetooth and audio services:
    Swap
    ```sh
    [LinkKey]
    Key=...
    ```
    with your key from Windows.
    For example:
    ```sh
    hex:69,27,6d,20,67,6f,6e,6e,61,20,6b,6d,73
    # becomes
    Key=69276D20676F6E6E61206B6D73
    ```
    Save the file and do the same for the rest of the devices.
    Restart the Bluetooth service:
    ```sh
    systemctl restart bluetooth.service
    systemctl --user restart wireplumber pipewire pipewire-pulse
    ```
    7. Profit.
    # Ending
    Thank you for reading this far! I'm fairly new to Linux, so I've probably made a mistake somewhere. I'd be grateful if you could report any errors in this text.
    > [!note]
    >
    > You are probably doing this to connect audio devices. If so, install the audio packages:
    >
    > ```sh
    > # i use pipewire
    > pacman -S wireplumber pipewire pipewire-pulse
    > ```
    >
    > And restart these services after restarting the bluetooth service:
    >
    > ```sh
    > systemctl --user restart wireplumber pipewire pipewire-pulse
    > ```
    ### Everything else
    You are free to use your own configuration. In my case, I use my [dotfiles](https://github.com/shimeoki/dotfiles):
    ```sh
    chezmoi init shimeoki
    chezmoi apply
    ```
    > [!caution]
    >
    > Don't apply these dotfiles before checking the "Installation" in the README. It's probably broken.
    # Resources
    This is a list of all the links I have mentioned in this guide. They are listed in the order they are mentioned in the text.
    1. https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6
    2. https://archlinux.org/download/
    3. https://www.microsoft.com/en-us/software-download/windows11/
    4. https://www.ventoy.net/en/index.html
    5. https://www.ventoy.net/en/doc_mbr_vs_gpt.html
    6. https://en.wikipedia.org/wiki/Insyde_Software#InsydeH2O_UEFI_BIOS
    7. https://github.com/ventoy/Ventoy/issues/2825
    8. https://github.com/linux-nvme/nvme-cli
    9. https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#NVMe_drive
    10. https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#Sanitize_command
    11. https://wiki.archlinux.org/title/fdisk
    12. https://github.com/massgravel/Microsoft-Activation-Scripts
    13. https://github.com/ChrisTitusTech/winutil
    14. https://wiki.archlinux.org/title/Dual_boot_with_Windows#Windows_settings
    15. https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows
    16. https://wiki.archlinux.org/title/Bluetooth#Dual_boot_pairing
    17. https://docs.microsoft.com/en-us/windows/security/identity-protection/access-control/local-accounts#system
    18. https://wiki.archlinux.org/title/dm-crypt/Encrypting_an_entire_system#LUKS_on_a_partition
    19. https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#Encryption_options_for_LUKS_mode
    20. https://wiki.archlinux.org/title/installation_guide
    21. https://bugs.archlinux.org/task/79619
    22. https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot
    23. https://www.reddit.com/r/archlinux/comments/ug9pu0/comment/i72v541
    24. https://github.com/Foxboron/sbctl/wiki/Linux-Windows-Dual-Boot-with-Windows-Bitlocker
    25. https://github.com/shimeoki/dotfiles
    Also, if you found my text strange, that could be because of the DeepL Write assistance. Link: https://www.deepl.com/en/write
  6. @shimeoki shimeoki revised this gist Sep 11, 2023. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -53,6 +53,7 @@
    - [Create Arch Linux boot entry](#Create-Arch-Linux-boot-entry)
    - [Configuration](#Configuration)
    - [Set up network](#Set-up-network)
    - [Add user](#Add-user)
    - [Install desktop environment](#Install-desktop-environment)
    - [Install `TLP`](#Install-TLP)
    - [Enabling Secure Boot](#Enabling-Secure-Boot)
    @@ -433,6 +434,19 @@ systemctl disable systemd-resolved.service
    nmcli device wifi connect <ssid> password <wifi-password>
    ```

    ### Add user
    ```
    useradd -m -G wheel <username>
    ```
    > If you get an error that the 'wheel' or 'users' group doesn't exist, just add it with `groupadd <groupname>`
    ```
    EDITOR=nano visudo
    ```
    ```
    # Uncomment this line:
    %wheel ALL=(ALL) ALL
    ```

    ### Install desktop environment
    > I'll use [GNOME](https://wiki.archlinux.org/title/GNOME):
    ```
    @@ -505,7 +519,7 @@ pacman -S pipewire-pulse
    # Replace conflicting packages
    ```
    ```
    sudo pacman -S bluez
    pacman -S bluez
    systemctl enable bluetooth.service
    systemctl start bluetooth.service
    ```
  7. @shimeoki shimeoki revised this gist Sep 10, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -452,7 +452,7 @@ systemctl enable tlp.service
    > Do it as `root`, otherwise you'll have to use `sudo`.
    ```
    sudo pacman -S sbctl
    pacman -S sbctl
    ```
    ```
    sbctl status
  8. @shimeoki shimeoki created this gist Sep 10, 2023.
    544 changes: 544 additions & 0 deletions dual-boot.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,544 @@
    # My Windows 11 + Arch Linux dual-boot installation
    [This gist](https://gist.github.com/orhun/02102b3af3acfdaf9a5a2164bea7c3d6#installing-secure-boot) was very helpful to me and I wanted to write my own version with a dual-boot setup.
    > ### Warning!
    > All actions are at your own risk!
    # Table of Contents
    - [Table of Contents](#Table-of-Contents)
    - [Hardware](#Hardware)
    - [Pre-installation](#Pre-installation)
    - [Disabling Secure Boot](#Disabling-Secure-Boot)
    - [Cleaning NVMe drive](#Cleaning-NVMe-drive)
    - [Check drives](#Check-drives)
    - [Check the available formatting methods](#Check-the-available-formatting-methods)
    - [Perform a block erase](#Perform-a-block-erase)
    - [Check completion](#Check-completion)
    - [Verify cleaning](#Verify-cleaning)
    - [Partition the disk](#Partition-the-disk)
    - [Check current partitions](#Check-current-partitions)
    - [Proceed with `fdisk`](#Proceed-with-fdisk)
    - [Create MSR partition](#Create-MSR-partition)
    - [Create root partitions](#Create-root-partitions)
    - [Change partition types](#Change-partition-types)
    - [Write changes and check](#Write-changes-and-check)
    - [Format ESP](#Format-ESP)
    - [Windows 11 installation and configuration](#Windows-11-installation-and-configuration)
    - [Install Windows 11 from .iso file](#Install-Windows-11-from-iso-file)
    - [Install browser](#Install-browser)
    - [Activate your system](#Activate-your-system)
    - [Clean your system with `winutil`](#Clean-your-system-with-winutil)
    - [Set up BitLocker](#Set-up-BitLocker)
    - [Disable fast startup and hibernation](#Disable-fast-startup-and-hibernation)
    - [Change Windows time to UTC](#Change-Windows-time-to-UTC)
    - [Connect Bluetooth devices](#Connect-Bluetooth-devices)
    - [Arch Linux installation and configuration](#Arch-Linux-installation-and-configuration)
    - [Set up LUKS on a partition](#Set-up-LUKS-on-a-partition)
    - [Open LUKS partition](#Open-LUKS-partition)
    - [Create filesystem](#Create-filesystem)
    - [Check the mapping works as intended](#Check-the-mapping-works-as-intended)
    - [Mount ESP](#Mount-ESP)
    - [Continue with normal installation](#Continue-with-normal-installation)
    - [Connect to the internet](#Connect-to-the-internet)
    - [Install essential packages](#Install-essential-packages)
    - [Generate fstab](#Generate-fstab)
    - [Change root](#Change-root)
    - [Change timezone](#Change-timezone)
    - [Generate locales](#Generate-locales)
    - [Set hostname](#Set-hostname)
    - [Set root password](#Set-root-password)
    - [Configure mkinitcpio](#Configure-mkinitcpio)
    - [Install microcode](#Install-microcode)
    - [Install boot loader](#Install-boot-loader)
    - [Configure boot loader](#Configure-boot-loader)
    - [Create Arch Linux boot entry](#Create-Arch-Linux-boot-entry)
    - [Configuration](#Configuration)
    - [Set up network](#Set-up-network)
    - [Install desktop environment](#Install-desktop-environment)
    - [Install `TLP`](#Install-TLP)
    - [Enabling Secure Boot](#Enabling-Secure-Boot)
    - [Bluetooth dual-boot configuration](#Bluetooth-dual-boot-configuration)
    - [Configure audio](#Configure-audio)
    - [Sync keys](#Sync-keys)
    - [Ending](#Ending)

    # Hardware
    ### HUAWEI MateBook D 15 BoM-WFQ9
    - AMD Ryzen 5 5500U
    - 16GB DDR4
    - 512GB SSD
    > ### Warning!
    > Sound from speakers or wired headphones under Linux doesn't work on this laptop. Bluetooth headphones will, however. Windows works fine.
    # Pre-installation
    #### Required:
    - PC or laptop with stable power supply
    - Ventoy flash drive with Windows 11 and Arch Linux .iso files
    - Internet (Wi-Fi)
    - Free time

    ## Disabling Secure Boot
    Simply go into your UEFI and disable Secure Boot. Otherwise you won't be able to boot from the flash drive. We'll enable it after installation.
    In my case, I have to press F2 after turning on my laptop to get into [InsydeH2O](https://en.wikipedia.org/wiki/Insyde_Software#InsydeH2O_UEFI_BIOS).

    ## Cleaning NVMe drive
    > Documentation: [Memory cell clearing - ArchWiki](https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#NVMe_drive)
    Boot from your flash drive, select your Arch Linux .iso file and boot it in normal mode.

    > If you see the "Perform MOK Management" window, simply select "Enroll key from disk" and select the appropriate key. You can read more [here](https://www.ventoy.net/en/doc_secure.html).
    ### Check drives
    ```
    nvme list
    ```
    In my case I have `/dev/nvme0`. I'll use this name in future commands.

    ### Check the available formatting methods
    ```
    nvme id-ctrl /dev/nvme0 -H | grep "Format \|Crypto Erase\|Sanitize"
    ```
    In my case I have `[1:1] : 0x1 Block Erase Sanitize Operation Supported`. `Crypto Erase Sanitize` or `Overwrite Erase Sanitize` are not available for me.

    ### Perform a block erase
    > ### Warning!
    > This operation will erase all information on the drive.
    ```
    nvme sanitize /dev/nvme0 -a 0x02
    ```
    ### Check completion
    ```
    nvme sanitize-log /dev/nvme0
    ```
    ```
    Sanitize Progress (SPROG) : 65535
    Sanitize Status (SSTAT) : 0x101
    ```
    In my case it took 5-10 seconds, but [ArchWiki](https://wiki.archlinux.org/title/Solid_state_drive/Memory_cell_clearing#Sanitize_command) says that it can take for 2-3 hours. When you'll see `Sanitize Status ... 0x101` you're ready to proceed.

    ### Verify cleaning
    ```
    dd if=/dev/nvme0n1 bs=8192 status=progress | hexdump
    ```
    ```
    0000000 0000 0000 0000 0000 0000 0000 0000 0000
    *
    ...
    ```
    If you see ***only*** zeros, you can press Ctrl+C and you are done. If not, repeat the steps above.

    ## Partition the disk
    > Documentation: [fdisk - ArchWiki](https://wiki.archlinux.org/title/fdisk)
    ### Check current partitions
    ```
    fdisk -l /dev/nvme0n1
    ```
    As we have cleaned the drive, there should be nothing left.

    ### Proceed with `fdisk`
    ```
    fdisk /dev/nvme0n1
    ```
    ```
    > g # Create new GPT.
    > n # Create new partition.
    # Then skip until `Last sector,...` and enter:
    > +1G # Size 1G for our EFI system partition.
    ```
    You can check the current partitioning with `p`.

    ### Create MSR partition
    Repeat steps above for `16M` partition.

    ### Create root partitions
    I won't add a swap partition and will split my drive 50%/50%.
    ```
    # Math time.
    476.94 * 1024 = 488386.56 (total MB on drive)
    488386.56 - 1016 = 487370.56 (remaining MB on drive)
    487370.56 / 2 = 243685.28 (splitted partitions in MB)
    243685.28 / 1024 = 237.97... (splitted partitions in GB)
    ```
    So I'm going to divide by `238G`.
    Repeat the steps in [Proceed with `fdisk`](#Proceed-with-fdisk), but specify the size of the partitions. One will be Windows root and the other will be Arch Linux root. Create the first partition and for the second partition enter the last sector on the drive instead of the size.

    ### Change partition types
    ```
    > t
    > 1 # Select the first partition.
    > 1 # Change type to ESP (EFI System Partition).
    ```
    ```
    > t
    > 2 # Select the second partition.
    > 10 # Change type to MSR partition.
    ```
    ```
    > t
    > 3 # Select the third partition.
    > 11 # Change type to Windows Basic Data.
    ```
    Last partition for Linux root can be left untouched.

    ### Write changes and check
    ```
    > w
    ```
    ```
    fdisk -l /dev/nvme0n1
    ```
    ### Format ESP
    ```
    mkfs.fat -F 32 /dev/nvme0n1p1
    ```
    This is not necessary, but I did it anyway.

    # Windows 11 installation and configuration
    ## Install Windows 11 from .iso file
    Select your Windows 11 .iso file and boot it in normal mode.
    > If you want to get less bloatware, select `Time and currency format: English (World)` on the first screen. If you try to do this, you will get an `OOBEREGION` error later. Just skip it.
    Just do a normal install, choose custom partitioning and select the third partition. Don't do anything else on this screen, because we've done everything we need to do in [Partition the disk](#Partition-the-disk).

    ## Install browser
    After installing Windows, don't forget to install your preferred browser. In my case, I'm going to install Firefox. Just go to Microsoft Edge, skip everything, install and continue.

    ## Activate your system
    > [Microsoft Activation Scripts](https://github.com/massgravel/Microsoft-Activation-Scripts)
    Run Powershell as administrator:
    ```
    irm https://massgrave.dev/get | iex
    ```
    ```
    > 1 # Permanent HWID activation.
    > 0
    > 0
    ```

    ## Clean your system with [winutil](https://github.com/ChrisTitusTech/winutil)
    Run Powershell as administrator:
    ```
    irm https://christitus.com/win | iex
    ```
    Powershell will ask you to install Chocolatey. Accept and continue. Select 'Tweaks', select the profile you want and tick 'Remove Microsoft Edge' and click 'Run Tweaks'. You can now close everything.

    ## Set up BitLocker
    In Search, find "Manage BitLocker" and follow the steps to encrypt used disk space.
    You'll need a flash drive to store the recovery key file. Wait for the system to encrypt the entire system partition.
    > The system will prompt you for your BitLocker recovery key when you restart, so don't lose it!
    ## Disable fast startup and hibernation
    > Documentation: [ArchWiki](https://wiki.archlinux.org/title/Dual_boot_with_Windows#Windows_settings).
    Go to "Control panel" => Change "View by:" to "Large icons" => "Power options" => "Choose what the power button does" => "Change settings that are currently unavailable" => Remove ticks on "Turn on fast startup" and "Hibernate" => "Save changes".

    ## Change Windows time to UTC
    > Documentation: [ArchWiki](https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows).
    You have two ways:
    1. Execute `regedit` and find `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal`. Add `DWORD` value with hexadecimal value `1`.
    2. Simply type `reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal /d 1 /t REG_DWORD /f` in Command Prompt as administrator.
    > After restarting, change the time zone and region to yours in Settings.
    ## Connect Bluetooth devices
    If you plan to use a Bluetooth headphones (as in my case), pair it now and check the sound. We'll need it later.

    # Arch Linux installation and configuration
    ## Set up LUKS on a partition
    > Documentation: [LUKS on a partition - ArchWiki](https://wiki.archlinux.org/title/dm-crypt/Encrypting_an_entire_system#LUKS_on_a_partition).
    By this time, Windows should have created the Windows Recovery Environment partition. You can check this with:
    ```
    fdisk -l /dev/nvme0n1
    ```
    In my case `/dev/nvme0n1p5` is `Linux Filesystem` because 4th partition is now `Windows Recovery Environment`.

    ```
    cryptsetup -y -v luksFormat /dev/nvme0n1p5
    > YES
    ```
    Then enter your passphrase twice.

    ### Open LUKS partition
    ```
    cryptsetup luksOpen /dev/nvme0n1p5 root
    mount /dev/mapper/root /mnt
    ```
    You can check encryption with:
    ```
    cryptsetup luksDump /dev/nvme0n1p5
    ```
    ### Create filesystem
    ```
    mkfs.ext4 /dev/mapper/root
    ```
    ### Check the mapping works as intended
    ```
    umount /mnt
    cryptsetup luksClose root
    cryptsetup luksOpen /dev/nvme0n1p5 root
    mount /dev/mapper/root /mnt
    ```
    ## Mount ESP
    ```
    mount --mkdir /dev/nvme0n1p1 /mnt/boot
    ```

    ## Continue with normal installation
    > Documentation: [Installation guide - ArchWiki](https://wiki.archlinux.org/title/installation_guide)
    ### Connect to the internet
    ```
    ip link # Check network interface.
    rfkill # "unblocked"
    iwctl
    device list # In my case I have "wlan0".
    station wlan0 scan
    station wlan0 get-networks # Find your SSID.
    station wlan0 connect <ssid>
    > ... # Enter passphrase.
    exit
    ```
    Check connection:
    ```
    ping archlinux.org # Ctrl+C to cancel.
    ```

    ### Install essential packages
    ```
    pacstrap /mnt base base-devel linux linux-firmware sudo nano networkmanager
    ```

    ### Generate fstab
    ```
    genfstab -U /mnt >> /mnt/etc/fstab
    nano /mnt/etc/fstab
    ```

    ### Change root
    ```
    arch-chroot /mnt
    ```

    ### Change timezone
    ```
    ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime # Enter your "Region/City".
    hwclock --systohc
    ```

    ### Generate locales
    ```
    nano /etc/locale.gen
    ```
    Uncomment the required locales, save and exit.
    ```
    locale-gen
    nano /etc/locale.conf
    ```
    ```
    LANG=en_US.UTF-8
    ```
    Save and exit.

    ### Set hostname
    ```
    nano /etc/hostname
    ```
    ```
    BOM-WFQ9
    ```

    ### Set root password
    ```
    passwd
    ```

    ### Configure mkinitcpio
    Open current mkinitcpio:
    ```
    nano /etc/mkinitcpio.conf
    ```
    Change `HOOKS` line to:
    ```
    HOOKS=(base systemd autodetect modconf kms keyboard block sd-encrypt filesystems fsck)
    ```
    and `MODULES` line to:
    ```
    MODULES=(amdgpu)
    ```
    > Only if you have an AMD GPU.
    Regenerate:
    ```
    mkinitcpio -p linux
    ```

    ### Install microcode
    ```
    pacman -S amd-ucode # intel-ucode for Intel
    ```

    ### Install boot loader
    Check UEFI variables:
    ```
    ls /sys/firmware/efi/efivars
    ```
    > I'll use `systemd-boot`.
    ```
    bootctl install
    ```
    > I had bad timing and caught a [bug](https://bugs.archlinux.org/task/79619):
    ```
    Failed to get device path for 259:1: Bad file descriptor
    ```
    > To fix it, just downgrade systemd:
    ```
    pacman -U https://archive.archlinux.org/packages/s/systemd/systemd-254.1-1-x86_64.pkg.tar.zst
    ```

    ### Configure boot loader
    ```
    nano /boot/loader/loader.conf
    ```
    ```
    timeout 5
    console-mode auto
    editor no
    ```

    ### Create Arch Linux boot entry
    ```
    nano /boot/loader/entries/arch.conf
    ```
    ```
    title Arch Linux
    linux /vmlinuz-linux
    initrd /amd-ucode.img
    initrd /initramfs-linux.img
    options rd.luks.name=<luks-partition-uuid>=root root=/dev/mapper/root
    ```
    > I recommend finding the UUID with `lsblk -f` and taking a picture. You need the UUID of the `crypto_LUKS` partition, not the `root`!
    You can now restart.

    ## Configuration
    > Do this after booting to a fresh operating system.
    ### Set up network
    ```
    systemctl enable NetworkManager.service
    systemctl start NetworkManager.service
    systemctl disable systemd-resolved.service
    nmcli device wifi connect <ssid> password <wifi-password>
    ```

    ### Install desktop environment
    > I'll use [GNOME](https://wiki.archlinux.org/title/GNOME):
    ```
    pacman -S gnome
    systemctl enable gdm.service
    ```

    ### Install [TLP](https://wiki.archlinux.org/title/TLP)
    > Only for laptops.
    ```
    pacman -S tlp
    systemctl enable tlp.service
    ```

    ## Enabling Secure Boot
    > Documentation: [ArchWiki](https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot), [comment on Reddit](https://www.reddit.com/r/archlinux/comments/ug9pu0/comment/i72v541) and [sbctl wiki](https://github.com/Foxboron/sbctl/wiki/Linux-Windows-Dual-Boot-with-Windows-Bitlocker).
    > Do it as `root`, otherwise you'll have to use `sudo`.
    ```
    sudo pacman -S sbctl
    ```
    ```
    sbctl status
    # Installed: sbctl is not installed
    # Setup Mode: Enabled
    # Secure Boot: Disabled
    # Vendor Keys: none
    ```
    ```
    sbctl create-keys
    sbctl enroll-keys -m
    ```
    ```
    sbctl status
    # Installed: sbctl is installed
    # Owner GUID: ...
    # Setup Mode: Disabled
    # Secure Boot: Disabled
    # Vendor Keys: microsoft
    ```
    ```
    sbctl verify
    # A lot of lines, but we only need to sign 6 files.
    ```
    ```
    sbctl sign -s /boot/vmlinuz-linux
    sbctl sign -s /boot/EFI/Boot/bootx64.efi
    sbctl sign -s /boot/EFI/systemd/systemd-bootx64.efi
    sbctl sign -s /EFI/Microsoft/Boot/bootmgfw.efi
    sbctl sign -s /EFI/Microsoft/Boot/bootmgr.efi
    sbctl sign -s /EFI/Microsoft/Boot/memtest.efi
    ```
    Verify:
    ```
    sbctl list-files
    # They should be listed.
    ```
    ```
    pacman -S linux
    # Ensure that the string "Signing EFI binaries..." appears.
    ```
    Reboot, and before booting into Windows or Arch Linux, enable Secure Boot in UEFI. Make sure that Windows and Arch Linux boot correctly. In the Arch Linux console you can check `sbctl status`. You should see `Secure Boot: Enabled`.

    ## Bluetooth dual-boot configuration
    ### Configure audio
    > I recommend doing all commands as `root`.
    ```
    pacman -S pipewire
    pacman -S pipewire-pulse
    # Replace conflicting packages
    ```
    ```
    sudo pacman -S bluez
    systemctl enable bluetooth.service
    systemctl start bluetooth.service
    ```

    ### Sync keys
    I only connect one Bluetooth 5.0 device. Actions may be different.

    > Documentation: [Dual boot pairing - ArchWiki](https://wiki.archlinux.org/title/Bluetooth#Dual_boot_pairing)
    Since we have paired the Bluetooth device with Windows, we should get the pairing key from Windows and replace the current key in Arch Linux with it.
    Download [PsExec](https://learn.microsoft.com/en-us/sysinternals/downloads/psexec) and extract it to a folder of your choice. Run Powershell or Command Prompt as an administrator and run `regedit`:
    ```
    .\PsExec64.exe -s -i regedit.exe
    ```
    In the `regedit` window, search for `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys` and select the required Bluetooth adapter. RMB on the key and export it as a .reg file in to a location of your choice. Then go to that file, open it with Notepad and take a picture of the hex key.
    Boot into Arch Linux and follow the steps below:
    1. As `root` run:
    ```
    cd /var/lib/bluetooth
    ```
    2. Get your `<bt-adapter-mac-address>` with `dir` and run `cd <bt-adapter-mac-address>` (you can enter first symbol and press Tab).
    3. Check desired device with `dir` and run `cd <device-mac-address`.
    4. Edit `info` file:
    ```
    nano info
    ```
    5. Swap `Key=...` with your key from Windows. For example: `hex:69,27,6d,20,67,6f,6e,6e,61,20,6b,6d,73` is `69276D20676F6E6E61206B6D73`.
    6. Save, exit and restart Bluetooth and audio services:
    ```
    systemctl restart bluetooth.service
    systemctl --user restart wireplumber pipewire pipewire-pulse
    ```
    7. Profit.

    # Ending
    Thank you for reading this far! I'm fairly new to Linux, so I've probably made a mistake somewhere. I'd be grateful if you could report any errors in this text.