User:M0p/Installation

From ArchWiki

Variables

Basics

In this step, we will set some variables for basic system settings.

DISK=/dev/disk/by-id/nvme-PM951_NVMe_SAMSUNG_512GB__S29PNXAH110182
TARGET_USERNAME='YOUR USERNAME'
TARGET_HOSTNAME='YOUR HOSTNAME'
ENCRYPTION_PWD='YOUR DISK ENCRYPTION PASSWORD, 8 MINIMUM'
TARGET_USERPWD='YOUR USER PASSWORD'
TARGET_TIMEZONE='YOUR TIMEZONE, as in "GMT-8"'
MOUNTPOINT=/mnt

Specific variables

See respective pages for details

Partitioning

Layout

  1. EFI system partition
  2. Optional /boot partition for specific cases
  3. / partition

Command

Create an empty GPT partition table

sgdisk --zap-all $DISK

Create EFI partition

sgdisk -n1:0:512M -t1:EF00 $DISK

Create additional partitions

sgdisk -n2:0:1G $DISK
sgdisk -n3:0:2G $DISK
...

Newly created partitions will be available at

$DISK-part2
$DISK-part3

Format and mount partitions

See respective pages for details

Format and mount EFI partition

Format EFI partition

mkfs.vfat -n EFI $DISK-part1

Create mountpoint

mkdir $MOUNTPOINT/efi

Mount

mount $DISK-part1 $MOUNTPOINT/efi

Install packages

Barebone

pacstrap $MOUNTPOINT base linux-lts arch-install-scripts gdisk sudo nano dosfstools mkinitcpio grub efibootmgr

Filesystem specific packages, example

  • ZFS
pacstrap $MOUNTPOINT archzfs-linux-lts
  • Btrfs
pacstrap $MOUNTPOINT cryptsetup btrfs-progs snapper snap-pac grub-btrfs

Other packages for different purposes, example

Generate /etc/fstab

Generally this command would be sufficient

genfstab -U $MOUNTPOINT >> $MOUNTPOINT/etc/fstab

But there are also cases where manual modification is needed

Hostname

echo $TARGET_HOSTNAME > $MOUNTPOINT/etc/hostname

Allow wheel user to use sudo

mv $MOUNTPOINT/etc/sudoers $MOUNTPOINT/etc/sudoers.original
tee $MOUNTPOINT/etc/sudoers << EOF
root ALL=(ALL) ALL
%wheel ALL=(ALL) ALL
@includedir /etc/sudoers.d
EOF

Edit and /etc/default/grub and /etc/mkinitcpio.conf

This is filesystem specific

Enter the new system

Pass all installation variables to chroot. #Specific variables are not included in this example.

arch-chroot $MOUNTPOINT /usr/bin/env DISK=$DISK PROPS=$PROPS TARGET_TIMEZONE=$TARGET_TIMEZONE TARGET_USERPWD=$TARGET_USERPWD TARGET_USERNAME=$TARGET_USERNAME bash --login

Add user and set user password

If user home was not created during #Format and mount partitions

useradd -s /bin/bash -U -G wheel,video -m --btrfs-subvolume-home $TARGET_USERNAME
echo "$TARGET_USERNAME:$TARGET_USERPWD" | chpasswd

If user home was created during #Format and mount partitions

useradd -s /bin/bash -U -G wheel,video -d /home/$TARGET_USERNAME $TARGET_USERNAME
cp /etc/skel/.* /home/$TARGET_USERNAME
chown -R $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME
echo "$TARGET_USERNAME:$TARGET_USERPWD" | chpasswd

If use Btrfs, use the following useradd command to take advantage of subvolumes

useradd -s /bin/bash -U -G wheel,video -m --btrfs-subvolume-home $TARGET_USERNAME
echo "$TARGET_USERNAME:$TARGET_USERPWD" | chpasswd

Set timezone

ln -sf /usr/share/zoneinfo/Etc/$TARGET_TIMEZONE /etc/localtime

Enable system services

This is specific to different use cases. Generally a networking manager need to be activated

systemctl enable NetworkManager.service

Generate initramfs

mkinitcpio -P

Install GRUB

Generally the following commands would suffice, but there are still exceptions

grub-install --bootloader-id=$DISTRO
grub-mkconfig -o /boot/grub/grub.cfg

Unmount

After exiting chroot, umount target disk

mount | grep "$MOUNTPOINT/" | tac | awk "/\$MOUNTPOINT/ {print $3}" | xargs -i{} umount -lf {}
umount $MOUNTPOINT/efi