#!/bin/bash # archinst - v1.3.9 # Copyight (c) 2024 Joseph Chris under MIT License # # Simple Arch Linux installation script # version="1.3.9" echo "=========================================================" echo " archinst.sh version $version by Joseph Chris" echo "=========================================================" echo " BEFORE INSTALL" echo " 1. Connect to Internet" echo " 2. Complete the partition and mount to /mnt" echo " a. UEFI+GPT: Ensure ESP partition mounted to /efi" echo " b. BIOS+GPT: Require 2MB partition type 'bios boot'" echo " b. UEFI+MBR: NOT SUPPORTTED/POSSIBLE BY THIS SCRIPT" echo " SEE: https://wiki.archlinux.org/title/Partitioning" echo " 3. LUKS is not supported." echo " 4. If you are not ready, press Ctrl+C to exit!" echo "=========================================================" echo -e "\n\n" install_default="base linux linux-firmware vim openssh lvm2 mdadm btrfs-progs dosfstools exfatprogs jfsutils xfsprogs" echo "Will install: $install_default" read -p "Enter other packages? " install install="$install_default $install" echo "Ok, we will install: $install" read -p "What timezone are you using? [UTC] " timezone if [ ! -f "/mnt/usr/share/zoneinfo/$timezone" ]; then echo "I can not find the timezone. Set to UTC." timezone=UTC fi echo "Locale: we will set en_US.UTF-8 as default. You can change it later after system installation." read -p "What is your hostname? [archlinux] " sethostname if [ -z $sethostname ]; then sethostname=archlinux fi github="" read -p "Do you want to import SSH key from GitHub? [GitHub Username/leave it blank] " github if [ ! -z $github ]; then echo "Added install openssh." install="$install openssh" fi if [ ! -d /sys/firmware/efi/efivars ]; then bootmode=bios else bootmode=uefi fi # Will always set root password set_root_password=Yes # read -p "Do you want to set root password later? [y/n] " set_root_password # if [ $set_root_password = "y" ]; then # set_root_password=Yes # else # set_root_password=No # fi mbresp="(none)" read -p "Install GRUB? [y/n] " grub if [ $grub = "y" ]; then grub=Yes if [ $bootmode = "bios" ]; then read -p "Which disk to install MBR? [/dev/sda] " mbresp if [ -z $mbresp ]; then mbresp=/dev/sda fi echo "Install MBR to $mbresp" else read -p "Which dir to install GRUB EFI? [/efi] " mbresp if [ -z $mbresp ]; then mbresp=/efi fi echo "Install GRUB EFI to $mbresp" fi else grub=No fi # confirm pkgarray=($install) echo "=========================================================" echo " Installation Summary " echo "=========================================================" echo " Timezone: $timezone" echo " Locale: en_US.UTF-8" echo " Hostname: $sethostname" echo " Boot Type: $bootmode" echo " Set Password: $set_root_password" echo " GitHub SSH Key: $github" echo " Install GRUB: $grub" echo " MBR/ESP: $mbresp" echo " Packages: [See Below]" for pkg in "${pkgarray[@]}"; do echo " $pkg " done echo "=========================================================" read -p "Is that right? [y/n] " confirm if [ $confirm != "y" ]; then echo "Abort" exit 2 fi # start installation echo "Setting up time..." timedatectl set-ntp true timedatectl status echo "Updating keyring..." echo "pacman -Sy archlinux-keyring" yes | pacman -Sy archlinux-keyring echo "Installing base system..." echo "pacstrap /mnt base linux linux-firmware $install" pacstrap /mnt base linux linux-firmware $install echo "Generating fstab..." genfstab -U /mnt >> /mnt/etc/fstab echo "Setting up timezone..." arch-chroot /mnt ln -sf /usr/share/zoneinfo/$timezone /etc/localtime arch-chroot /mnt hwclock --systohc echo "Setting up locale..." cp /mnt/etc/locale.gen /mnt/etc/locale.gen.available echo "en_US.UTF-8 UTF-8" > /mnt/etc/locale.gen echo "LANG=en_US.UTF-8" > /mnt/etc/locale.conf arch-chroot /mnt locale-gen echo "Setting up hostname..." echo "$sethostname" > /mnt/etc/hostname echo "127.0.0.1 localhost" >> /mnt/etc/hosts echo "::1 localhost" >> /mnt/etc/hosts echo "127.0.0.1 $sethostname" >> /mnt/etc/hosts if [ ! -z $github ]; then echo "Installing SSH Keys of GitHub user $github..." mkdir -p /mnt/root/.ssh curl https://github.com/$github.keys -o /mnt/root/.ssh/authorized_keys chmod 600 /mnt/root/.ssh/authorized_keys arch-chroot /mnt systemctl enable sshd echo "SSH Key:" cat /mnt/root/.ssh/authorized_keys fi for netif_class in /sys/class/net/*; do netif_name=$(basename $netif_class) netif_addr=$(cat /sys/class/net/$netif_name/address) if [ $netif_name != "lo" ]; then echo "Setting up network interface $netif_name..." cat > /mnt/etc/systemd/network/$netif_name.network <> /mnt/etc/resolv.conf arch-chroot /mnt ln -sf /usr/bin/vim /usr/bin/vi echo "Updating initramfs..." # https://wiki.archlinux.org/title/Installation_guide_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) # https://wiki.archlinux.org/title/Mkinitcpio_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) # https://wiki.archlinux.org/title/Install_Arch_Linux_on_LVM#Configure_the_system # https://wiki.archlinux.org/title/Dm-crypt/Encrypting_an_entire_system # https://wiki.archlinux.org/title/RAID_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) initramfs_hooks="base udev autodetect keyboard keymap consolefont modconf block filesystems mdadm_udev encrypt lvm2 keyboard fsck" initramfs_modules="dm-raid dm_integrity raid0 raid1 raid10 raid456" sed -i "s/^HOOKS=(.*)/HOOKS=($initramfs_hooks)/g" /mnt/etc/mkinitcpio.conf sed -i "s/^MODULES=(.*)/MODULES=($initramfs_modules)/g" /mnt/etc/mkinitcpio.conf while read -r dm_tabline;do dm_dev_name=$(echo "$dm_tabline" | cut -d":" -f1) dm_dev_uuid=$(echo "$dm_tabline" | cut -d" " -f6 | cut -d":" -f5) echo -e "$dm_dev_name\t$dm_dev_uuid" >> /mnt/etc/crypttab done <<< $(dmsetup table --target crypt) arch-chroot /mnt mkinitcpio -P if [ $set_root_password = "Yes" ]; then echo "Please set root password." arch-chroot /mnt passwd fi if [ $grub != "No" ]; then echo "Installing GRUB... You have 5 seconds to press Ctrl-C to abrot." sleep 5 if [ $bootmode = "uefi" ]; then arch-chroot /mnt pacman -Syy grub efibootmgr echo "Install GURB x86_64-efi to $mbresp..." arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=$mbresp --bootloader-id=GRUB else arch-chroot /mnt pacman -Syy grub echo "Install GRUB i386-pc to $mbresp..." arch-chroot /mnt grub-install --target=i386-pc $mbresp fi sed -i "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"\"/g" /mnt/etc/default/grub echo "Generating GRUB configuration..." arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg fi # print notes echo "Done! Welcome to be an Archman!" echo "Content of fstab:" cat /mnt/etc/fstab cat << EOF ========================================================= INSTALL COMPLETE ========================================================= PLEASE DO STEPS BELOW THESE STEPS WILL NOT DONE AUTOMATICALLY: 1. CHECK /mnt/etc/fstab BEFORE REBOOT! 2. Update microcodes IN CHROOT: pacman -Syy amd-ucode pacman -Syy intel-ucode ========================================================= EOF