<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad Javad Naderi</title>
    <description>The latest articles on DEV Community by Mohammad Javad Naderi (@mjnaderi).</description>
    <link>https://dev.to/mjnaderi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1171284%2Fbfcca65d-4290-473a-8f93-de9c347df5ea.jpeg</url>
      <title>DEV Community: Mohammad Javad Naderi</title>
      <link>https://dev.to/mjnaderi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mjnaderi"/>
    <language>en</language>
    <item>
      <title>Accessing Host Services from Docker Containers</title>
      <dc:creator>Mohammad Javad Naderi</dc:creator>
      <pubDate>Sun, 18 Feb 2024 22:25:25 +0000</pubDate>
      <link>https://dev.to/mjnaderi/accessing-host-services-from-docker-containers-1a97</link>
      <guid>https://dev.to/mjnaderi/accessing-host-services-from-docker-containers-1a97</guid>
      <description>&lt;p&gt;Accessing a host service from within a Docker container is a common requirement. For instance, you might have a HTTP proxy running on the host system at &lt;code&gt;127.0.0.1:8080&lt;/code&gt; that you want to access from a Docker container.&lt;/p&gt;

&lt;p&gt;One straightforward solution is to use &lt;code&gt;--network host&lt;/code&gt; for the Docker container or &lt;code&gt;network_mode: host&lt;/code&gt; in Docker Compose. However, this approach can lead to complications. If you use &lt;code&gt;network_mode: host&lt;/code&gt; for one service, you may find yourself needing to use it for other services or publish their ports just to enable them to communicate with each other. This can quickly result in losing the benefits of Docker Compose's default network.&lt;/p&gt;

&lt;p&gt;A more elegant solution is to connect to the special DNS name &lt;code&gt;host.docker.internal&lt;/code&gt;, which resolves to the internal IP address used by the host (for example, using &lt;code&gt;host.docker.internal:8080&lt;/code&gt; to connect to the proxy). On Linux, you need to pass &lt;code&gt;--add-host=host.docker.internal:host-gateway&lt;/code&gt; to the &lt;code&gt;docker&lt;/code&gt; command. The Docker Compose equivalent is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="na"&gt;extra_hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;host.docker.internal:host-gateway&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;However, this method won't work, since our host service is listening on &lt;code&gt;127.0.0.1&lt;/code&gt;. One workaround is to bind the host service to &lt;code&gt;0.0.0.0&lt;/code&gt;, but this exposes it to the outside world, which is often undesirable. The other workaround is to bind the host service to &lt;code&gt;172.17.0.1&lt;/code&gt;, but other apps that rely on &lt;code&gt;127.0.0.1:8080&lt;/code&gt; will break. Or we can bind to both &lt;code&gt;127.0.0.1&lt;/code&gt; and &lt;code&gt;172.17.0.1&lt;/code&gt;, but the host service may have no configuration option to specify the address or bind to multiple addresses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution using Socat
&lt;/h2&gt;

&lt;p&gt;I found a simple and effective solution to this problem using the &lt;code&gt;socat&lt;/code&gt; command. Socat is a command-line utility that establishes two bidirectional byte streams and transfers data between them. In this context, it can be used to listen on a TCP port on &lt;code&gt;host.docker.internal&lt;/code&gt; and forward to the host service. This allows you to connect to the host service using &lt;code&gt;host.docker.internal&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffa0qw0raz3v2pj5u8byc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffa0qw0raz3v2pj5u8byc.png" alt="Diagram of Accessing Host Service from Docker Container"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's how to set this up in Docker Compose for our HTTP proxy example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;proxy-relay&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;alpine/socat:latest&lt;/span&gt;
    &lt;span class="na"&gt;network_mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;host&lt;/span&gt;
    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TCP-LISTEN:8080,fork,bind=host.docker.internal TCP-CONNECT:127.0.0.1:8080&lt;/span&gt;
    &lt;span class="na"&gt;extra_hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;host.docker.internal:host-gateway&lt;/span&gt;

  &lt;span class="na"&gt;my-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;some-image&lt;/span&gt;
    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-command --connect-to host.docker.internal:8080&lt;/span&gt;
    &lt;span class="na"&gt;extra_hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;host.docker.internal:host-gateway&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this configuration, the &lt;code&gt;proxy-relay&lt;/code&gt; service listens on &lt;code&gt;host.docker.internal:8080&lt;/code&gt; and forwards to &lt;code&gt;127.0.0.1:8080&lt;/code&gt;. This allows &lt;code&gt;my-service&lt;/code&gt; to access the proxy without using &lt;code&gt;network_mode: host&lt;/code&gt; and without changing the bind address of the proxy. We also did not hard-code &lt;code&gt;172.17.0.1&lt;/code&gt; anywhere.&lt;/p&gt;

&lt;p&gt;Did you find this post useful? Please leave your feedback in the comments. 😊️&lt;/p&gt;

</description>
      <category>docker</category>
      <category>network</category>
    </item>
    <item>
      <title>Installing Arch Linux with Full Disk Encryption</title>
      <dc:creator>Mohammad Javad Naderi</dc:creator>
      <pubDate>Wed, 27 Sep 2023 09:43:02 +0000</pubDate>
      <link>https://dev.to/mjnaderi/installing-arch-linux-with-full-disk-encryption-16e9</link>
      <guid>https://dev.to/mjnaderi/installing-arch-linux-with-full-disk-encryption-16e9</guid>
      <description>&lt;p&gt;If you're aiming for a seamless encrypted Arch Linux installation in UEFI mode, follow along as this guide will walk you through the process step by step. We'll be using LUKS (Linux Unified Key Setup) and LVM (Logical Volume Manager) partitions on LUKS to achieve full disk encryption.&lt;/p&gt;

&lt;p&gt;For your convenience, you can also find this guide as a &lt;a href="https://gist.github.com/mjnaderi/28264ce68f87f52f2cabb823a503e673"&gt;GitHub Gist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're only interested in installing Linux and not setting up dual boot with Windows, feel free to skip the Windows-related sections.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prepare the System
&lt;/h1&gt;

&lt;p&gt;Before we dive into the installation process, let's ensure that your system is ready:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data Backup:&lt;/strong&gt; Make sure you've backed up all your important data. We're about to make significant changes, and it's always wise to have a safety net.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UEFI Mode:&lt;/strong&gt; In your system's BIOS settings, set the boot mode to UEFI.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Prepare the USB Drive
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ventoy Installation:&lt;/strong&gt; Start by installing &lt;a href="https://github.com/ventoy/Ventoy"&gt;Ventoy&lt;/a&gt; on your USB drive. Ventoy is a versatile tool that allows you to easily create a multi-boot USB drive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Download Arch ISO:&lt;/strong&gt; Head to &lt;a href="https://www.archlinux.org/download/"&gt;Arch Linux's official website&lt;/a&gt; and download the Arch ISO image. Copy it to your USB drive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optional Windows 11:&lt;/strong&gt; If you plan to set up a dual boot with Windows 11, download the Windows 11 ISO image and also copy it to your USB drive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Disk Partition Structure
&lt;/h1&gt;

&lt;p&gt;Here is an example to give you a clear picture of what the final disk partition structure will look like. If you're not interested in installing Windows, you can simply ignore the green parts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fre78eers8qn7moenzt49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fre78eers8qn7moenzt49.png" alt="Disk Partitions" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For better flexibility, I do not reuse the Windows EFI for Linux. Instead, I create a distinct EFI partition dedicated solely to Linux, resulting in the presence of two EFI partitions. I also use separate partitions for EFI and Boot.&lt;/p&gt;

&lt;p&gt;In the context of this guide, I've designated the disk device and Linux partitions with names according to the table below. Please be aware that these names should be substituted with the actual device paths relevant to your system configuration:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Device&lt;/th&gt;
&lt;th&gt;In this Doc&lt;/th&gt;
&lt;th&gt;Examples&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Disk Device&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/dev/&amp;lt;your-disk&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/dev/sda&lt;/code&gt;, &lt;code&gt;/dev/nvme0n1&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EFI Partition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/dev/&amp;lt;your-disk-efi&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/dev/sda5&lt;/code&gt;, &lt;code&gt;/dev/nvme0n1p5&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boot Partition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/dev/&amp;lt;your-disk-boot&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/dev/sda6&lt;/code&gt;, &lt;code&gt;/dev/nvme0n1p6&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LUKS Partition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/dev/&amp;lt;your-disk-luks&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/dev/sda7&lt;/code&gt;, &lt;code&gt;/dev/nvme0n1p7&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h1&gt;
  
  
  Install Windows (Optional)
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Boot from the Windows 11 ISO and install Windows. If you want to use BitLocker for disk encryption, ensure that you install the Windows Pro version.&lt;/li&gt;
&lt;li&gt;In Windows, open the start menu and search for "BitLocker". Open the BitLocker settings and enable BitLocker for the &lt;code&gt;C&lt;/code&gt; drive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Important:&lt;/strong&gt; Store the BitLocker recovery key in a safe place. You will need it later.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Install Arch Linux
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Connect the USB drive and boot from the Arch Linux ISO.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make sure the system is booted in UEFI mode. The following command should display the directory contents without error.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ls /sys/firmware/efi/efivars
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connect to the internet. A wired connection is preferred since it's easier to connect. &lt;a href="https://wiki.archlinux.org/index.php/Installation_guide#Connect_to_the_internet"&gt;More info&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run &lt;code&gt;fdisk&lt;/code&gt; to create Linux partitions.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# fdisk /dev/&amp;lt;your-disk&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you have installed Windows, you already have a GPT partition table. Otherwise, create an empty GPT partition table using the &lt;code&gt;g&lt;/code&gt; command. (&lt;strong&gt;WARNING:&lt;/strong&gt; This will erase the entire disk.)&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# WARNING: This will erase the entire disk.

Command (m for help): g
Created a new GPT disklabel (GUID: ...).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create the EFI partition (&lt;code&gt;/dev/&amp;lt;your-disk-efi&amp;gt;&lt;/code&gt;):&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Command (m for help): n
Partition number: &amp;lt;Press Enter&amp;gt;
First sector: &amp;lt;Press Enter&amp;gt;
Last sector, +/-sectors or +/-size{K,M,G,T,P}: +100M

Command (m for help): t
Partition type or alias (type L to list all): uefi
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create the Boot partition (&lt;code&gt;/dev/&amp;lt;your-disk-boot&amp;gt;&lt;/code&gt;):&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Command (m for help): n
Partition number: &amp;lt;Press Enter&amp;gt;
First sector: &amp;lt;Press Enter&amp;gt;
Last sector, +/-sectors or +/-size{K,M,G,T,P}: +512M

Command (m for help): t
Partition type or alias (type L to list all): linux
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create the LUKS partition (&lt;code&gt;/dev/&amp;lt;your-disk-luks&amp;gt;&lt;/code&gt;):&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Command (m for help): n
Partition number: &amp;lt;Press Enter&amp;gt;
First sector: &amp;lt;Press Enter&amp;gt;
Last sector, +/-sectors or +/-size{K,M,G,T,P}: &amp;lt;Press Enter&amp;gt;

Command (m for help): t
Partition type or alias (type L to list all): linux
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Print the partition table using the &lt;code&gt;p&lt;/code&gt; command and check that everything is OK:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Command (m for help): p
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Write changes to the disk using the &lt;code&gt;w&lt;/code&gt; command. (Make sure you know what you're doing before running this command).&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Command (m for help): w
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Format the EFI and Boot Partitions.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkfs.fat -F 32 /dev/&amp;lt;your-disk-efi&amp;gt;
mkfs.ext4 /dev/&amp;lt;your-disk-boot&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set up the encrypted partition. You can choose any other name instead of &lt;code&gt;cryptlvm&lt;/code&gt;.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# cryptsetup --use-random luksFormat /dev/&amp;lt;your-disk-luks&amp;gt;
# cryptsetup luksOpen /dev/&amp;lt;your-disk-luks&amp;gt; cryptlvm
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create an LVM volume group. You can choose any other name instead of &lt;code&gt;vg0&lt;/code&gt;.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pvcreate /dev/mapper/cryptlvm
# vgcreate vg0 /dev/mapper/cryptlvm
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create LVM partitions (logical volumes).&lt;/p&gt;

&lt;p&gt;We create logical volumes for swap, root (&lt;code&gt;/&lt;/code&gt;), and home (&lt;code&gt;/home&lt;/code&gt;). Leave 256MiB of free space in the volume group because the &lt;code&gt;e2scrub&lt;/code&gt; command requires the LVM volume group to have at least 256MiB of unallocated space to dedicate to the snapshot.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# lvcreate --size 8G vg0 --name swap
# lvcreate --size 100G vg0 --name root
# lvcreate -l +100%FREE vg0 --name home
# vreduce --size -256M vg0/home
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Format logical volumes.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# mkswap /dev/vg0/swap
# mkfs.ext4 /dev/vg0/root
# mkfs.ext4 /dev/vg0/home
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Mount new filesystems.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# mount /dev/vg0/root /mnt
# mount --mkdir /dev/&amp;lt;your-disk-efi&amp;gt; /mnt/efi
# mount --mkdir /dev/&amp;lt;your-disk-boot&amp;gt; /mnt/boot
# mount --mkdir /dev/vg0/home /mnt/home
# swapon /dev/vg0/swap
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install the base system. We also install some useful packages like &lt;code&gt;git&lt;/code&gt;, &lt;code&gt;vim&lt;/code&gt;, and &lt;code&gt;sudo&lt;/code&gt;.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pacstrap -K /mnt base linux linux-firmware openssh git vim sudo
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Generate &lt;code&gt;/etc/fstab&lt;/code&gt;. This file can be used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# genfstab -U /mnt &amp;gt;&amp;gt; /mnt/etc/fstab
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter the new system.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# arch-chroot /mnt /bin/bash
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set TimeZone.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---&amp;gt; See available timezones:
# ls /usr/share/zoneinfo/

---&amp;gt; Set timezone:
# ln -s /usr/share/zoneinfo/Asia/Tehran /etc/localtime
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run hwclock(8) to generate &lt;code&gt;/etc/adjtime&lt;/code&gt;.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# hwclock --systohc
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set Locale.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# vim /etc/locale.gen (uncomment en_US.UTF-8 UTF-8)
# locale-gen
# echo LANG=en_US.UTF-8 &amp;gt; /etc/locale.conf
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set hostname.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# echo yourhostname &amp;gt; /etc/hostname
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a user.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# useradd -m -G wheel --shell /bin/bash yourusername
# passwd yourusername
# visudo
---&amp;gt; Uncomment "%wheel ALL=(ALL) ALL"
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Configure &lt;code&gt;mkinitcpio&lt;/code&gt; with modules needed to create the initramfs image.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pacman -S lvm2
# vim /etc/mkinitcpio.conf
---&amp;gt; Add 'encrypt' and 'lvm2' to HOOKS before 'filesystems'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Recreate the initramfs image:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# mkinitcpio -P
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Setup GRUB.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pacman -S grub efibootmgr
# grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In &lt;code&gt;/etc/default/grub&lt;/code&gt; edit the line GRUB_CMDLINE_LINUX as follows. Don't forget to replace &lt;code&gt;/dev/&amp;lt;your-disk-luks&amp;gt;&lt;/code&gt; with the appropriate path.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GRUB_CMDLINE_LINUX="cryptdevice=/dev/&amp;lt;your-disk-luks&amp;gt;:cryptlvm root=/dev/vg0/root"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you have installed Windows and want to add Windows to the GRUB menu, edit &lt;code&gt;/etc/grub.d/40_custom&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
if [ "${grub_platform}" == "efi" ]; then
  menuentry "Windows 11" {
    insmod part_gpt
    insmod fat
    insmod search_fs_uuid
    insmod chain

    # After --set=root, add the Windows EFI partition's UUID.
    # (can be found with "blkid" command)
    search --fs-uuid --set=root $FS_UUID
    chainloader /EFI/Boot/bootx64.efi
  }
fi
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above script, replace &lt;code&gt;$FS_UUID&lt;/code&gt; with Windows EFI partition UUID. You can find this UUID using &lt;code&gt;lsblk&lt;/code&gt; command. It should be something like &lt;code&gt;8E12-69DD&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now generate the main GRUB configuration file:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# grub-mkconfig -o /boot/grub/grub.cfg
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;code&gt;networkmanager&lt;/code&gt; package and enable &lt;code&gt;NetworkManager&lt;/code&gt; service to ensure you have Internet connectivity after rebooting.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pacman -S networkmanager
# systemctl enable NetworkManager
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Exit new system and unmount all filesystems.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# exit
# umount -R /mnt
# swapoff -a
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Arch is now installed 🎉. Reboot.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# reboot
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open BIOS settings and set &lt;code&gt;GRUB&lt;/code&gt; as first boot priority. Save and exit BIOS settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After booting the system, you should see the GRUB menu.&lt;/p&gt;

&lt;p&gt;If you have installed Windows, select "Windows 11" in GRUB menu. If you have previously enabled Bitlocker, BitLocker will ask for your recovery key when you try to boot Windows through GRUB for the first time. Enter your BitLocker recovery key.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reboot again and log in to Arch linux with your username and password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check internet connectivity.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ping google.com
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you want to use Gnome desktop, install &lt;code&gt;gnome&lt;/code&gt; and &lt;code&gt;gdm&lt;/code&gt; packages:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo pacman -S gnome gdm
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And enable &lt;code&gt;gdm&lt;/code&gt; service:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo systemctl enable gdm
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reboot!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Notes
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Backup LUKS Header
&lt;/h2&gt;

&lt;p&gt;It is important to make a backup of LUKS header so that you can access your data in case of emergency (if your LUKS header somehow gets damaged).&lt;/p&gt;

&lt;p&gt;Create a backup file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# cryptsetup luksHeaderBackup /dev/&amp;lt;your-disk-luks&amp;gt; --header-backup-file luks-header-backup-$(date -I)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Store the backup file in a safe place, such as a USB drive. If something bad happens, you can restore the backup header:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# cryptsetup luksHeaderRestore /dev/&amp;lt;your-disk-luks&amp;gt; --header-backup-file /path/to/backup_header_file&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Disable Windows Hibernate and Fast Startup&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;If you want to use the same NTFS drive in both Windows and Linux (for example an NTFS partition on your internal disk or external hard drive), consider disabling "Hibernate" and "Fast Startup" features in Windows.&lt;/p&gt;

&lt;p&gt;You can check the current settings on &lt;code&gt;Control Panel &amp;gt; Hardware and Sound &amp;gt; Power Options &amp;gt; System Setting &amp;gt; Choose what the power buttons do&lt;/code&gt;. The box &lt;code&gt;Turn on fast startup&lt;/code&gt; should either be disabled or missing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://wiki.archlinux.org/title/NTFS-3G#Metadata_kept_in_Windows_cache,_refused_to_mount"&gt;More info&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/mattiaslundberg/8620837"&gt;https://gist.github.com/mattiaslundberg/8620837&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.archlinux.org/index.php/Installation_guide"&gt;https://wiki.archlinux.org/index.php/Installation_guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.archlinux.org/title/Dm-crypt/Encrypting_an_entire_system#LVM_on_LUKS"&gt;https://wiki.archlinux.org/title/Dm-crypt/Encrypting_an_entire_system#LVM_on_LUKS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.archlinux.org/title/GRUB"&gt;https://wiki.archlinux.org/title/GRUB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://joshrosso.com/docs/2020/2020-2-16-arch-windows-install/"&gt;https://joshrosso.com/docs/2020/2020-2-16-arch-windows-install/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>archlinux</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
