Add comments, wiki links, replace keymap, locale, timezone and hostname with systemd-firstboot

This commit is contained in:
2026-07-01 17:34:16 +02:00
parent 5b104376c3
commit 9076d6559b
+86 -48
View File
@@ -1,14 +1,14 @@
#!/bin/bash #!/bin/bash
# https://wizardzines.com/comics/bash-errors/bash-errors.png
set -euo pipefail set -euo pipefail
# Write log
exec >> >(tee -i /tmp/install.log) exec >> >(tee -i /tmp/install.log)
exec 2>&1 exec 2>&1
clear clear
# Friendly introduction. # Friendly introduction
echo "0. WELCOME" echo "0. WELCOME"
echo "Welcome to the Arch Linux installation script!" echo "Welcome to the Arch Linux installation script!"
echo "This script will ERASE ALL DATA on the partition you will choose next!" echo "This script will ERASE ALL DATA on the partition you will choose next!"
@@ -20,29 +20,27 @@ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
fi fi
clear clear
# Selecting disk. # Selecting disk
echo "1. PARTITIONING" echo "1. PARTITIONING"
echo "Please select a disk to partition:" echo "Please select a disk to partition:"
echo echo
# Don't separate values by space. # Don't separate values by space
IFS=$'\n' IFS=$'\n'
# Set variable containing name and size of all disks. # Set variable containing name and size of all disks
declare -a dsks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') ) declare -a dsks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') )
# Select value on array. # Select value on array
select dev in "${dsks[@]}" select dev in "${dsks[@]}"; do
do break
break
done done
echo echo
# Separate values by spaces. # Separate values by spaces
IFS=' ' IFS=' '
# Create new variable of selection. # Create new variable of selection
array=(${dev}) array=(${dev})
dev="${array[0]}" dev="${array[0]}"
@@ -115,7 +113,7 @@ echo "Please enter a username:"
read -r user read -r user
echo echo
# Setting user password. # Setting user password
echo "Also please choose a password for your user:" echo "Also please choose a password for your user:"
pwu="" pwu=""
while [[ -z "${pwu}" ]]; do while [[ -z "${pwu}" ]]; do
@@ -141,51 +139,52 @@ clear
echo "5. INSTALLING SYSTEM.." echo "5. INSTALLING SYSTEM.."
echo echo
# Starting partitioning. # Starting partitioning
echo "Partitioning /dev/${dev}.." echo "Partitioning /dev/${dev}.."
echo echo
# Clearing partition table of selected disk. # Clearing partition table of selected disk
echo "Clearing existing partitioning table." echo "Clearing existing partitioning table."
sgdisk -Z "/dev/${dev}" sgdisk -Z "/dev/${dev}"
echo echo
# Creating boot partition. # Creating boot partition
echo "Creating boot partition of 512 MB." echo "Creating boot partition of 512 MB."
sgdisk -n 1:0:+512M "/dev/${dev}" sgdisk -n 1:0:+512M "/dev/${dev}"
echo echo
# Setting type for EFI. # Setting type for EFI
echo "Setting partition type." echo "Setting partition type."
sgdisk -t 1:ef00 "/dev/${dev}" sgdisk -t 1:ef00 "/dev/${dev}"
echo echo
# Creating system partition. # Creating system partition
echo "Creating system partition." echo "Creating system partition."
sgdisk -n 2:0:0 "/dev/${dev}" sgdisk -n 2:0:0 "/dev/${dev}"
echo echo
# Print partitions. # Print partitions
echo "This is your new partition table:" echo "This is your new partition table:"
lsblk | grep "${dev}" lsblk | grep "${dev}"
echo echo
# Get new variable. # Get new variable
if [[ "${dev}" = "nvme0n1" ]]; then if [[ "${dev}" = "nvme0n1" ]]; then
main="${dev}p2" main="${dev}p2"
else else
main="${dev}2" main="${dev}2"
fi fi
# Encrypting partition. # Encrypting partition
echo "Encrypting system partition. This might take a while." echo "Encrypting system partition. This might take a while."
echo echo
# https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#Encryption_options_for_LUKS_mode # https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#Encryption_options_for_LUKS_mode
echo -en "${pwcr}\n${pwcr}" | cryptsetup -s 512 luksFormat /dev/$main echo -en "${pwcr}\n${pwcr}" | cryptsetup -s 512 luksFormat /dev/$main
echo "Partition successfully encrypted." echo "Partition successfully encrypted."
echo echo
# Opening encrypted partition and mounting at /dev/mapper/main. # Opening encrypted partition and mounting at /dev/mapper/main
echo "Decrypting.. This also might take a while." echo "Decrypting.. This also might take a while."
echo echo
echo -en "${pwcr}\n${pwcr}" | cryptsetup luksOpen "/dev/${main}" main echo -en "${pwcr}\n${pwcr}" | cryptsetup luksOpen "/dev/${main}" main
@@ -203,11 +202,12 @@ else
boot="${dev}1" boot="${dev}1"
fi fi
# Create boot filesystem
mkfs.fat -F 32 -n UEFI "/dev/${boot}" mkfs.fat -F 32 -n UEFI "/dev/${boot}"
echo "Filesystem for boot successfully created." echo "Filesystem for boot successfully created."
echo echo
# Creating btrfs partition. # Creating btrfs filesystem
mkfs.btrfs "/dev/mapper/main" mkfs.btrfs "/dev/mapper/main"
mount "/dev/mapper/main" "/mnt" mount "/dev/mapper/main" "/mnt"
@@ -230,7 +230,8 @@ echo
lsblk -a lsblk -a
echo echo
# Updating mirrors using reflector. # Updating mirrors using reflector
# https://wiki.archlinux.org/title/Installation_guide#Select_the_mirrors
echo "Updating mirrors.." echo "Updating mirrors.."
reflector --verbose --latest 10 --country Germany --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist reflector --verbose --latest 10 --country Germany --age 24 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
echo "Done." echo "Done."
@@ -244,7 +245,8 @@ if checkupdates | grep -q archlinux-keyring; then
fi fi
echo echo
# Installing base system. # Installing base system
# https://wiki.archlinux.org/title/Installation_guide#Install_essential_packages
echo "Installing basic packages.." echo "Installing basic packages.."
# Base packages # Base packages
@@ -319,42 +321,73 @@ echo "Base system installed."
echo echo
# Generating fstab # Generating fstab
# https://wiki.archlinux.org/title/Installation_guide#Fstab
echo "Generating fstab.." echo "Generating fstab.."
genfstab -Up "/mnt" > "/mnt/etc/fstab" genfstab -Up "/mnt" > "/mnt/etc/fstab"
echo "Done." echo "Done."
echo echo
# Setting timezone ##########
# Setting timezone to Europe/Berlin
echo "Setting timezone.." echo "Setting timezone.."
arch-chroot "/mnt" ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
arch-chroot "/mnt" hwclock --systohc ## Replaced by systemd-firstboot
# arch-chroot "/mnt" ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
https://wiki.archlinux.org/title/Installation_guide#Time
arch-chroot "/mnt" hwclock --systohc # Set the Hardware Clock to the current System Time
echo "Done." echo "Done."
echo echo
##########
## Replaced by systemd-firstboot
# Setting hostname # Setting hostname
echo "Setting hostname.." # echo "Setting hostname.."
echo "${host}" > "/mnt/etc/hostname" # echo "${host}" > "/mnt/etc/hostname"
echo "Done." # echo "Done."
echo # echo
##########
# Setting locale # Setting locale
# https://wiki.archlinux.org/title/Installation_guide#Localization
echo "Setting and generating locale.." echo "Setting and generating locale.."
cat << EOF > "/mnt/etc/locale.gen" cat << EOF > "/mnt/etc/locale.gen"
en_US.UTF-8 UTF-8 en_US.UTF-8 UTF-8
EOF EOF
# https://wiki.archlinux.org/title/Linux_console/Keyboard_configuration#Persistent_configuration
#echo "${localegen}" >>/mnt/etc/locale.gen
arch-chroot "/mnt" locale-gen arch-chroot "/mnt" locale-gen
echo "LANG=en_US.UTF-8" > "/mnt/etc/locale.conf"
echo "KEYMAP=de-latin1" > "/mnt/etc/vconsole.conf" ## Replaced by systemd-firstboot
# echo "LANG=en_US.UTF-8" > "/mnt/etc/locale.conf"
# echo "KEYMAP=de-latin1" > "/mnt/etc/vconsole.conf"
echo "Done." echo "Done."
echo echo
##########
# Set X locale and keyboard alyout. # Set X locale and keyboard alyout.
echo "Setting locale and keyboard layout." echo "Setting locale and keyboard layout."
## Replaced by systemd-firstboot
#arch-chroot /mnt localectl --no-convert set-keymap de-latin1-nodeadkeys #arch-chroot /mnt localectl --no-convert set-keymap de-latin1-nodeadkeys
systemd-firstboot --root=/mnt --keymap=de-latin1-nodeadkeys
##########
# https://wiki.archlinux.org/title/Systemd-firstboot
systemd-firstboot \
--root=/mnt \
--keymap=de-latin1-nodeadkeys \
--locale=en_US.UTF-8 \
--timezone=Europe/Berlin \
--hostname="${host}" # https://wiki.archlinux.org/title/Installation_guide#Network_configuration
systemctl enable systemd-firstboot
##########
## Obsolete for Wayland ## Obsolete for Wayland
# cat << EOF > "/mnt/etc/X11/xorg.conf.d/00-keyboard.conf" # cat << EOF > "/mnt/etc/X11/xorg.conf.d/00-keyboard.conf"
@@ -372,34 +405,39 @@ systemd-firstboot --root=/mnt --keymap=de-latin1-nodeadkeys
# echo "Done." # echo "Done."
# echo # echo
# Editing mkinitcpio.conf. ##########
# Editing mkinitcpio.conf
echo "Editing /etc/mkinitcpio.conf.." echo "Editing /etc/mkinitcpio.conf.."
sed -i '55s/.*/HOOKS=(base udev autodetect microcode modconf kms block keyboard keymap encrypt filesystems fsck shutdown)/' /mnt/etc/mkinitcpio.conf sed -i '55s/.*/HOOKS=(base udev autodetect microcode modconf kms block keyboard keymap encrypt filesystems fsck shutdown)/' /mnt/etc/mkinitcpio.conf
echo "Done." echo "Done."
echo echo
# Editing taskbar. # Editing taskbar
#sed -i '65s/.*/launchers=applications:systemsettings.desktop,applications:org.kde.konsole.desktop,applications:firefox.desktop/' /mnt/home/${user}/.config/plasma-org.kde.plasma.desktop-appletsrc #sed -i '65s/.*/launchers=applications:systemsettings.desktop,applications:org.kde.konsole.desktop,applications:firefox.desktop/' /mnt/home/${user}/.config/plasma-org.kde.plasma.desktop-appletsrc
# Creating inital ramdisk. # Creating inital ramdisk
# https://wiki.archlinux.org/title/Installation_guide#Initramfs
echo "Creating inital ramdisk for linux-zen.." echo "Creating inital ramdisk for linux-zen.."
arch-chroot /mnt mkinitcpio -p linux-zen arch-chroot /mnt mkinitcpio -p linux-zen
echo "Done." echo "Done."
echo echo
# Enable network and display manager. # Enable network and display manager
echo "Enabling NetworkManager and Plasma Login Manager.." echo "Enabling NetworkManager and Plasma Login Manager.."
arch-chroot "/mnt" systemctl enable NetworkManager plasmalogin arch-chroot "/mnt" systemctl enable NetworkManager plasmalogin
echo "Done." echo "Done."
echo echo
# Set root password # Set root password
# https://wiki.archlinux.org/title/Installation_guide#Root_password
echo "Setting root password.." echo "Setting root password.."
echo -en "${pwrt}\n${pwrt}" | arch-chroot "/mnt" passwd echo -en "${pwrt}\n${pwrt}" | arch-chroot "/mnt" passwd
echo "Done." echo "Done."
echo echo
# Install bootloader. # Install bootloader
# https://wiki.archlinux.org/title/Installation_guide#Boot_loader
echo "Installing systemd-boot.." echo "Installing systemd-boot.."
arch-chroot "/mnt" bootctl --path=/boot install arch-chroot "/mnt" bootctl --path=/boot install
echo "Done." echo "Done."
@@ -408,7 +446,7 @@ echo
# Get UUID for primary partition # Get UUID for primary partition
uuid=$(ls -l /dev/disk/by-uuid | grep "${main}" | awk '{print $9}') uuid=$(ls -l /dev/disk/by-uuid | grep "${main}" | awk '{print $9}')
# Set bootloader entry. # Set bootloader entry
echo "Setting up bootloader.." echo "Setting up bootloader.."
cat << EOF > "/mnt/boot/loader/entries/arch.conf" cat << EOF > "/mnt/boot/loader/entries/arch.conf"
title Arch Linux title Arch Linux
@@ -423,7 +461,7 @@ options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd options init=/usr/lib/systemd/systemd
EOF EOF
# Set bootloader fallback entry. # Set bootloader fallback entry
cat << EOF > "/mnt/boot/loader/entries/arch-fallback.conf" cat << EOF > "/mnt/boot/loader/entries/arch-fallback.conf"
title Arch Linux Fallback title Arch Linux Fallback
linux /vmlinuz-linux linux /vmlinuz-linux
@@ -435,13 +473,13 @@ options lang=de locale=de_DE.UTF-8
options init=/usr/lib/systemd/systemd options init=/usr/lib/systemd/systemd
EOF EOF
# Set bootloader. # Set bootloader
echo "timeout 1" >> "/mnt/boot/loader/loader.conf" echo "timeout 1" >> "/mnt/boot/loader/loader.conf"
echo "default arch.conf" >> "/mnt/boot/loader/loader.conf" echo "default arch.conf" >> "/mnt/boot/loader/loader.conf"
echo "Done." echo "Done."
echo echo
# Set username, password and group. # Set username, password and group
echo "Adding user.." echo "Adding user.."
arch-chroot /mnt useradd -m "${user}" arch-chroot /mnt useradd -m "${user}"
echo -en "${pwur}\n${pwur}" | arch-chroot /mnt passwd "${user}" echo -en "${pwur}\n${pwur}" | arch-chroot /mnt passwd "${user}"
@@ -450,7 +488,7 @@ sed -i '82s/.*/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers
echo "Done." echo "Done."
echo echo
# Enabling plasma login manager auto login. # Enabling plasma login manager auto login
echo "Enabling auto login.." echo "Enabling auto login.."
cat << EOF > /mnt/etc/plasmalogin.conf cat << EOF > /mnt/etc/plasmalogin.conf
[Autologin] [Autologin]
@@ -460,7 +498,7 @@ EOF
echo "Done." echo "Done."
echo echo
# Unmounting and rebooting. # Unmounting and rebooting
echo "Unmounting system.." echo "Unmounting system.."
umount "/mnt/boot" umount "/mnt/boot"
umount "/mnt" umount "/mnt"