Skip to content

Instantly share code, notes, and snippets.

@tonylambiris
Forked from Razz/arch.md
Last active June 19, 2019 19:26
Show Gist options
  • Save tonylambiris/65f05f3178345d07840d0d833c826801 to your computer and use it in GitHub Desktop.
Save tonylambiris/65f05f3178345d07840d0d833c826801 to your computer and use it in GitHub Desktop.
install arch

Write USB install key (OSX specific)

# diskutil list
# disutil unmount /dev/diskX
// Dont forget the r in rdisk
# sudo dd if=/path/to/arch.iso of=/dev/rdiskX bs=4M status=progress

Connect to wifi after booting USB

root@archiso ~ # wifi-menu -o

Find the target disk device to install

We'll assume /dev/sda4, so sub that for yours

root@archiso ~ # fdisk -l

Resize an existing NTFS partition

// Get the estimated smallest size (in MB) for Windows
root@archiso ~ # ntfsresize -m /dev/sda3
// Perform a read-only test for resizing to > 2x smallest size
root@archiso ~ # ntfsresize --no-action --size 100G /dev/sda3
// Perform the resize
root@archiso ~ # ntfsresize --size 100G /dev/sda3
// Configure partitions (refer to https://goo.gl/o2NELB for an example)
root@archiso ~ # gdisk /dev/sda
// Finalize NTFS partition resizing
root@archiso ~ # ntfsresize -f -v /dev/sda3

Setup disk encryption

root@archiso ~ # cryptsetup -c aes-xts-plain64 -y --use-random --type luks1 luksFormat /dev/sda4
root@archiso ~ # cryptsetup open --type luks1 /dev/sda4 arch

Create LVM devices

root@archiso ~ # pvcreate /dev/mapper/arch
root@archiso ~ # vgcreate arch /dev/mapper/arch
root@archiso ~ # lvcreate --size 1024M arch --name swap
root@archiso ~ # lvcreate --size 500M arch --name boot
root@archiso ~ # lvcreate -l +100%FREE arch --name root

Verify creation of new volumes

root@archiso ~ # ls /dev/mapper/

Create filesystems

root@archiso ~ # mkswap /dev/mapper/arch-swap -L SWAP
root@archiso ~ # mkfs.ext4 /dev/mapper/arch-boot -m 1 -L BOOT
// Create a ext4 filesystem
root@archiso ~ # mkfs.ext4 /dev/mapper/arch-root -m 1 -L ROOT
// Create a btrfs filesystem
root@archiso ~ # mkfs.btrfs /dev/mapper/arch-root -L ROOT

Mount the paths for the chroot

root@archiso ~ # mount /dev/mapper/arch-root /mnt
root@archiso ~ # mkdir /mnt/boot
root@archiso ~ # mount /dev/mapper/arch-boot /mnt/boot
root@archiso ~ # mkdir /mnt/boot/efi
root@archiso ~ # mount /dev/sda1 /mnt/boot/efi
// Activate swap (needed when generating fstab)
root@archiso ~ # swapon /dev/mapper/arch-swap

Bootstrap the chroot

root@archiso ~ # pacstrap /mnt base base-devel grub-efi-x86_64 efibootmgr refind-efi intel-ucode btrfs-progs net-tools wpa_supplicant zsh vim git dialog ntp terminus-font

Generate fstab

root@archiso ~ # genfstab -pU /mnt >> /mnt/etc/fstab

Define a ramdisk for /tmp (not required)

root@archiso ~ # echo -e "tmpfs\t/tmp\ttmpfs\tdefaults,noatime,mode=1777\t0 0\n" >> /mnt/etc/fstab

Change relatime to noatime on all non-boot partitions (reduces wear if using an SSD)

root@archiso ~ # sed -i -re '/boot/! s/relatime/noatime/g' /mnt/etc/fstab

Enter the chroot

root@archiso ~ # arch-chroot /mnt

Setup system timezone

[root@archiso /]# ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

Update system time

[root@archiso /]# ntpdate pool.ntp.org

Generate system clock drift file

[root@archiso /]# hwclock --systohc

Set LANG in /etc/locale.conf

[root@archiso /]# echo LANG=en_US.UTF-8 >> /etc/locale.conf

Set KEYMAP and FONT in /etc/vconsole.conf

[root@archiso /]# cat >> /etc/vconsole.conf <<-EOT
KEYMAP=us
FONT=ter-p28n
EOT

Set the hostname

[root@archiso /]# echo myhostname > /etc/hostname

Write /etc/hosts with new hostname

[root@archiso /]# cat >> /etc/hosts <<-EOT
127.0.0.1       localhost.localdomain   localhost
::1             localhost.localdomain   localhost
127.0.1.1       myhostname.localdomain  myhostname
EOT

Generate the locale for en_US.UTF-8

[root@archiso /]# sed -i -re '/#en_US.UTF-8/ s/^#(.*)$/\1/g' /etc/locale.gen
[root@archiso /]# locale-gen -a

Set a password for root

[root@archiso /]# passwd

Create a regular user (and set a password)

[root@archiso /]# useradd -m -g users -c 'User Name' -s /bin/zsh myusername
[root@archiso /]# passwd myusername
// Add user to supplemental groups (optional but highly recommended)
[root@archiso /]# usermod -G wheel,disk,network,video,audio,optical,floppy,storage,scanner,input,power myusername

Update /etc/mkinitcpio.conf to include modules and hooks

Add 'ext4' and 'btrfs' to MODULES=() Add 'encrypt' and 'lvm2' to HOOKS=() after 'block' but before 'filesystems'

Regenerate initrd image

[root@archiso /]# mkinitcpio -p linux

Configure options in /etc/default/grub

Uncomment GRUB_ENABLE_CRYPTODISK=y Edit GRUB_CMDLINE_LINUX= to include cryptdevice=/dev/sda4:arch:allow-discards

Example output:

[root@archiso /]# egrep "^(GRUB_ENABLE_CRYPTO|GRUB_CMDLINE_LINUX)" /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash biosdevname=0 net.ifnames=0 processor.ignore_ppc=1 acpi_osi=Linux"
GRUB_CMDLINE_LINUX="cryptdevice=/dev/sda4:arch:allow-discards scsi_mod.use_blk_mq=y dm_mod.use_blk_mq=y"
GRUB_ENABLE_CRYPTODISK=y

Install grub and write updated configuration

[root@archiso /]# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch --recheck
[root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg

Install rEFInd (optional, useful if dual-booting with Windows)

[root@archiso /]# refind-install --alldrivers --yes

Note: If your system doesn't detect a rEFInd entry, re-run the above command after booting into your new system.

Exit the chroot

[root@archiso /]# exit

Unmount and deactivate all partitions

root@archiso ~ # umount -R /mnt
root@archiso ~ # swapoff -a

Reboot into the new system (don't forget to remove the cd/usb)

root@archiso ~ # reboot

Configure the system to only prompt once for luks password

Follow this guide: https://gist.github.com/tonylambiris/756a71208e692f4f6a6e4ca4bd9408ac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment