2021-01-31 08:36:10 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-02-01 03:13:05 -05:00
|
|
|
# Unmounting partitions.
|
|
|
|
echo "Unmounting /mnt in order to proceed with the installation of Arch Linux."
|
|
|
|
umount -R /mnt
|
|
|
|
|
2021-01-31 10:28:23 -05:00
|
|
|
# Exit on STDERR.
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Setting up the correct time.
|
2021-02-01 03:16:23 -05:00
|
|
|
timedatectl set-ntp true &>/dev/null
|
2021-01-31 10:28:23 -05:00
|
|
|
|
2021-01-31 08:36:10 -05:00
|
|
|
# Selecting the target for the installation.
|
|
|
|
echo "Select the disk where Arch Linux is going to be installed."
|
2021-01-31 15:57:34 -05:00
|
|
|
select ENTRY in $(lsblk -dpn -oNAME);
|
2021-01-31 08:36:10 -05:00
|
|
|
do
|
|
|
|
DISK=$ENTRY
|
|
|
|
echo "Installing Arch Linux on $DISK."
|
|
|
|
break
|
|
|
|
done
|
|
|
|
|
|
|
|
# Deleting old partition scheme.
|
|
|
|
read -r -p "This will delete the current partition table on $DISK. Do you agree [y/N]? " response
|
|
|
|
response=${response,,}
|
|
|
|
if [[ "$response" =~ ^(yes|y)$ ]]
|
|
|
|
then
|
2021-02-01 03:16:23 -05:00
|
|
|
wipefs -af $DISK &>/dev/null
|
|
|
|
sgdisk -Zo $DISK &>/dev/null
|
2021-01-31 08:36:10 -05:00
|
|
|
else
|
2021-02-01 03:13:05 -05:00
|
|
|
echo "Quitting."
|
|
|
|
exit
|
2021-01-31 08:36:10 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Creating a new partition scheme.
|
|
|
|
echo "Creating new partition scheme on $DISK."
|
|
|
|
parted -s $DISK \
|
2021-01-31 08:50:43 -05:00
|
|
|
mklabel gpt \
|
|
|
|
mkpart ESP fat32 1MiB 513MiB \
|
|
|
|
mkpart Cryptroot 513MiB 100% \
|
2021-01-31 08:36:10 -05:00
|
|
|
|
|
|
|
ESP="/dev/disk/by-partlabel/ESP"
|
|
|
|
Cryptroot="/dev/disk/by-partlabel/Cryptroot"
|
|
|
|
echo "Done."
|
|
|
|
|
|
|
|
partprobe $DISK
|
|
|
|
|
|
|
|
# Formatting the ESP as FAT32.
|
|
|
|
echo "Formatting the EFI Partition as FAT32."
|
2021-02-01 03:16:23 -05:00
|
|
|
mkfs.fat -F 32 $ESP &>/dev/null
|
2021-01-31 08:36:10 -05:00
|
|
|
|
|
|
|
# Creating a LUKS Container for the root partition.
|
|
|
|
echo "Creating LUKS Container for the root partition."
|
|
|
|
cryptsetup --type luks1 luksFormat $Cryptroot
|
|
|
|
echo "Opening the newly created LUKS Container."
|
|
|
|
cryptsetup open $Cryptroot cryptroot
|
|
|
|
BTRFS=/dev/mapper/cryptroot
|
|
|
|
|
|
|
|
# Formatting the LUKS Container as BTRFS.
|
|
|
|
echo "Formatting the LUKS container as BTRFS."
|
2021-02-01 03:16:23 -05:00
|
|
|
mkfs.btrfs $BTRFS &>/dev/null
|
2021-01-31 08:36:10 -05:00
|
|
|
mount $BTRFS /mnt
|
|
|
|
|
|
|
|
# Creating BTRFS subvolumes.
|
|
|
|
echo "Creating BTRFS subvolumes."
|
2021-02-01 03:16:23 -05:00
|
|
|
btrfs su cr /mnt/@ &>/dev/null
|
|
|
|
btrfs su cr /mnt/@home &>/dev/null
|
|
|
|
btrfs su cr /mnt/@snapshots &>/dev/null
|
|
|
|
btrfs su cr /mnt/@var_log &>/dev/null
|
|
|
|
btrfs su cr /mnt/@swap &>/dev/null
|
2021-01-31 08:36:10 -05:00
|
|
|
|
|
|
|
# Mounting the newly created subvolumes.
|
|
|
|
umount /mnt
|
2021-01-31 09:07:17 -05:00
|
|
|
echo "Mounting the newly created subvolumes."
|
2021-01-31 08:36:10 -05:00
|
|
|
mount -o compress=zstd,subvol=@ $BTRFS /mnt
|
|
|
|
mkdir -p /mnt/{home,.snapshots,/var/log,swap,boot}
|
|
|
|
mount -o compress=zstd,subvol=@home $BTRFS /mnt/home
|
|
|
|
mount -o compress=zstd,subvol=@snapshots $BTRFS /mnt/.snapshots
|
|
|
|
mount -o nodatacow,subvol=@var_log $BTRFS /mnt/var/log
|
|
|
|
mount -o nodatacow,subvol=@swap $BTRFS /mnt/swap
|
|
|
|
mount $ESP /mnt/boot
|
2021-01-31 09:07:17 -05:00
|
|
|
|
|
|
|
# Pacstrap (setting up a base sytem onto the new root).
|
|
|
|
echo "Installing the base sytem."
|
2021-02-01 03:16:23 -05:00
|
|
|
pacstrap /mnt base linux linux-firmware btrfs-progs grub grub-btrfs efibootmgr snapper sudo neovim networkmanager &>/dev/null
|
2021-01-31 09:07:17 -05:00
|
|
|
|
|
|
|
# Fstab generation.
|
|
|
|
echo "Generating a new fstab."
|
2021-01-31 09:29:22 -05:00
|
|
|
genfstab -U /mnt >> /mnt/etc/fstab
|
|
|
|
|
|
|
|
# Setting hostname.
|
2021-02-01 01:02:41 -05:00
|
|
|
read -r -p "Please enter the hostname: " hostname
|
2021-01-31 09:29:22 -05:00
|
|
|
echo $hostname > /mnt/etc/hostname
|
|
|
|
|
2021-02-01 01:02:41 -05:00
|
|
|
# Setting up locales.
|
|
|
|
read -r -p "Please insert the locale you use in this format (xx_XX.UTF-8): " locale
|
|
|
|
echo "$locale UTF-8" > /mnt/etc/locale.gen
|
|
|
|
echo "LANG=\"$locale\"" > /mnt/etc/locale.conf
|
|
|
|
|
|
|
|
# Setting up keyboard layout.
|
|
|
|
read -r -p "Please insert the keyboard layout you use: " kblayout
|
|
|
|
echo "KEYMAP=\"$kblayout\"" > /mnt/etc/vconsole.conf
|
|
|
|
|
2021-01-31 09:29:22 -05:00
|
|
|
# Setting hosts file.
|
|
|
|
echo "Setting hosts file."
|
|
|
|
cat > /mnt/etc/hosts <<EOF
|
|
|
|
127.0.0.1 localhost
|
|
|
|
::1 localhost
|
|
|
|
127.0.1.1 $hostname.localdomain $hostname
|
|
|
|
EOF
|
|
|
|
|
2021-01-31 12:20:13 -05:00
|
|
|
# Configuring /etc/mkinitcpio.conf
|
|
|
|
echo "Configuring /etc/mkinitcpio for ZSTD compression, BTRFS and LUKS hook."
|
|
|
|
sed -i -e 's,BINARIES=(),BINARIES=(/usr/bin/btrfs),g' /mnt/etc/mkinitcpio.conf
|
|
|
|
sed -i -e 's,#COMPRESSION="zstd",COMPRESSION="zstd",g' /mnt/etc/mkinitcpio.conf
|
|
|
|
sed -i -e 's,modconf block filesystems keyboard,keyboard keymap modconf block encrypt filesystems,g' /mnt/etc/mkinitcpio.conf
|
|
|
|
|
2021-02-01 01:20:36 -05:00
|
|
|
# Enabling LUKS in GRUB and setting the UUID of the LUKS container.
|
2021-01-31 12:20:13 -05:00
|
|
|
UUID=$(blkid $Cryptroot | cut -f2 -d'"')
|
|
|
|
sed -i 's/#\(GRUB_ENABLE_CRYPTODISK=y\)/\1/' /mnt/etc/default/grub
|
2021-01-31 14:03:03 -05:00
|
|
|
sed -i -e "s,quiet,quiet cryptdevice=UUID=$UUID:cryptroot root=$BTRFS,g" /mnt/etc/default/grub
|
2021-01-31 12:20:13 -05:00
|
|
|
|
|
|
|
# Creating a swapfile.
|
2021-02-01 01:20:36 -05:00
|
|
|
read -r -p "Do you want a swapfile? [y/N]? " response
|
|
|
|
response=${response,,}
|
|
|
|
if [[ "$response" =~ ^(yes|y)$ ]]
|
|
|
|
then
|
|
|
|
read -r -p "How much big should the swap file be? Type the size, just a number (eg: 1 = 1GB..): " swap
|
|
|
|
truncate -s 0 /mnt/swap/swapfile
|
|
|
|
chattr +C /mnt/swap/swapfile
|
2021-02-01 03:16:23 -05:00
|
|
|
btrfs property set /mnt/swap/swapfile compression none &>/dev/null
|
|
|
|
dd if=/dev/zero of=/mnt/swap/swapfile bs=1G count=$swap &>/dev/null
|
2021-02-01 01:20:36 -05:00
|
|
|
chmod 600 /mnt/swap/swapfile
|
2021-02-01 03:16:23 -05:00
|
|
|
mkswap /mnt/swap/swapfile &>/dev/null
|
|
|
|
swapon /mnt/swap/swapfile &>/dev/null
|
2021-02-01 01:20:36 -05:00
|
|
|
echo "/swap/swapfile none swap defaults 0 0" >> /mnt/etc/fstab
|
|
|
|
else
|
2021-02-01 03:13:52 -05:00
|
|
|
echo "Deleting BTRFS swap subvolume."
|
2021-02-01 03:09:08 -05:00
|
|
|
mount $BTRFS -o subvolid=5 /home
|
2021-02-01 03:16:23 -05:00
|
|
|
btrfs su de /home/@swap &>/dev/null
|
2021-02-01 03:08:10 -05:00
|
|
|
umount -R /home
|
|
|
|
echo "No swapfile has been added."
|
2021-02-01 01:20:36 -05:00
|
|
|
fi
|
2021-01-31 12:20:13 -05:00
|
|
|
|
2021-01-31 12:26:22 -05:00
|
|
|
# Configuring the system.
|
2021-01-31 12:20:13 -05:00
|
|
|
arch-chroot /mnt /bin/bash -xe <<"EOF"
|
2021-01-31 12:26:22 -05:00
|
|
|
|
2021-01-31 12:20:13 -05:00
|
|
|
# Setting up clock.
|
|
|
|
hwclock --systohc
|
|
|
|
|
|
|
|
# Generating locales.
|
|
|
|
locale-gen
|
|
|
|
|
|
|
|
# Generating a new initramfs.
|
2021-01-31 14:45:13 -05:00
|
|
|
mkinitcpio -P
|
2021-01-31 12:20:13 -05:00
|
|
|
|
|
|
|
# Installing Grub.
|
|
|
|
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
|
|
|
|
|
|
|
|
# Creating grub config file.
|
|
|
|
grub-mkconfig -o /boot/grub/grub.cfg
|
2021-01-31 12:26:22 -05:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Setting root password.
|
2021-02-01 02:46:53 -05:00
|
|
|
echo "Setting root password."
|
2021-01-31 12:26:22 -05:00
|
|
|
arch-chroot /mnt /bin/passwd
|
|
|
|
|
|
|
|
# Enabling auto-trimming.
|
|
|
|
echo "Enabling auto-trimming."
|
2021-02-01 03:16:23 -05:00
|
|
|
systemctl enable fstrim.timer --root=/mnt &>/dev/null
|
2021-01-31 12:26:22 -05:00
|
|
|
|
|
|
|
# Enabling NetworkManager.
|
|
|
|
echo "Enabling NetworkManager."
|
2021-02-01 03:16:23 -05:00
|
|
|
systemctl enable NetworkManager --root=/mnt &>/dev/null
|
2021-01-31 14:45:13 -05:00
|
|
|
|
|
|
|
# Unmounting partitions.
|
2021-02-01 03:13:05 -05:00
|
|
|
echo "Unmounting /mnt."
|
2021-01-31 14:45:13 -05:00
|
|
|
umount -R /mnt
|
2021-02-01 03:13:05 -05:00
|
|
|
echo "Done, you may now wish to reboot."
|
2021-01-31 15:57:34 -05:00
|
|
|
exit
|