srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
Diffstat (limited to 'linux')
-rw-r--r--linux/arch-install.md263
-rw-r--r--linux/lvm.md82
2 files changed, 290 insertions, 55 deletions
diff --git a/linux/arch-install.md b/linux/arch-install.md
index 51dc016..17d3d12 100644
--- a/linux/arch-install.md
+++ b/linux/arch-install.md
@@ -1,62 +1,215 @@
-timedatectl list-timezones | grep Johannesburg -- Finding desired timezone
-ln -sf /usr/share/zoneinfo/Afica/Johannesburg /etc/localtime -- Setting correct live timezone
-#Edit /etc/locale.gen and uncomment en_US.UTF-8 UTF-8 and other needed locales.
-locale-gen ## Generate the locales by running
+### Arch Linux Installation with optional LUKS (encryption) on LVM (Logical Volume Management)
+- Look for an appropriate keyboard layout
+`# localectl list-keymaps | grep US`
+- Set the console keyboard layout
+`# loadkeys en_US.UTF-8`
+- Verify the boot mode, the below command must show the directory without error otherwise the system is not booted in UEFI mode
+`# ls /sys/firmware/efi/efivars`
+- Test internet connection
+`# ip a`
+- Press "enter" and select wifi and enter password
+`# wifi-menu`
+- Update the system clock
+`# timedatectl set-ntp true`
+- Update mirror list by installing reflector and running the following command
+`# pacman -Syy reflector`
+`# reflector -c <Country> -a 6 --sort rate --save /etc/pacman.d/mirrorlist`
+- Update servers
+`pacman -Syy`
+- List block devices to get the disk-name, usually "sda", "vda" or "nvme01" etc..
+`# lsblk`
+- Create EFI Partition using gdisk (partitioning tool)
+`# gdisk /dev/<disk-name>`
+ - Type `n` for new and press "enter"
+ - Press "enter" on default Partition number
+ - Press "enter" on default First sector
+ - `+300M` -- On Last sector (efi partition)
+ - `ef00` -- Change the Current type code from Linux filesystem to EFI system partition and don't do anything else yet
+- Either create a default linux filesystem or LVM (recommended)
+NOTE: If your filesystem choice is BTRFS much later on, there is no need to create LVMs since it has it's own Subvolume feature. LVM (Logical Volume Management) is useful if we want a flexible disk storage that we either need to create separate partitions on, be able to resize them on the fly or to create snapshots.
+- Continuing...
+ - For default filesystem press "enter" 4 times on all parameters (Partition number, First sector, Last sector and Current type)
+ or
+ - Create LVM partition
+ - Type `n` for new again and press "enter"
+ - Press "enter" on default Partition number again
+ - Press "enter" on default First sector again
+ - Press "enter" on default Last sector this time
+ - `8e00` -- Change the Current type code from Linux filesystem to Linux LVM
+- Save changes
+ - Type "w" to write changes and press "enter"
+ - Type "y" to confirm and press "enter"
+- List block devices again to check the new partitions
+ `# lsblk`
+NOTE: From here onwards we'll assume the disk and it's partition's names are sda, sda1 and sda2 respectively and one must adjust it to their actually names on their system accordingly.
+- (Optional) Encrypt our main partition (sda2) using LUKS
+ - Format the partition using cryptsetup
+ `# cryptsetup luksFormat /dev/sda2`
+ or
+ - Format the partition and setup a stronger encryption with sha512 LUKS and added randomness
+ `# cryptsetup --cipher aes-xts-plain64 --hash sha512 --use-random --verify-passphrase luksFormat /dev/sda2`
+ - If an error occurs try this
+ `# modprobe dm_crypt`
+ - Type `YES` to confirm overwrite press "enter"
+ - Type in new encryption passphrase
+ - Verify passphrase
+ - Open up partition to create a name for it, create LVMs and format them
+ `# cryptsetup open /dev/sda2 <name-of-partition>`
+ - Enter passphrase
+ - Create physical volumes (PV) on the encrypted volume path "/dev/mapper/"
+ (device mapper)
+ `# pvcreate /dev/mapper/<name-of-partition>`
+ - Create the volume group (VG) with the name "vg1" or any other appropriate name on the encrypted volume path
+ NOTE: Always make meaningful volume and volume group names.
+ `# vgcreate vg1 /dev/mapper/<name-of-partition>`
+ - Create logical volumes (LV) root, swap (optional) and home
+ `# lvcreate -L 40G vg1 -n root` -- plan on having a lot of packages installed bump it up maybe to 60gb or 80gb etc..
+ `# lvcreate -L 4G vg1 -n swap` -- can be any size between 2gb, 4gb or 8gb
+ `# lvcreate -l 100%FREE vg1 -n home` -- give the remaining space to home
+```
+ -L = absolute size
+ -l = left over space
+ 100%FREE = percentage of free space
+ nG = partition size where n is number of and G is gigabytes
+ vg1 = specify VG name
+ -n = name LV
+ <name> = name of LV
+```
-echo LANG=en_US.UTF-8 >> /etc/locale.conf
-#Create the locale.conf(5) file, and set the LANG variable accordingly:
-/etc/locale.conf
+ - Check changes and see if everything is correct
+ `# lsblk`
+ - Format boot efi partition "/dev/sda1" to FAT32 filesystem
+ `# mkfs.fat -F32 /dev/sda1`
+ - Format root partition "dev/vg1/root" to EXT4 filesystem
+ `# mkfs.ext4 /dev/vg1/root`
+ - Format home partition "dev/vg1/home" to EXT4 filesystem
+ `# mkfs.ext4 /dev/vg1/home`
+ - Only make swap file partition "dev/vg1/swap" if it was previously made (optional)
+ `# mkswap /dev/vg1/swap`
+ - Check partitions before mounting
+ `# lsblk`
+ - Make a boot directory in installation directory to mount "/dev/sda1"
+ `# mkdir /mnt/boot`
+ - Mount efi boot into installation directory
+ `# mount /dev/sda1 /mnt/boot`
+ - Mount logical volume path of root into installation directory
+ `# mount /dev/vg1/root /mnt`
+ - Make a home directory in installation directory
+ `# mkdir /mnt/home`
+ - Mount logical volume path of home into installation directory
+ `# mount /dev/vg1/home /mnt/home`
+ - Only activate swap on installation directory if it was previously made
+ (optional)
+ `# swapon /dev/vg1/swap`
+ - Check mountpoints are correct
+ `# lsblk`
+ - Install base packages
+ NOTE: If LTS (long-term support) is desired replace linux with linux-lts. Omit linux-firmware if installing in a VM (virtual machine) or container. Replace vim with desired text-editor. Replace intel-ucode with amd-ucode if we have an amd processor. Omit lvm2 if not using LVM.
+ `# pacstrap /mnt base linux linux-firmware vim lvm2 git man openssh tmux`
+ or get a normal base installation with common programs
+ `# pacstrap -i /mnt base base-devel`
+ - Generate the fstab file (where mount points are stored) use `-U` or `-L` to define by UUID or labels respectively
+ `# genfstab -U /mnt >> /mnt/etc/fstab`
+ - See what is in the fstab file
+ `# cat /mnt/etc/fstab`
+ - Move into the installation
+ `# arch-chroot /mnt`
+ - Localization of timezone, find nearest timezone
+ `# timedatectl list-timezones | grep <City>`
+ - Setting correct live timezone
+ `# ln -sf /usr/share/zoneinfo/<Continent>/<City> /etc/localtime`
+ - Synchronize hardware clock to system clock
+ `# hwclock --systohc`
+ - Edit locale.gen file, replace vim with text-editor of choice
+ `# vim /etc/locale.gen`
+ - Uncomment `en_US.UTF-8 UTF-8` and any other needed locales (LANG variable), save and exit
+ - Generate the locales by running
+ `# locale-gen`
+ - Also put the chosen locale into locale.conf
+ `# echo LANG=en_US.UTF-8 >> /etc/locale.conf`
+ - If chosen a different keyboard layout in the beginning put it into vconsole.conf
+ `# echo KEYMAP=<keymap> >> /etc/vconsole.conf`
+ - Hostname (machine's name)
+ `# vim /etc/hostname`
+ - Put in desired hostname, example: `archlinux`, save and exit
+ - Edit host file (/etc/hosts) putting in previously mentioned hostname
+ `# echo "127.0.0.1 localhost" >> /etc/hosts`
+ `# echo "::1 localhost" >> /etc/hosts`
+ `# echo "127.0.1.1 <hostname>.localdomain <hostname>" >> /etc/hosts`
+ - Give root user a new password
+ `# passwd`
+- Type in new password and retype it to verify
+- Install packages
+ `pacman -S grub efibootmgr base-devel xdg-utils xdg-user-dirs linux-headers networkmanager network-manager-applet wpa_supplicant dialog mtools dosfstools nfs-utils inetutils dnsutils bluez bluez-utils cups hplip alsa-utils pipewire pipewire-alsa pipewire-pulse pipewire-jack rsync reflector acpi acpi_call tlp virt-manager qemu qemu-arch-extra edk2-ovmf bridge-utils dnsmasq vde2 openbsd-netcat iptables-nft ipset firewalld sof-firmware nss-mdns acpid os-prober ntfs-3g xclip`
+- If using a new keymap and/or LVM and/or encryption edit initcpio.conf file and insert the necessary information
+ `# vim /etc/mkinitcpio.conf`
+- Look for the "HOOKS" section and after "autodectect" insert `keymap` then after "block" insert `encrypt` and `lvm2`, save and exit.
+ Example:
+```
+HOOKS=(base udev autodetect keymap modconf block encrypt lvm2 filesystems keyboard fsck)
+```
+- Generate the initramfs (initial RAM file system) image, replace linux with linux-lts if that was chosen
+ `# mkinitcpio -p linux`
+- Install GRUB (boot loader)
+ `# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB`
+ NOTE: If above command doesn't work try this rather
+ `# Grub-install - - target=x86_64-efi - - bootloader-id=grub - - efi-directory=/boot/efi`
+- Display block ID (UUID) for "/dev/sda2" and copy it using the command below or omit everything after `blkid` and write it down somewhere
+ `# blkid | grep -oP '/dev/sda2: UUID="\K[^"]+' | xclip -sel clip
+- Edit GRUB file
+ `# vim /etc/default/grub`
+- Go down to `GRUB_CMDLINE_LINUX=""` and insert inbetween the apostrophes:
+ `cryptdevice=UUID=</dev/sda2's-UUID>:<name-of-partition> root=/dev/volume-group-path-name/root`
+ Example:
+```
+GRUB_CMDLINE_LINUX="cryptdevice=UUID=f233c213-37e8-4f60-b0bd-a6689ea0cb6c:cryptlvm root=/dev/vg1/root"
+```
+- save and exit
+- Generate configuration file for grub
+ `# grub-mkconfig -o /boot/grub/grub.cfg`
+- Enable Network, Bluetooth and Printer services for when the machine is booted
+ `# systemctl enable NetworkManager`
+ `# systemctl enable bluetooth`
+ `# systemctl enable cups.service`
+- Create a new user, `-m` is associate a home directory and `G` is the group the user will belong to being the `wheel` group
+ `useradd -mG wheel <username>`
+- Password for new user
+ `# passwd <username>`
+- Type in new password and retype it to verify
+- Enable sudo privileges for any user of the `wheel` group, replace vim with editor of choice
+ `# EDITOR=vim visudo`
+- Look for and uncomment `# %wheel ALL=(ALL) ALL`, save and exit
+- Exit installation and return to the installer
+ `# exit`
+- Unmount the partitions
+ `# umount -a`
+- Reboot
+ `# reboot`
+- Grub boot loader should load, press "enter" to boot the OS
+- If encrypted enter passphrase
+- Login as user with <username> and it's password
+- Check for IP
+ `$ ip a`
+- Login into wifi
+ `$ nmtui`
+ - Go to `Activate a connection`, select network to connect to, enter password and quit
-LANG=en_US.UTF-8
-hwclock --systohc
-ip a -- check for internet connection/ip addr(ess)
-ping www.archlinux.com -- check for internet connection part 2
-iwctl -- if using wifi
-lsblk -- list block
-gdisk /dev/sda -- partition disk
-n -- create new partition
-1 -- default partition number
-## enter default for first sector
-+300M -- for last sector(efi partition)
+ - Install yay package manager
+ `$ git clone https://aur.archlinux.org/yay.git`
+ `$ cd yay`
+ `$ makepkg -si PKGBUILD`
+ `$ cd`
+ `$ rm -rf yay`
-ef00 -- change partition type code to EFI system
-n -- create second partition number
-## all parameters are set to default (press enter 3 times) (first, last sector type code(Current type) )
+ - Install graphics card drivers
+ - If intel card:
+ `$ sudo pacman -S x86-video-intel`
+ - If amd card:
+ `$ sudo pacman -S x86-video-amdgpu`
+ - If nvidia card:
+ NOTE: First check up on archwiki to see what is supported and methods: https://wiki.archlinux.org/title/NVIDIA
+ `$ sudo pacman -S nvidia nvidia-utils nvidia-settings`
-w -- write(save) table to disk and exit
-lsblk -- list information about block devices
-mkfs.fat -F32 /dev/sda1 -- make file system partition for boot efi
-cryptsetup --cipher aes-xts-plain64 --hash sha512 --use-random --verify-passphrase luksFormat /dev/sda2 ## setup encryption with sha512 luks
-crypsetup luksOpen /dev/sda2 *name of encryption partition* ## naming your encryption partition and type your encryption passphrase
-mkfs.btrfs /dev/mapper/*name of encryption partition* format the encrypted partition
-lsblk -- check changes and see if everything is correct
-mount /dev/mapper/*name of encryption partition* /mnt ## mounting the partition and create sub volumes
-cd /mnt ## change directory to /mnt
-btrfs subvolume create @ ## create first subvolume as root
-btrfs subvolume create @home ## create second subvolume as home
-cd ## cd back to root directory
-umount /mnt ## unmount
-mount -o noatime,space_cache=v2,compress-zstd,ssd,discard=async,subvol=@ /dev/mapper/*name of encryption partition* /mnt ## mount 2 subvolumes with options 'no access time (makes access time of disk a little bit faster)', 'use space cache with version 2 since ver 1 doesn't work', 'compresstion method is zstd', 'ssd option if you have one', 'discard to optimize performance of the ssd' and use 'subwool to make sure this volume is equal to the roots of volume first' and then define the mapper device
-mkdir /mnt/{boot,home} ##create both at once
-mount -o noatime,space_cache=v2,compress-zstd,ssd,discard=async,subvol=@home /dev/mapper/*name of encryption partition* /mnt/home
-mount /dev/sda1 /mnt/boot
-pacstap /mnt base linux linux-firmware git vim man networkmanager
-genfstab -U /mnt >> /mnt/etc/fcstab
-arch-chroot /mnt
-vim /etc/mkinitcpio.conf
-## under modules ##
--- MODULES=(btrfs)
-## put encrypt between block and filesystems
-HOOKS=(base udev autodetect modconf block encrypt filesystems keyboard fsck)
-
-
-echo "arch" >> /etc/hostname
-echo "127.0.0.1 localhost" >> /etc/hosts
-echo "::1 localhost" >> /etc/hosts
-echo "127.0.1.1 arch.localdomain arch" >> /etc/hosts
-passwd # then enter your root password and verify it
-
-pacman -S grub efibootmgr networkmanager network-manager-applet dialog wpa_supplicant mtools dosfstools base-devel linux-headers avahi xdg-user-dirs xdg-utils gvfs gvfs-smb nfs-utils inetutils dnsutils bluez bluez-utils cups hplip alsa-utils pipewire pipewire-alsa pipewire-pulse pipewire-jack bash-completion openssh rsync reflector acpi acpi_call tlp virt-manager qemu qemu-arch-extra edk2-ovmf bridge-utils dnsmasq vde2 openbsd-netcat iptables-nft ipset firewalld flatpak sof-firmware nss-mdns acpid os-prober ntfs-3g terminus-font
diff --git a/linux/lvm.md b/linux/lvm.md
index e69de29..7329eb5 100644
--- a/linux/lvm.md
+++ b/linux/lvm.md
@@ -0,0 +1,82 @@
+### Create/Resize partitions using LVM (Logical Volume Manager)
+ Useful if we want a flexible disk storage that we either need to create separate partitions on, be able to resize them on the fly or create snapshots.
+ NOTE: LVM is exclusive to linux, no offical support in most other OS's (Windows,FreeBSD..) and is redundent on filesystems like BTRFS since it has it's own Subvolume feature.
+#### LVM Concepts:
+ LVM is a Linux's native paritition type, other partition types are PC (MBR or GPT) that are considered standard and don't have the cool features of LVM.
+ - Device Mapper or dev/mapper (not exclusive to LVM) is a framework for mapping physical block devices onto higher-level virtual block devices
+ - Physical Volumes occupy the "whole of" or a partition of the actual disks/drives that are phyically present.
+ - Volume Groups are the overall collection of one or more physical volumes that encompass/split logical volumes.
+ - Logical Volumes are the divided partitions of a volume group between potentially more than one disk/drive.
+ ```bash
+ ┌───────────────────────┐┌─────────────────────────────┐
+ │ Physical Hard Drive ││ Physical Hard Drive │
+ └───────────────────────┘└─────────────────────────────┘
+ ┌───────────────────────┐
+ │ Partition │
+ └───────────────────────┘
+ ┌───────────────────────┐┌───────────────────────┐
+ │ Physical Volume ││ Physical Volume │
+ └───────────────────────┘└───────────────────────┘
+ ┌────────────────────────────────────────────────┐
+ │ Volume Group │
+ └────────────────────────────────────────────────┘
+ ┌───────────────────┐ ┌──────────────────────────┐
+ │ Logical Volume │ │ Logical Volume │
+ └───────────────────┘ └──────────────────────────┘
+ ┌───────────────────┐ ┌──────────────────────────┐
+ │ Filesystem │ │ Filesystem │
+ └───────────────────┘ └──────────────────────────┘
+ ```
+#### Create/Extend/Reduce:
+ 1. First list/find out information about the partitions
+ `$ fdisk -l` # Needs root privileges,
+ `$ df -h` # Displays amount of disk space on filesystems, "-h" in human readable form
+ `$ lsblk` # List/find information about avaliable block devices/partitions
+ - Find info about VG(Volume Groups), PV(Physical Volumes) and LV(Logical Volumes):
+ - hello
+ `$ vgs` # Needs root privileges,
+ - hello
+ `$ lvs`
+ - Report information about Physical Volumes
+ `$ pvs` # Needs root privileges,
+
+ 2. Unmount the partition/filesystem making sure we are not on it:
+ NOTE: It is best not to be on the filesystem currently being managed although it's possible on EXT3 and EXT4 but BTRFS and ZFS need the use of a program called grow (still safe to gather/list information on them though).
+ - Change to a different user and kill any processes of the target filesystem's user.
+ `$ su root` # If going to change (extend/reduce) a user's filesystem
+ `$ pkill <user>` # Make sure user's processes aren't running
+ or
+ `$ su <user>` # If going to change (extend/reduce) the root's filesystem
+ then
+ `umount /dev/path/<home_or_root>`
+
+ 3. Create/resize partitions
+ - Create:
+ - Create the Logical Volume from existing free space within the Volume Group. The command below creates a LV with a size of 60GB from the VG called "vg1" and LV name is Stuff
+ NOTE: Always make meaningful volume and volume group names.
+ `$ lvcreate -L +60G --name Stuff vg1`
+ - Create a filesystem, creating the Logical Volume does not create the filesystem. The command below creates an EXT4 filesystem that fits the newly created Logical Volume.
+ `$ mkfs -t ext4 /dev/vg1/Stuff`
+Add a filesystem label
+
+Adding a filesystem label makes it easy to identify the filesystem later in case of a crash or other disk related problems.
+
+e2label /dev/MyVG01/Stuff Stuff
+ - Resize:
+ - Reduce the Logical Volume:
+ - Extend the Logical Volume:
+
+Extend the Logical Volume (LV) from existing free space within the Volume Group. The command below expands the LV by 50GB. The Volume Group name is MyVG01 and the Logical Volume Name is Stuff.
+
+lvextend -L +50G /dev/MyVG01/Stuff
+ sudo lvextend -l 100%VG -r /dev/mapper/vg1-root
+ 4. Mount the partition
+
+
+ ```
+ umount /dev/mapper/vg1-root
+ umount /dev/mapper/vg1-home
+ lvresize --resizefs -L -20G /dev/mapper/vg1-home
+ mount /dev/mapper/vg1-home
+ ```
+