<?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: Rafael Coelho</title>
    <description>The latest articles on DEV Community by Rafael Coelho (@rccsilva).</description>
    <link>https://dev.to/rccsilva</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%2F593272%2F0e2b1f28-c8d6-4e9a-9627-0c9f759c57fc.jpeg</url>
      <title>DEV Community: Rafael Coelho</title>
      <link>https://dev.to/rccsilva</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rccsilva"/>
    <language>en</language>
    <item>
      <title>Installing Arch Linux with LVM and cryptsetup</title>
      <dc:creator>Rafael Coelho</dc:creator>
      <pubDate>Mon, 29 Mar 2021 15:54:20 +0000</pubDate>
      <link>https://dev.to/rccsilva/installing-arch-linux-with-lvm-and-cryptsetup-1igh</link>
      <guid>https://dev.to/rccsilva/installing-arch-linux-with-lvm-and-cryptsetup-1igh</guid>
      <description>&lt;p&gt;As a software developer, you probably already know that anyone with a small amount of programming knowledge should be using Arch Linux (that's a joke).&lt;/p&gt;

&lt;p&gt;Honestly, I'm writing this post in order to have a quick guide for myself whenever I like to install Arch Linux. I hope you find it useful.&lt;/p&gt;

&lt;p&gt;Some disclaimers before we start. First, this tutorial is almost a copy and paste from the original Arch Linux &lt;a href="https://wiki.archlinux.org/index.php/Installation_guide" rel="noopener noreferrer"&gt;wiki&lt;/a&gt;. I think it suits my needs better than the Wiki and I hope you think it does that too. Second, this post is much more like a &lt;code&gt;script&lt;/code&gt; than a tutorial which is concerned to explain the meaning and consequences of every single command. For that I think you'll find better answers inside the &lt;a href="https://wiki.archlinux.org/" rel="noopener noreferrer"&gt;Arch Linux Wiki&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Downloading
&lt;/h2&gt;

&lt;p&gt;Download the latest version of Arch Linux &lt;a href="https://archlinux.org/download/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Create a bootable USB with &lt;a href="https://rufus.ie/" rel="noopener noreferrer"&gt;Rufus&lt;/a&gt; if you're using Windows, or with &lt;a href="https://wiki.archlinux.org/index.php/USB_flash_installation_medium" rel="noopener noreferrer"&gt;&lt;code&gt;dd&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Installing
&lt;/h2&gt;

&lt;p&gt;1) Load a custom key map. For me, it's the Brazilian standard (ABNT).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;loadkeys br-abnt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Verify you're connected to the internet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ping dev.to
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Update system time and date&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;timedatectl set-ntp &lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Partition the disk&lt;/p&gt;

&lt;p&gt;Verify your current disk state with &lt;code&gt;fdisk -l&lt;/code&gt;&lt;br&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%2F872azuox1nnwg3aw4ihs.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%2F872azuox1nnwg3aw4ihs.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case, the target disk is mounted at &lt;code&gt;/dev/sda&lt;/code&gt;. Make sure to take note of your mount point, otherwise you may format the wrong disk and loose all your data.&lt;/p&gt;

&lt;p&gt;Execute &lt;code&gt;fdisk /dev/sdX&lt;/code&gt;, where &lt;code&gt;X&lt;/code&gt; is the letter of your disk.&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%2F8qdh4t28h2dmq6uos98l.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%2F8qdh4t28h2dmq6uos98l.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You be redirected to another console where you'll be able to format and create partitions on the selected disk.&lt;/p&gt;

&lt;p&gt;First, we'll execute &lt;code&gt;g&lt;/code&gt; to create a GPT disklabel.&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%2Fwdgoi8lfw7lqyo28e59y.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%2Fwdgoi8lfw7lqyo28e59y.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we have to create two partitions: 1) One for your boot files and 2) another one to hold all the OS data.&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%2Fcxfye8s4mm90xg51uvlj.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%2Fcxfye8s4mm90xg51uvlj.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create the first partition, we'll type &lt;code&gt;n&lt;/code&gt; and press &lt;code&gt;Enter&lt;/code&gt;. We'll press enter to next two options (partition number and first sector) in order to select the default values, and finally write &lt;code&gt;+500M&lt;/code&gt; in the third option in order to allocate 500Mb of space to it.&lt;/p&gt;

&lt;p&gt;To create the second partition, we'll again execute the &lt;code&gt;n&lt;/code&gt; command and select the default values (pressing &lt;code&gt;Enter&lt;/code&gt;) to all the options since we want all the available space to the second partition.&lt;/p&gt;

&lt;p&gt;Finally, by pressing &lt;code&gt;t&lt;/code&gt; and selecting &lt;code&gt;1&lt;/code&gt; for the first partition and &lt;code&gt;1&lt;/code&gt;, which is the code for &lt;code&gt;EFI System&lt;/code&gt;, we are able to replace the default partition type of our first partition for the one we need.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;write&lt;/strong&gt; the modifications press &lt;code&gt;w&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;5) Encrypting the partitions&lt;/p&gt;

&lt;p&gt;Once we have the partitions set, we can &lt;a href="https://wiki.archlinux.org/index.php/dm-crypt/Device_encryption" rel="noopener noreferrer"&gt;encrypt&lt;/a&gt; the one which will hold the OS and all our data. &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%2Fbxsvcpzybql8kgxs2af8.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%2Fbxsvcpzybql8kgxs2af8.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case, it's the &lt;code&gt;/dev/sda2&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cryptsetup luksFormat /dev/sdX
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember that if you forget your password, you'll loose all the data stored in the partition forever.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cryptsetup open /dev/sda2 cryptlvm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6) Create the &lt;a href="https://wiki.archlinux.org/index.php/LVM#Volume_operations" rel="noopener noreferrer"&gt;LVM&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pvcreate /dev/mapper/cryptlvm

vgcreate CryptDisk /dev/mapper/cryptlvm

lvcreate &lt;span class="nt"&gt;-L&lt;/span&gt; 8G CryptDisk &lt;span class="nt"&gt;-n&lt;/span&gt; swap

lvcreate &lt;span class="nt"&gt;-l&lt;/span&gt; 100%FREE CryptDisk &lt;span class="nt"&gt;-n&lt;/span&gt; root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7) Format the partitions&lt;/p&gt;

&lt;p&gt;Replace the &lt;code&gt;XX&lt;/code&gt; with the letter and number of your boot partition (the 500Mb one)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkfs.msdos &lt;span class="nt"&gt;-F32&lt;/span&gt; /dev/sdXX

mkfs.ext4 /dev/CryptDisk/root

mkswap /dev/CryptDisk/swap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;8) Mount the partitions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mount /dev/CryptDisk/root /mnt

swapon /dev/CryptDisk/swap

&lt;span class="nb"&gt;mkdir&lt;/span&gt; /mnt/boot

mount /dev/sdXX /mnt/boot &lt;span class="c"&gt;# Replace XX with your 500Mb partition&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you're ready to install Arch Linux!!!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing
&lt;/h2&gt;

&lt;p&gt;If you don't live in US or Europe the mirrors used to download the Arch Linux are not the best for you. Thus, I recommend you to rank the mirrors in order to have the best performance when downloading the OS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pacman &lt;span class="nt"&gt;-S&lt;/span&gt; pacman-contrib

&lt;span class="nb"&gt;cp&lt;/span&gt; /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup

rankmirrors &lt;span class="nt"&gt;-n&lt;/span&gt; 6 /etc/pacman.d/mirrorlist.backup &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/pacman.d/mirrorlist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It usually takes around 5 to 10 minutes to run this process.&lt;/p&gt;

&lt;p&gt;Finally, it's time to install Arch Linux!!!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pacstrap /mnt base base-devel linux linux-firmware
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;Since we'll have to edit some configuration files, I start by installing &lt;code&gt;vim&lt;/code&gt;, but you may use another text editor of your choice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pacman &lt;span class="nt"&gt;-Sy&lt;/span&gt; vim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1) Generate &lt;code&gt;fstab&lt;/code&gt; configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;genfstab &lt;span class="nt"&gt;-U&lt;/span&gt; /mnt &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /mnt/etc/fstab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Login into the installed system&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;arch-chroot /mnt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Time Zone&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ln&lt;/span&gt; &lt;span class="nt"&gt;-sf&lt;/span&gt; /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime

hwclock &lt;span class="nt"&gt;--systohc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Locales&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;/etc/locale.gen&lt;/code&gt; and uncomment &lt;code&gt;en_US.UTF-8 UTF-8&lt;/code&gt; and any other locale that you might need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vim /etc/locale.gen

locale-gen

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"LANG=en_US.UTF-8"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/locale.conf

localectl set-keymap &lt;span class="nt"&gt;--no-convert&lt;/span&gt; br-abnt &lt;span class="c"&gt;# Replace "br-abnt" with your keyboard type&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5) Network&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"rafael-dell"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/hostname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modify the &lt;code&gt;/etc/hosts&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;127.0.0.1   localhost
::1     localhost
127.0.1.1   rafael-dell.localdomain rafael-dell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6) &lt;code&gt;initramfs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since we're using custom configurations (LVM and ecrypted disk), we have to modify the &lt;code&gt;/etc/mkinitcpio.conf&lt;/code&gt; so the machine can be properly booted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vim /etc/mkinitcpio.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the followings commands in the &lt;code&gt;HOOKS&lt;/code&gt;: &lt;code&gt;encrypt lvm2 keyboard&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;7) Install the bootloader&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pacman &lt;span class="nt"&gt;-S&lt;/span&gt; grub

grub-install &lt;span class="nt"&gt;--target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;x86_64-efi &lt;span class="nt"&gt;--efi-directory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/boot &lt;span class="nt"&gt;--bootloader-id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;GRUB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we have an encrypted disk, we need to set a few grub variables before generating the grub configuration files.&lt;/p&gt;

&lt;p&gt;Edit the file &lt;code&gt;/etc/default/grub&lt;/code&gt; and modify the following lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;GRUB_CMDLINE_LINUX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cryptdevice=UUID=&amp;lt;device-UUID&amp;gt;:cryptlvm root=/dev/CryptDisk/root rw"&lt;/span&gt;
&lt;span class="nv"&gt;GRUB_ENABLE_CRYPTODISK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll have to replace the &lt;code&gt;&amp;lt;device-UUID&amp;gt;&lt;/code&gt; with the encrypted partition UUID. If you're using &lt;code&gt;vim&lt;/code&gt;, you can execute &lt;code&gt;read ! blkid /dev/sdXX&lt;/code&gt; to paste the partition's UUID, otherwise you can run &lt;code&gt;lsblk -f&lt;/code&gt; and get it.&lt;/p&gt;

&lt;p&gt;8) Set up a root password&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we are done. Now you can &lt;code&gt;reboot&lt;/code&gt; and enjoy your &lt;/p&gt;

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