Arch-install-encrypted-btrfs/README.md

249 lines
7.5 KiB
Markdown
Raw Normal View History

2020-10-06 19:16:04 +00:00
# Install Arch Linux with encrypted filesystem(optional) and on btrfs partition (UEFI)
2020-10-07 07:41:24 +00:00
Official guide for basic install: [https://wiki.archlinux.org/index.php/Installation_Guide](https://wiki.archlinux.org/index.php/Installation_Guide)
2020-10-06 15:03:28 +00:00
it is always good to consult with official guide, cause arch config might change in time
2020-10-07 07:41:24 +00:00
For setting up different locale than pl check official guide
2020-10-06 15:03:28 +00:00
# 1. Boot ISO
### Download the ISO file from [https://www.archlinux.org](https://www.archlinux.org/)
2020-10-07 07:41:24 +00:00
### Put on pedrive
2020-10-06 15:03:28 +00:00
>dd if=archlinux.img of=/dev/sdX bs=16M && sync # on linux
### Boot from the usb.
### Set keymap
>loadkeys pl
2020-10-07 07:41:24 +00:00
### Update clock
2020-10-06 15:03:28 +00:00
>timedatectl set-ntp true
2020-10-07 07:41:24 +00:00
### Optionally (recommended) update mirrorlist
2020-10-06 15:03:28 +00:00
>reflector --country 'Poland' --age 24 --verbose --sort rate --save /etc/pacman.d/mirrorlist
# 2. Prepare Disk
### Update btrfs-progs
>pacman -Syy btrfs-progs
2020-10-07 07:41:24 +00:00
### Display disks setup
2020-10-06 15:03:28 +00:00
>fdisk -l
2020-10-07 07:41:24 +00:00
### Create partitions (if you have not already)
2020-10-06 15:03:28 +00:00
>fdisk /dev/sdX
2020-10-07 07:41:24 +00:00
1. 100MB EFI partition
2020-10-06 15:03:28 +00:00
2. 100% size partiton # ( encrypted optionally) for BTRFS, this partition will require formatting AFTER encryption if you do encryption
2020-10-07 07:41:24 +00:00
### Swap will be as file in its own subvolume
2020-10-06 15:03:28 +00:00
>mkfs.vfat -F32 /dev/sdX1 # EFI partiton formatting is required
### ----------------- encryption (optional) ------------------
### Setup the encryption of the system, don't use letters outside en-us keyboard like ąęć etc. for password
2020-10-07 07:41:24 +00:00
### You can check if grub with encrypted /boot support luks2 format when you are reading it, it coud have changed, but now grub only supports luks1
2020-10-06 15:03:28 +00:00
>cryptsetup -c=aes-xts-plain64 --key-size=512 --hash=sha512 --iter-time=3000 --use-random luksFormat --type=luks1 /dev/sdX2
>cryptsetup luksOpen /dev/sdX2 MainPart
2020-10-07 07:41:24 +00:00
### Formatting as btrfs now when it is already encrypted
2020-10-06 15:03:28 +00:00
>mkfs.btrfs -L "Arch Linux" /dev/mapper/MainPart
### ---------------- end of encryption ------------------------
### Format the partition if not yet formatted:
>pacman -Syy btrfs-progs
>mkfs.btrfs -L "Arch Linux" /dev/sdX2
2020-10-07 07:41:24 +00:00
### Mount partition to be able to create btrfs subvolumes
### If using encryption, change /dev/sdX2 to /dev/mapper/MainPart:
2020-10-06 15:03:28 +00:00
>mount /dev/sdX2 /mnt
## Create subvolumes
2020-10-07 07:41:24 +00:00
### Using more complicated sheme, (but there actually is only need for separate @swap subvolume , other files can be on default top subvolume)
2020-10-06 15:03:28 +00:00
>btrfs su cr /mnt/@
>btrfs su cr /mnt/@swap
>btrfs su cr /mnt/@home
>btrfs su cr /mnt/@var
>btrfs su cr /mnt/@tmp
>btrfs su cr /mnt/@snapshots
>umount /mnt
2020-10-07 07:41:24 +00:00
### If using encryption, change /dev/sdX2 to /dev/mapper/MainPart:
2020-10-06 15:03:28 +00:00
>mount -o defaults,noatime,discard,ssd,subvol=@ /dev/sdX2 /mnt
>mkdir /mnt/swap
>mkdir /mnt/home
>mkdir /mnt/var
>mkdir /mnt/tmp
>mkdir /mnt/snapshots
>mkdir /mnt/efi # for EFI partition /dev/sdX1
2020-10-07 07:41:24 +00:00
### If using encryption, change /dev/sdX2 to /dev/mapper/MainPart
2020-10-06 15:03:28 +00:00
### IMPORTANT for swap subvolume add nodatacow option to disable CoW
2020-10-07 07:41:24 +00:00
### Discard ssd and noatime are for ssd disks only
2020-10-06 15:03:28 +00:00
>mount -o defaults,noatime,nodatacow,discard,ssd,subvol=@swap /dev/sdX2 /mnt/swap
>mount -o defaults,noatime,discard,ssd,subvol=@home /dev/sdX2 /mnt/home
>mount -o defaults,noatime,discard,ssd,subvol=@var /dev/sdX2 /mnt/var
>mount -o defaults,noatime,discard,ssd,subvol=@tmp /dev/sdX2 /mnt/tmp
>mount -o defaults,noatime,discard,ssd,subvol=@snapshots /dev/sdX2 /mnt/snapshots
>mount /dev/sdX1 /mnt/efi
# 3. Install Arch Linux
### Select the mirror to be used if not updated with reflector on start
>nano /etc/pacman.d/mirrorlist
2020-10-07 07:41:24 +00:00
### This command can be customized with additional packages
2020-10-06 15:03:28 +00:00
>pacstrap /mnt/ base base-devel git btrfs-progs efibootmgr linux linux-headers linux-firmware mkinitcpio dhcpcd bash-completion sudo
2020-10-07 07:41:24 +00:00
### Use genfstab with -U parameter if no encryption
2020-10-06 15:03:28 +00:00
>genfstab /mnt >> /mnt/etc/fstab
2020-10-07 07:41:24 +00:00
### If using swapfile check if nodatacow is added for @swap
2020-10-06 15:03:28 +00:00
>nano /mnt/etc/fstab
# 4. Configure the system
2020-10-07 07:41:24 +00:00
### Switch to installed system root user
2020-10-06 15:03:28 +00:00
>arch-chroot /mnt /bin/bash
2020-10-07 07:41:24 +00:00
### Nano can be usefull when editing config files
2020-10-06 15:03:28 +00:00
>pacman -Syy nano
### Setup system clock
>ln -s /usr/share/zoneinfo/Europe/Warsaw /etc/localtime
>hwclock --systohc --utc
### Set the hostname
>/etc/hostname
>>myhostname
2020-10-07 07:41:24 +00:00
### Edit vconsole
2020-10-06 15:03:28 +00:00
>/etc/vconsole.conf
>>KEYMAP=pl
>>FONT=Lat2-Terminus16.psfu.gz
>>FONT_MAP=8859-2
2020-10-07 07:41:24 +00:00
### Setup locale
### Uncomment pl_PL.UTF-8 in /etc/locale.gen and then:
2020-10-06 15:03:28 +00:00
>locale-gen
2020-10-07 07:41:24 +00:00
### Update locale
>/etc/locale.conf
>>LANG=pl_PL.UTF-8
>>LC_ALL=pl_PL.UTF-8
2020-10-06 15:03:28 +00:00
2020-10-07 07:41:24 +00:00
### Hosts
2020-10-06 15:03:28 +00:00
>/etc/hosts
>>127.0.0.1 localhost
>>::1 localhost
>>127.0.1.1 myhostname.localdomain myhostname
2020-10-07 07:41:24 +00:00
### Now create 4GiB swap file. nodatacow is already (or should be) on @swap subvolume but it is recommended to disable cow for file :
2020-10-06 15:03:28 +00:00
>touch /swap/swapfile
2020-10-07 07:41:24 +00:00
### Check if C attribute is enabled with
2020-10-06 15:03:28 +00:00
>lsattr /swap/swapfile'
2020-10-07 07:41:24 +00:00
### If not then disable COW for swapfile manually:
2020-10-06 15:03:28 +00:00
>chattr +C /swap/swapfile
2020-10-07 07:41:24 +00:00
### Expanding empty file to 4GiB swap file
2020-10-06 15:03:28 +00:00
>dd if=/dev/zero of=/swap/swapfile bs=1024K count=4096
>chmod 600 /swap/swapfile
### Format the swap file.
>mkswap /swap/swapfile
### Turn swap file on.
>swapon /swap/swapfile
### You also need to update /etc/fstab to mount swapfile on boot:
>/etc/fstab
>>/swap/swapfile none swap sw 0 0
### Set password for root
>passwd
### Add real user
>useradd -m MYUSERNAME
>passwd MYUSERNAME
### Configure mkinitcpio with modules needed for the initrd image
>nano /etc/mkinitcpio.conf
2020-10-07 07:41:24 +00:00
### Remove 'fsck' and add 'encrypt', 'keyboard', 'keymap' and 'btrfs' to HOOKS before filesystems
### If no encryption then only remove fsck and add on that place btrfs
2020-10-06 15:03:28 +00:00
>HOOKS=(... keyboard keymap block encrypt btrfs ... filesystems ...)
###### optionally add BINARIES=(/usr/bin/btrfs) for rescue?
2020-10-07 07:41:24 +00:00
### Regenerate initrd images
2020-10-06 15:03:28 +00:00
>mkinitcpio -P
# 5. Install bootloader
### Setup grub (UEFI)
>pacman -S grub efibootmgr os-prober dosfstools mtools
### -------------encryption only---------------------
>nano /etc/default/grub
2020-10-07 07:41:24 +00:00
>>GRUB_ENABLE_CRYPTODISK=y
### Find UUID of crypto partition so we can add it to grub config
2020-10-06 15:03:28 +00:00
>blkid
2020-10-07 07:41:24 +00:00
### Now set this line including proper UUID:
>/etc/default/grub
>>GRUB_CMDLINE_LINUX="cryptdevice=UUID=<MainPart-UUID>:MainPart:allow-discards
2020-10-06 15:03:28 +00:00
### allow-discards is only for ssd
2020-10-07 07:41:24 +00:00
### Generate key so grub dons ask twice for password on boot
2020-10-06 15:03:28 +00:00
>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
2020-10-07 07:41:24 +00:00
### 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
2020-10-06 15:03:28 +00:00
>>FILES=(/crypto_keyfile.bin)
>mkinitcpio -P
### -------------encryption end---------------------
2020-10-07 07:41:24 +00:00
### Install
2020-10-06 15:03:28 +00:00
>grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
>grub-mkconfig -o /boot/grub/grub.cfg
### Exit new system
>exit
### Unmount all partitions
>swapoff -a
>umount -R /mnt
### Reboot into the new system, don't forget to remove the CD/pendrive
>reboot
### or
>shutdown now
2020-10-07 07:41:24 +00:00
## Addtitional tips
### To get proper locale and keymap, check:
2020-10-06 15:03:28 +00:00
>localectl status
2020-10-07 07:41:24 +00:00
### On KDE plasma , also set settings > ... > keyboard layout && regional settings