Arch-Linux-Installer/install.sh

409 lines
9.2 KiB
Bash
Raw Normal View History

2022-02-13 16:18:55 +01:00
#!/bin/bash
2022-02-14 14:48:27 +01:00
### Variables:
# $dsks = whole lsblk output (e.g. "sda 1,0T, sdb ..")
# $disk = only selected disk (e.g. "sdc 500G")
# $dev = selected disk without size (e.g. "sdd")
# $main = main partition (e.g. "sde2")
# $szmn = size of the main partition (e.g. "50")
# szrt = size of root LVM volume
# $boot = boot partition (e.g. "sdf1")
# $host = hostname
# $user = username
# $pwur = user password
# $pwrt = root password
# $pwcr = encryption password
2022-03-28 13:04:15 +02:00
# $pwfr = password first
# $pwsc = password second
2022-02-14 14:48:27 +01:00
2022-02-14 00:37:10 +01:00
# Friendly introduction.
echo "Welcome to the Arch Linux installation script!"
2022-02-14 14:48:27 +01:00
echo "This script will ERASE ALL DATA on the partition you will choose next!"
2022-02-14 00:37:10 +01:00
echo
read -p "Do you want to continue? Type [Y]es or [N]o. " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
2022-02-16 14:57:02 +01:00
then
2022-02-14 00:37:10 +01:00
exit 1
fi
echo
2022-02-14 15:37:22 +01:00
# Selecting disk.
2022-02-15 18:00:02 +01:00
echo "1. PARTITIONING"
2022-02-13 16:18:55 +01:00
echo "Please select a disk to partition:"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Don't separate values by space.
IFS=$'\n'
# Set variable containing name and size of all disks.
2022-02-14 00:48:01 +01:00
dsks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') )
2022-02-13 16:18:55 +01:00
# Declare the array.
2022-02-14 00:48:01 +01:00
declare -a dsks
2022-02-13 16:18:55 +01:00
# Select value on array.
2022-02-14 00:48:01 +01:00
select dev in ${dsks[*]}
2022-02-13 16:18:55 +01:00
do
2022-02-14 15:40:42 +01:00
break
done
2022-02-15 18:00:02 +01:00
echo
2022-02-14 15:40:42 +01:00
2022-02-14 15:37:22 +01:00
# Separate values by spaces.
IFS=' '
# Create new variable of selection.
array=($dev)
dev="${array[0]}"
szmn="${array[1]%?}"
# Setting partition size.
echo "Your system partition has a size of $szmn GB."
2022-02-16 19:11:58 +01:00
echo "What size should your root volume have (GB)?"
2022-02-16 12:52:27 +01:00
echo "The rest will be used for your home volume."
2022-02-14 15:37:22 +01:00
read szrt
echo
2022-02-15 18:00:02 +01:00
echo "2. ENCRYPTION"
echo
2022-02-14 15:37:22 +01:00
# Setting encryption password.
2022-02-14 14:48:27 +01:00
echo "Choose a strong password for encrypting the primary partition:"
while [ -z "$pwcr" ]; do
echo "Please enter a password: "
read -s pwfr
read -s -p "Retype a password: " pwsc
if [ $pwfr == $pwsc ];
then
pwcr=$pwfr
echo
echo "Both passwords are the same. Continuing.."
else
echo
echo "You have entered different passwords. Try again.."
2022-03-28 12:56:49 +02:00
echo
continue
2022-02-14 14:48:27 +01:00
fi
2022-02-14 15:40:42 +01:00
break
done
2022-02-14 16:10:49 +01:00
echo
2022-02-14 15:40:42 +01:00
2022-02-15 18:00:02 +01:00
echo "3. HOSTNAME"
echo
2022-02-14 15:37:22 +01:00
# Setting hostname.
echo "Before installing the system, please enter a hostname:"
read host
echo
2022-02-14 14:48:27 +01:00
2022-02-15 18:00:02 +01:00
echo "4. ROOT PASSWORD"
echo
2022-02-14 15:37:22 +01:00
# Setting root password.
2022-02-14 16:10:49 +01:00
echo "Choose a password for the root account:"
2022-03-28 13:04:15 +02:00
while [ -z "$pwrt" ]; do
2022-02-14 15:37:22 +01:00
echo "Please enter a password: "
read -s pwfr
read -s -p "Retype a password: " pwsc
if [ $pwfr == $pwsc ];
then
pwrt=$pwfr
echo
echo "Both passwords are the same. Continuing.."
else
echo
echo "You have entered different passwords. Try again.."
2022-03-28 12:56:49 +02:00
echo
continue
2022-02-14 15:37:22 +01:00
fi
2022-02-14 15:40:42 +01:00
break
done
2022-02-14 16:10:49 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-02-15 18:00:02 +01:00
echo "4. USER"
echo
2022-02-14 15:37:22 +01:00
# Setting username
2022-02-15 18:00:02 +01:00
echo "Please enter a username:"
2022-02-14 15:37:22 +01:00
read user
echo
# Setting user password.
2022-02-14 16:10:49 +01:00
echo "Also please choose a password for your user:"
2022-03-28 13:04:15 +02:00
while [ -z "$pwur" ]; do
2022-02-14 15:37:22 +01:00
echo "Please enter a password: "
read -s pwfr
read -s -p "Retype a password: " pwsc
if [ $pwfr == $pwsc ];
then
pwur=$pwfr
echo
echo "Both passwords are the same. Continuing.."
else
echo
echo "You have entered different passwords. Try again.."
2022-03-28 12:56:49 +02:00
echo
continue
2022-02-14 15:37:22 +01:00
fi
2022-02-14 15:40:42 +01:00
break
done
2022-02-15 18:00:02 +01:00
echo
2022-02-14 15:37:22 +01:00
2022-02-15 18:00:02 +01:00
echo "5. INSTALLING SYSTEM.."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Starting partitioning.
echo "Partitioning /dev/$dev.."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Clearing partition table of selected disk.
echo "Clearing existing partitioning table."
sgdisk -Z /dev/$dev &&
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Creating boot partition.
2022-02-14 15:37:22 +01:00
#szmn="${array[1]%?}"
2022-02-13 16:18:55 +01:00
echo "Creating boot partition of 256 MB."
sgdisk -n 1:0:+256M /dev/$dev &&
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Setting type for EFI.
2022-02-16 19:11:58 +01:00
echo "Marking partition as boot."
2022-02-13 16:18:55 +01:00
sgdisk -t 1:ef00 /dev/$dev &&
2022-02-16 19:11:58 +01:00
echo
2022-02-13 16:18:55 +01:00
# Creating system partition.
2022-02-14 00:48:01 +01:00
echo "Creating system partition of $szmn GB."
2022-02-13 16:18:55 +01:00
sgdisk -n 2:0:0 /dev/$dev
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Print partitions.
echo "This is your new partition table:"
lsblk | grep "$dev"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-02-14 14:48:27 +01:00
# Get new variable.
2022-02-14 16:10:49 +01:00
main=${dev}2
2022-02-13 16:18:55 +01:00
# Encrypting partition.
2022-02-14 00:37:10 +01:00
echo "Encrypting system partition. This might take a while."
echo
2022-02-14 16:10:49 +01:00
echo -en "$pwcr\n$pwcr" | cryptsetup -c aes-xts-plain -s 512 luksFormat /dev/$main &&
2022-02-13 16:18:55 +01:00
echo "Partition successfully encrypted."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Opening encrypted partition and mounting at /dev/mapper/lvm.
2022-02-14 00:37:10 +01:00
echo "Decrypting.. This also might take a while."
echo
2022-02-14 16:10:49 +01:00
echo -en "$pwcr\n$pwcr" | cryptsetup luksOpen /dev/$main lvm &&
2022-02-14 00:37:10 +01:00
echo "Partition successfully opened."
echo
2022-02-13 16:18:55 +01:00
2022-02-14 00:48:01 +01:00
lsblk | grep "$dev"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Creating physical volume.
echo "Creating physical volume."
pvcreate /dev/mapper/lvm &&
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Creating volume group "main".
echo "Creating volume group."
vgcreate main /dev/mapper/lvm &&
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
# Creating logical volumes.
echo "Creating logical volumes for root and home."
2022-02-14 00:48:01 +01:00
lvcreate -L ${szrt}G -n root main &&
2022-02-13 16:18:55 +01:00
lvcreate -l 100%FREE -n home main &&
echo "Logical volumes successfully created."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
echo "Creating the filesystem."
2022-02-14 16:10:49 +01:00
boot=${dev}1
2022-02-13 16:18:55 +01:00
mkfs.fat -F 32 -n UEFI /dev/$boot &&
echo "Filesystem for boot successfully created."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
mkfs.ext4 -L root /dev/mapper/main-root &&
echo "Filesystem for root successfully created."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
mkfs.ext4 -L home /dev/mapper/main-home &&
echo "Filesystem for home successfully created."
2022-02-15 18:00:02 +01:00
echo "Done."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
echo "Mounting.."
2022-02-15 18:00:02 +01:00
mount /dev/mapper/main-root /mnt &&
mkdir /mnt/boot &&
mkdir /mnt/home &&
mount /dev/$boot /mnt/boot &&
mount /dev/mapper/main-home /mnt/home &&
2022-02-13 16:18:55 +01:00
echo "Mounting complete."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-02-15 18:00:02 +01:00
lsblk | grep "$dev"
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:18:55 +01:00
2022-02-13 16:25:31 +01:00
# Updating mirrors using reflector.
echo "Updating mirrors.."
2022-02-15 18:00:02 +01:00
reflector --verbose --latest 10 --country Germany --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist &&
2022-02-14 15:37:22 +01:00
#reflector --verbose --latest 10 --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist &&
2022-02-13 16:25:31 +01:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
echo "Updating keyring.."
pacman -Sy archlinux-keyring --noconfirm &&
echo "Done."
echo
2022-02-13 16:25:31 +01:00
# Installing base system.
echo "Installing basic packages.."
2022-02-13 16:36:40 +01:00
#pacstrap /mnt base base-devel firefox konsole linux linux-firmware linux-zen lvm2 networkmanager nano plasma-desktop sddm sddm-kcm &&
pacstrap /mnt base firefox konsole linux linux-firmware linux-zen lvm2 nano networkmanager plasma-desktop sddm sddm-kcm sudo &&
2022-02-13 16:25:31 +01:00
echo "Base system installed."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:25:31 +01:00
# Generating fstab.
echo "Generating fstab."
genfstab -Up /mnt > /mnt/etc/fstab &&
echo "Installed fstab."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
# Setting hostname.
2022-02-15 18:00:02 +01:00
echo "Setting hostname"
echo $host > /mnt/etc/hostname &&
echo "Done."
echo
2022-02-13 16:25:31 +01:00
# Setting locale.
echo "Setting and generating locale."
2022-02-13 20:12:42 +01:00
#localegen=$(cat /mnt/etc/locale.gen)
2022-02-16 15:29:20 +01:00
cat <<EOF > /mnt/etc/locale.gen
2022-02-13 16:25:31 +01:00
en_US.UTF-8 UTF-8
2022-03-09 11:45:07 +01:00
de_DE.UTF-8 UTF-8
2022-02-13 16:25:31 +01:00
EOF
2022-02-13 20:12:42 +01:00
#echo "${localegen}" >>/mnt/etc/locale.gen
2022-02-13 16:25:31 +01:00
arch-chroot /mnt locale-gen
2022-02-15 18:00:02 +01:00
echo "LANG=en_US.UTF-8" >/mnt/etc/locale.conf &&
#echo "LANG=de_DE.UTF-8" >/mnt/etc/locale.conf
2022-02-15 18:00:02 +01:00
echo "KEYMAP=de-latin1" > /mnt/etc/vconsole.conf &&
2022-02-13 16:25:31 +01:00
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
2022-02-15 23:24:43 +01:00
# Set X locale and keyboard alyout.
echo "Setting locale and keyboard layout."
arch-chroot /mnt localectl --no-convert set-keymap de-latin1-nodeadkeys &&
2022-03-09 11:45:07 +01:00
cat << EOF > /mnt/etc/X11/xorg.conf.d/00-keyboard.conf &&
2022-02-15 23:24:43 +01:00
# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "de"
Option "XkbModel" "pc105"
Option "XkbVariant" "deadgraveacute"
EndSection
EOF
echo "Done."
echo
2022-02-13 16:25:31 +01:00
# Editing mkinitcpio.conf.
echo "Editing /etc/mkinitcpio.conf."
2022-02-14 00:37:10 +01:00
echo
2022-02-13 16:25:31 +01:00
sed -i '7s/.*/MODULES=(ext4)/' /mnt/etc/mkinitcpio.conf &&
sed -i '52s/.*/HOOKS=(base udev autodetect modconf block keyboard keymap encrypt lvm2 filesystems fsck shutdown)/' /mnt/etc/mkinitcpio.conf &&
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
# Creating inital ramdisk.
echo "Creating inital ramdisk for linux-zen."
arch-chroot /mnt mkinitcpio -p linux-zen &&
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
# Enable network and display manager.
echo "Enabling Networkmanager and display manager (sddm)."
arch-chroot /mnt systemctl enable NetworkManager sddm &&
echo "Done."
2022-02-15 18:00:02 +01:00
echo
2022-02-13 16:25:31 +01:00
2022-02-14 16:10:49 +01:00
# Set root password
2022-02-13 16:25:31 +01:00
echo "Setting root password:"
2022-02-14 16:10:49 +01:00
echo -en "$pwrt\n$pwrt" | arch-chroot /mnt passwd
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-14 16:10:49 +01:00
# Install bootloader.
2022-02-15 18:00:02 +01:00
echo "Installing systemd-boot."
arch-chroot /mnt bootctl install &&
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-14 16:10:49 +01:00
# Set bootloader entry.
2022-02-15 18:00:02 +01:00
echo "Setting up bootloader."
cat << EOF > /mnt/boot/loader/entries/arch.conf &&
2022-02-13 16:25:31 +01:00
title Arch Linux
linux /vmlinuz-linux-zen
#initrd /amd-ucode.img
#initrd /intel-ucode.img
initrd /initramfs-linux-zen.img
2022-02-16 15:29:20 +01:00
options cryptdevice=/dev/$main:lvm
2022-02-13 16:25:31 +01:00
options root=/dev/mapper/main-root rw
options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd
#options loglevel=3
EOF
2022-02-14 16:10:49 +01:00
# Set bootloader fallback entry.
2022-02-15 18:00:02 +01:00
cat << EOF > /mnt/boot/loader/entries/arch-fallback.conf &&
2022-02-13 16:25:31 +01:00
title Arch Linux Fallback
linux /vmlinuz-linux
initrd /initramfs-linux-fallback.img
2022-02-14 00:48:01 +01:00
options cryptdevice=/dev/$main:lvm
2022-02-13 16:25:31 +01:00
options root=/dev/mapper/main-root rw
options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd
EOF
2022-02-14 16:10:49 +01:00
# Set bootloader.
2022-02-15 18:00:02 +01:00
echo "timeout 1" >> /mnt/boot/loader/loader.conf &&
echo "default arch.conf" >> /mnt/boot/loader/loader.conf &&
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-15 18:00:02 +01:00
# Set username, password and group.
echo "Adding user."
arch-chroot /mnt useradd -m $user &&
echo -en "$pwur\n$pwur" | arch-chroot /mnt passwd $user &&
arch-chroot /mnt gpasswd -a $user wheel &&
2022-02-16 15:29:20 +01:00
sed -i '82s/.*/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers &&
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-15 18:00:02 +01:00
# Enabling sddm auto-login.
echo "Enabling auto-login."
mkdir /mnt/etc/sddm.conf.d &&
cat << EOF > /mnt/etc/sddm.conf.d/autologin.conf
[Autologin]
User=$user
Session=plasma
EOF
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-15 18:00:02 +01:00
# Unmounting and rebooting.
echo "Unmounting system."
umount /mnt/boot &&
2022-02-16 15:29:20 +01:00
umount /mnt/home &&
2022-02-15 18:00:02 +01:00
echo "Done."
echo
2022-02-13 16:25:31 +01:00
2022-02-15 18:00:02 +01:00
echo "Rebooting"
2022-02-13 16:25:31 +01:00
reboot