From 64a6c7bd5ea4d44134992c1d18f41ec5191da776 Mon Sep 17 00:00:00 2001 From: Alex David Date: Wed, 3 Jun 2020 23:31:33 -0700 Subject: [PATCH] Update setup scripts Changes: * Use efistub instead of grub * Use swapfile on root partition instead of dedicated partition * Automate calling chroot script --- archlinux/setup/README.md | 29 +++++++++------------- archlinux/setup/chroot | 24 +++++++++++------- archlinux/setup/init | 52 ++++++++++++++++++++++++++------------- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/archlinux/setup/README.md b/archlinux/setup/README.md index f425ab5..5ad2e21 100644 --- a/archlinux/setup/README.md +++ b/archlinux/setup/README.md @@ -1,27 +1,20 @@ # My archlinux setup scripts +### Download: + ```shell -wget https://raw.githubusercontent.com/alexdavid/dotfiles/master/archlinux/setup/init -bash init -arch-chroot /mnt -``` -Add `encrypt` to `/etc/mkinitcpio.conf` hooks: -``` -HOOKS="base udev autodetect block encrypt filesystems keyboard fsck" +wget https://git.sr.ht/~alexdavid/dotfiles/blob/master/archlinux/setup/init +wget https://git.sr.ht/~alexdavid/dotfiles/blob/master/archlinux/setup/chroot ``` +### Verify: + ```shell -mkinitcpio -p linux -pacman -S wget sudo git binutils -wget https://raw.githubusercontent.com/alexdavid/dotfiles/master/archlinux/setup/chroot -bash chroot +sha1sum init chroot +``` -# optional if wifi-menu is needed after reboot: -pacman -S dialog wpa_supplicant +### Install: -exit -umount /mnt/boot -umount /mnt -cryptsetup close main -reboot +```shell +bash init ``` diff --git a/archlinux/setup/chroot b/archlinux/setup/chroot index a04873f..e1d6b10 100644 --- a/archlinux/setup/chroot +++ b/archlinux/setup/chroot @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e + function section { echo echo @@ -14,6 +16,19 @@ function ask { read $1 } +section "INSTALLING PACKAGES NEEDED AFTER REBOOT" +ask WIFI "Install wifi-menu? (yes/no)" +[ "$WIFI" == "yes" ] && pacman -S dialog wpa_supplicant +pacman -S \ + dhcpcd \ + netctl \ + sudo \ + vi \ + ; + +section "ADDING ENCRYPT TO MKINITCPIO" +vi /etc/mkinitcpio.conf +mkinitcpio -p linux section "SETTING LOCALE" echo "en_US.UTF-8 UTF-8" > /etc/locale.gen @@ -24,23 +39,14 @@ ln -f -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime ask HOSTNAME "Hostname" echo "$HOSTNAME" > /etc/hostname - section "SETTING ROOT PASSWORD" passwd - section "CREATING MAIN USER" ask USERNAME "Username" useradd -m -g users -G wheel "$USERNAME" passwd "$USERNAME" - -section "INSTALLING GRUB" -pacman -S grub efibootmgr -grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub -grub-mkconfig -o /boot/grub/grub.cfg - - section "SETTING UP SIMPLE FIREWALL" cp /etc/iptables/simple_firewall.rules /etc/iptables/iptables.rules systemctl enable iptables.service diff --git a/archlinux/setup/init b/archlinux/setup/init index eec2929..1d609c5 100644 --- a/archlinux/setup/init +++ b/archlinux/setup/init @@ -44,13 +44,8 @@ ask DRIVE "Select a drive" echo # (default 2048) echo "+512M" - echo n # Add new partition (swap) - echo # (default 2) - echo # (default) - echo "+2G" - echo n # Add new partition (linux) - echo # (default 3) + echo # (default 2) echo # (default) echo # (default) @@ -58,10 +53,6 @@ ask DRIVE "Select a drive" echo 1 # Partition number 1 (/boot) echo 1 # EFI System - echo t # Change partition type - echo 2 # Partition number 2 (swap) - echo 19 # Linux swap - echo w # write } | fdisk "$DRIVE" fdisk -l @@ -72,17 +63,44 @@ PARTITIONS=($(lsblk -pln -o name "$DRIVE")) section "FORMATTING & MOUNTING DRIVES" -cryptsetup luksFormat --type luks "${PARTITIONS[3]}" -cryptsetup luksOpen "${PARTITIONS[3]}" main +cryptsetup luksFormat --type luks "${PARTITIONS[2]}" +cryptsetup luksOpen "${PARTITIONS[2]}" main mkfs.vfat -F32 "${PARTITIONS[1]}" mkfs.ext4 -F /dev/mapper/main mount /dev/mapper/main /mnt mkdir /mnt/boot mount "${PARTITIONS[1]}" /mnt/boot -# Install base -pacstrap /mnt base -genfstab -U /mnt >> /mnt/etc/fstab +section "CREATING SWAPFILE" +ask SWAPSIZE "Swapfile size (e.g. 4G)" +mkdir /mnt/var +fallocate -l "$SWAPSIZE" /mnt/var/swap +chmod 600 /mnt/var/swap +mkswap /mnt/var/swap -# Setup grub cryptmapper -echo "GRUB_CMDLINE_LINUX=\"cryptdevice=${PARTITIONS[3]}:cryptroot\"" >> /mnt/etc/default/grub +section "INSTALLING BASE" +pacstrap /mnt base linux linux-firmware +genfstab -U /mnt >> /mnt/etc/fstab +echo "/var/swap none swap defaults 0 0" >> /mnt/etc/fstab + +section "KICKING OFF CHROOT SCRIPT" +mv chroot /mnt/chroot +arch-chroot /mnt bash /chroot +rm /mnt/chroot + +section "CREATING EFISTUB BOOT ENTRY" +ask EFILABEL "EFI label" +PARTUUID=$(lsblk -dno PARTUUID ${PARTITIONS[2]}) +efibootmgr \ + --disk "$DRIVE" \ + --create \ + --label "$EFILABEL" \ + --loader /vmlinuz-linux \ + --unicode "cryptdevice=PARTUUID=$PARTUUID:root root=/dev/mapper/root rw initrd=\\initramfs-linux.img" \ + --verbose \ + ; + +section "CLEANING UP" +umount /mnt/boot +umount /mnt +cryptsetup close main -- 2.30.2