Compare commits

..

No commits in common. "5920fb3b2e6c462a1cd19cf675bccc2b83f2296e" and "077aec5d56d6096ee2030d6d9a81d8969d19a44c" have entirely different histories.

738
README.md
View file

@ -1,480 +1,260 @@
# ArchLinux install encrypted btrfs # Install Arch Linux with encrypted filesystem(optional) and on btrfs partition (UEFI)
Official guide for basic install: [https://wiki.archlinux.org/index.php/Installation_Guide](https://wiki.archlinux.org/index.php/Installation_Guide)
# Install Arch Linux on EFI system with full filesystem (including /boot) encrypted and on btrfs partition
Official guide for basic install: [https://wiki.archlinux.org/index.php/Installation\_Guide](https://wiki.archlinux.org/index.php/Installation_Guide)
it is always good to consult with official guide, cause arch config might change in time it is always good to consult with official guide, cause arch config might change in time
For setting up different locale, or better explanations check out Arch Wiki For setting up different locale than pl check official guide
## 1. Boot ISO # 1. Boot ISO
### Download the ISO file from [https://www.archlinux.org](https://www.archlinux.org/)
#### Download the ISO file from [https://www.archlinux.org](https://www.archlinux.org/) ### Put on pedrive
>dd if=archlinux.img of=/dev/sdX bs=16M && sync
#### Put on pendrive
### Boot from the usb.
```bash
dd if=archlinux.img of=/dev/sdX bs=16M && sync ### Set keymap
``` >loadkeys pl
#### Boot from the USB. ### Update clock
>timedatectl set-ntp true
#### Optional (**experimental** approach to have desktop environment during install):
### Optionally (recommended) update mirrorlist
##### Extend writable space so you can install basic desktop in live environment and for example use gparted for partitioning or open this tutorial in web browser or whatever you want. >reflector --country 'Poland' --age 24 --verbose --sort rate --save /etc/pacman.d/mirrorlist
<p class="callout warning">Remember this area is saved in your RAM, so make sure you have enough of it</p> # 2. Prepare Disk
``` ### Update btrfs-progs
mount -o remount,size=5G /run/archiso/cowspace >pacman -Syy btrfs-progs
pacman -Syy plasma-desktop glibc konsole xorg ### Display disks setup
pacman -Scc >fdisk -l
startplasma-wayland ### Create partitions (if you have not already)
``` >fdisk /dev/sdX
1. 100MB EFI partition
#### Set key map 2. 100% size partiton # ( encrypted optionally) for BTRFS, this partition will require formatting AFTER encryption if you do encryption
### Swap will be as file in its own subvolume
```bash
loadkeys pl >mkfs.vfat -F32 /dev/sdX1
```
### ----------------- encryption (optional) ------------------
#### Update clock
### Setup the encryption of the system, don't use letters outside en-us keyboard like ąęć etc. for password
```bash ### Grub have partial support for luks2 now, but can handle only pbkdf2
timedatectl set-ntp true >cryptsetup -c=aes-xts-plain64 --key-size=512 --hash=sha512 --iter-time=3000 --pbkdf=pbkdf2 --use-random luksFormat --type=luks2 /dev/sdX2
```
>cryptsetup luksOpen /dev/sdX2 MainPart
#### Optionally (recommended) update mirrorlist
### Formatting as btrfs now when it is already encrypted
```bash >mkfs.btrfs -L "Arch Linux" /dev/mapper/MainPart
reflector --country 'Poland' --age 24 --verbose --sort rate --save /etc/pacman.d/mirrorlist
```
### ---------------- end of encryption ------------------------
## 2. Prepare Disk
### Format the partition if not yet formatted:
#### Update btrfs-progs >pacman -Syy btrfs-progs
```bash >mkfs.btrfs -L "Arch Linux" /dev/sdX2
pacman -Syy btrfs-progs
``` ### Mount partition to be able to create btrfs subvolumes
### If using encryption, change /dev/sdX2 to /dev/mapper/MainPart:
#### Display disks and partitions >mount /dev/sdX2 /mnt
```bash ## Create subvolumes
lsblk ### Using more complicated sheme, (but there actually is only need for separate @swap subvolume , other files can be on default top subvolume)
```
>btrfs su cr /mnt/@
#### Create partitions (if you have not already)
>btrfs su cr /mnt/@swap
```bash
fdisk /dev/sdX >btrfs su cr /mnt/@home
```
>btrfs su cr /mnt/@var
1. 100MB EFI partition
2. 100% size partiton # ( encrypted optionally) for BTRFS partition, this partition will require formatting AFTER encryption if you do encryption >btrfs su cr /mnt/@tmp
##### Swap will bin in file with CoW disabled, which will be prepared later >btrfs su cr /mnt/@snapshots
#### Format EFI partition #### disable copy on write on var, tmp and swap
>chattr +C /mnt/@var
```Bash >chattr +C /mnt/@tmp
mkfs.vfat -F32 /dev/sdX1 >chattr +C /mnt/@swap
```
>umount /mnt
##### ----------------- encryption (optional) ------------------
### If using encryption, change /dev/sdX2 to /dev/mapper/MainPart:
>mount -o defaults,noatime,discard,ssd,subvol=@ /dev/sdX2 /mnt
#### Setup the encryption of the system,
>mkdir /mnt/swap
<p class="callout info">Don't use regional letters (not in en-us keyboard) like ąęć etc. for password. This requires additional steps, which are not covered by this tutorial.</p>
>mkdir /mnt/home
#### Grub have some kind of support for luks2, but not entirely, so for more fail-safe setup use luks1
>mkdir /mnt/var
```bash
cryptsetup -c=aes-xts-plain64 --key-size=512 --hash=sha512 --iter-time=3000 --pbkdf=pbkdf2 --use-random luksFormat --type=luks1 /dev/sdX2 >mkdir /mnt/tmp
cryptsetup luksOpen /dev/sdX2 MainPart >mkdir /mnt/snapshots
```
>mkdir /mnt/efi # for EFI partition /dev/sdX1
### Formatting as btrfs now when it is already encrypted
### If using encryption, change /dev/sdX2 to /dev/mapper/MainPart
```bash ### for swap subvolume add nodatacow option to disable CoW (works only if its separate partition)
mkfs.btrfs -L "Arch Linux" /dev/mapper/MainPart ### Discard ssd and noatime are for ssd disks only
```
>mount -o defaults,noatime,nodatacow,discard,ssd,subvol=@swap /dev/sdX2 /mnt/swap
##### ---------------- end of encryption ------------------------
>mount -o defaults,noatime,discard,ssd,subvol=@home /dev/sdX2 /mnt/home
#### Format the partition if not yet formatted:
>mount -o defaults,noatime,discard,ssd,subvol=@var /dev/sdX2 /mnt/var
```bash
pacman -Syy btrfs-progs >mount -o defaults,noatime,discard,ssd,subvol=@tmp /dev/sdX2 /mnt/tmp
mkfs.btrfs -L "Arch Linux" /dev/sdX2 >mount -o defaults,noatime,discard,ssd,subvol=@snapshots /dev/sdX2 /mnt/snapshots
```
>mount /dev/sdX1 /mnt/efi
#### Mount partition to be able to create btrfs subvolumes
##### If using encryption, change **/dev/sdX2** to **/dev/mapper/MainPart**: # 3. Install Arch Linux
```bash ### Select the mirror to be used if not updated with reflector on start
mount /dev/sdX2 /mnt >nano /etc/pacman.d/mirrorlist
```
### This command can be customized with additional packages
#### Create subvolumes >pacstrap /mnt/ base base-devel git btrfs-progs efibootmgr linux linux-headers linux-firmware mkinitcpio dhcpcd bash-completion sudo
##### This scheme can be adjusted to your needs, I'd suggest at least one subvolume for root (@) and one for snapshots (@snapshots). varlog and tmp are created to easily disable Copy on Write on` /var/log` and `/tmp`. ### Use genfstab with -U parameter if no encryption
>genfstab /mnt >> /mnt/etc/fstab
```bash
btrfs su cr /mnt/@ ### If using swapfile check if nodatacow is added for @swap
>nano /mnt/etc/fstab
btrfs su cr /mnt/@home
btrfs su cr /mnt/@varlog
# 4. Configure the system
btrfs su cr /mnt/@tmp
### Switch to installed system root user
btrfs su cr /mnt/@snapshots >arch-chroot /mnt /bin/bash
``` ### Nano can be usefull when editing config files
>pacman -Syy nano
##### Disable copy on write on `/var/log` and `/tmp`
### Setup system clock
```bash >ln -s /usr/share/zoneinfo/Europe/Warsaw /etc/localtime
chattr +C /mnt/@varlog
chattr +C /mnt/@tmp >hwclock --systohc --utc
umount /mnt
### Set the hostname
``` >/etc/hostname
>>myhostname
#### If using encryption, change **/dev/sdX2** to **/dev/mapper/MainPart**:
### Edit vconsole
```bash >/etc/vconsole.conf
mount -o defaults,noatime,discard,ssd,subvol=@ /dev/sdX2 /mnt >>KEYMAP=pl
>>FONT=Lat2-Terminus16.psfu.gz
mkdir /mnt/home >>FONT_MAP=8859-2
mkdir -p /mnt/var/log ### Setup locale
### Uncomment pl_PL.UTF-8 in /etc/locale.gen and then:
mkdir /mnt/tmp >locale-gen
mkdir /mnt/snapshots ### Update locale
>/etc/locale.conf
mkdir /mnt/efi # for EFI partition /dev/sdX1 >>LANG=pl_PL.UTF-8
``` >>LC_ALL=pl_PL.UTF-8
#### Discard and ssd options and are for ssd disks only ### Hosts
>/etc/hosts
#### If using encryption, change **/dev/sdX2** to **/dev/mapper/MainPart** >>127.0.0.1 localhost
>>::1 localhost
```bash >>127.0.1.1 myhostname.localdomain myhostname
mount -o defaults,noatime,discard,ssd,subvol=@home /dev/sdX2 /mnt/home
### Now create 4GiB swap file. nodatacow is already on @swap but if you follow exactly then @swap is on same partition as other subvolumes and nodatacow will not work for whole subvolume so you need to disavle CoW manualy :
mount -o defaults,noatime,discard,ssd,subvol=@varlog /dev/sdX2 /mnt/var/log >touch /swap/swapfile
### Check if C attribute is enabled with
mount -o defaults,noatime,discard,ssd,subvol=@tmp /dev/sdX2 /mnt/tmp >lsattr /swap/swapfile'
mount -o defaults,noatime,discard,ssd,subvol=@snapshots /dev/sdX2 /mnt/snapshots ### If not then disable COW for swapfile manually:
>chattr +C /swap/swapfile
mount /dev/sdX1 /mnt/efi
``` ### Expanding empty file to 4GiB swap file
>dd if=/dev/zero of=/swap/swapfile bs=1024K count=4096
# 3. Install Arch Linux
>chmod 600 /swap/swapfile
#### Select the mirror to be used if not updated with reflector on start
### Format the swap file.
```bash >mkswap /swap/swapfile
vim /etc/pacman.d/mirrorlist
``` ### Turn swap file on.
>swapon /swap/swapfile
#### Install base system:
### You also need to update /etc/fstab to mount swapfile on boot:
##### This command can be customized with additional packages (**btrfs-progs is necessary to let the system boot up from btrfs partition !**) >/etc/fstab
>>/swap/swapfile none swap sw 0 0
```bash
pacstrap /mnt/ base base-devel git btrfs-progs efibootmgr linux linux-headers linux-firmware mkinitcpio dhcpcd bash-completion sudo ### Set password for root
``` >passwd
### Add real user
#### Generate fstab: >useradd -m MYUSERNAME
##### Use genfstab with -U parameter if no encryption >passwd MYUSERNAME
```bash ### Configure mkinitcpio with modules needed for the initrd image
genfstab /mnt >> /mnt/etc/fstab >nano /etc/mkinitcpio.conf
``` ### Remove 'fsck' and add 'keyboard', 'keymap', 'encrypt' and 'btrfs' to HOOKS before filesystems
### If no encryption then only remove fsck and add on that place btrfs
#### >HOOKS=(... keyboard keymap block encrypt btrfs ... filesystems ...)
# 4. Configure the system ###### optionally add BINARIES=(/usr/bin/btrfs) for rescue?
#### Switch to installed system root user ### Regenerate initrd images
>mkinitcpio -P
```bash
arch-chroot /mnt /bin/bash # 5. Install bootloader
```
### Setup grub (UEFI)
#### Setup system clock >pacman -S grub efibootmgr os-prober dosfstools mtools
```bash
ln -s /usr/share/zoneinfo/Europe/Warsaw /etc/localtime ### -------------encryption only---------------------
>nano /etc/default/grub
hwclock --systohc --utc >>GRUB_ENABLE_CRYPTODISK=y
``` ### Find UUID (PARTUUID for /dev/sdX2) of crypto partition so we can add it to grub config
>blkid
#### Set the hostname in `/etc/hostname` ### Now set this line including proper UUID in place of "\<device-UUID>":
####(temporarly you cen use /dev/sdX2 in place of UUID and change it later easy in gui mode)
```test >/etc/default/grub
myhostname >>GRUB_CMDLINE_LINUX="cryptdevice=UUID=\<device-UUID>:MainPart:allow-discards
``` ### allow-discards is only for ssd
#### Edit vconsole in `/etc/vconsole.conf` ### Generate key so grub don't ask twice for password on boot
>dd bs=512 count=4 if=/dev/random of=/crypto_keyfile.bin iflag=fullblock
```text >chmod 600 /crypto_keyfile.bin
KEYMAP=pl >chmod 600 /boot/initramfs-linux*
FONT=Lat2-Terminus16.psfu.gz >cryptsetup luksAddKey /dev/sdX2 /crypto_keyfile.bin
FONT_MAP=8859-2 ### If you change name of key file there is need to add kernel parameter like cryptkey=rootfs:path
### Crypto_keyfile.bin is the default name that kernel will guess anyway
``` ### Now add this file to mkinitcpio.conf
>/etc/mkinitcpio.conf
#### Setup locale >>FILES=(/crypto_keyfile.bin)
##### Uncomment pl\_PL.UTF-8 in /etc/locale.gen and then run: >mkinitcpio -P
### -------------encryption end---------------------
```bash
locale-gen ### Install
``` >grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
>grub-mkconfig -o /boot/grub/grub.cfg
#### Update locale in `etc/locale.conf`
### Exit new system
```text >exit
LANG=en_US.UTF-8
LC_COLLATE=pl_PL.UTF-8 ### Unmount all partitions
LC_MEASUREMENT=pl_PL.UTF-8 >swapoff -a
LC_MONETARY=pl_PL.UTF-8 >umount -R /mnt
LC_NUMERIC=pl_PL.UTF-8
LC_TIME=pl_PL.UTF-8 ### Reboot into the new system, don't forget to remove the CD/pendrive
>reboot
``` ### or
>shutdown now
#### Hosts in `/etc/hosts`
## Addtitional tips
```text ### To get proper locale and keymap, check:
127.0.0.1 localhost >localectl status
::1 localhost ### On KDE plasma , also set settings > ... > keyboard layout && regional settings
127.0.1.1 myhostname.localdomain myhostname
```
#### Now create empty (with 0 size) swap file:
#### Create separate subvolume for swapfile. This subvolume is needed to let you make snapshot of `/`, which would not be possible with any file in it with CoW disabled!
```
btrfs su create /swap
chattr +C /swap
```
#### Copy on Write should always be disabled on swap file, so it will be done in the next step
```bash
touch /swap/swapfile
```
#### Check if C attribute is enabled (should be already if created in folder with disabled CoW attribute)
```bash
lsattr /swap/swapfile'
```
#### If not then disable CoW for swapfile manually:
```bash
chattr +C /swap/swapfile
```
#### Expanding empty file to 4GiB swap file
```bash
dd if=/dev/zero of=/swap/swapfile bs=1024K count=4096
chmod 600 /swap/swapfile
```
#### Format the swap file.
```bash
mkswap /swap/swapfile
```
#### Turn swap file on.
```bash
swapon /swap/swapfile
```
#### You also need to update `/etc/fstab` to mount swapfile on boot:
```text
/swap/swapfile none swap sw 0 0
```
#### Set password for root
```bash
passwd
```
#### Add real user an set password for him
```bash
useradd -m MYUSERNAME
passwd MYUSERNAME
```
### Configure mkinitcpio with modules needed for the initrd image
```bash
vim /etc/mkinitcpio.conf
```
#### Add 'keyboard', 'keymap', 'encrypt' and 'btrfs' to HOOKS before filesystems:
```
HOOKS=(base udev autodetect keyboard keymap modconf block btrfs filesystems keyboard fsck)
```
#### Add btrfsck to binaries:
```
BINARIES=(btrfsck)
```
#### **With encryption:** also add encrypt before btrfs:
```text
HOOKS=(... keyboard keymap block encrypt btrfs ... filesystems ...)
```
######
#### Regenerate initrd images
```bash
mkinitcpio -P
```
# 5. Install bootloader
#### Setup grub (UEFI)
```bash
pacman -S grub efibootmgr os-prober dosfstools mtools
```
#### -------------encryption only---------------------
#### edit `/etc/default/grub`
```text
GRUB_ENABLE_CRYPTODISK=y
```
#### Find UUID (UUID for /dev/sdX2) of crypto partition so we can add it to grub config
```bash
blkid
```
#### Now set this line including proper UUID in place of "&lt;device-UUID&gt;":
#### (temporarly you can use /dev/sdX2 in place of "UUID=&lt;device-UUID&gt;" and change it later easy in gui mode)
##### edit `/etc/default/grub`
```text
GRUB_CMDLINE_LINUX="cryptdevice=UUID=<device-UUID>:MainPart:allow-discards"
```
##### allow-discards is only for ssd to let trim work with encryption enabled
#### Generate key so grub don't ask twice for password on boot
```bash
dd bs=512 count=4 if=/dev/random of=/crypto_keyfile.bin iflag=fullblock
chmod 600 /crypto_keyfile.bin
chmod 600 /boot/initramfs-linux*
cryptsetup luksAddKey /dev/sdX2 /crypto_keyfile.bin
```
#### If you change name of key file there is need to add kernel parameter like cryptkey=rootfs:path
#### Crypto\_keyfile.bin is the default name that kernel will guess anyway
#### Now add this file to `/etc/mkinitcpio.conf`
```text
FILES=(/crypto_keyfile.bin)
```
then run:
```bash
mkinitcpio -P
```
#### -------------encryption end---------------------
#### Install grub for
```bash
grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg
```
#### Exit new system
```bash
exit
```
#### Unmount all partitions
```bash
swapoff -a
umount -R /mnt
```
#### Reboot into the new system, don't forget to remove the pendrive
```bash
reboot
```
#### or
```bash
shutdown now
```
### 6. Addtitional tips:
#### Install AUR helper (git and base-devel packages needed to do so):
```
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
```
#### To get proper locale and keymap, check:
```bash
localectl status
```
#### On KDE plasma , also set settings &gt; ... &gt; keyboard layout &amp;&amp; regional settings