archinstall/install.uefi

463 lines
16 KiB
Text
Raw Normal View History

#!/bin/bash
####################
# Einfache Version #
####################
#--------------------------#
#################
# Einstellungen #
#################
# Microcode für den Prozessor: amd-ucode|intel-ucode
MICROCODE="amd-ucode"
# Kernel: linux|linux-lts|linux-zen
KERNEL="linux"
# Rechnername: arch
HOSTNAME_NEW="arch"
# Passwort für den System-Benutzer (root): testen
ROOTPASSWORD="testen"
# Name des Benutzers: eichehome
USERNAME="eichehome"
# Passwort für den Benutzer: testen
USERPASSWORD="testen"
# Grafikkarte: amd|intel|nvidia
GRAPHICS_CARD="amd"
# Zeitzone: Europe/Berlin
TIMEZONE="Europe/Berlin"
# language: de_DE.UTF-8
LANG="de_DE.UTF-8"
# Pakete:
# GNOME Programme
GNOME=(xdg-user-dirs gdm gnome-backgrounds gnome-color-manager gnome-console gnome-control-center gnome-disk-utility gnome-keyring gnome-menus gnome-remote-desktop gnome-session gnome-settings-daemon gnome-shell gnome-system-monitor gnome-tour gnome-user-docs gnome-user-share grilo-plugins gvfs gvfs-afc gvfs-goa gvfs-google gvfs-gphoto2 gvfs-mtp gvfs-nfs gvfs-smb malcontent nautilus orca rygel sushi xdg-desktop-portal-gnome xdg-user-dirs-gtk yelp seahorse power-profiles-daemon)
# Ander grafische Programme
GRAPHIC_PROGRAMMS=()
# Cli-Anwendungen
CLI=(opendoas git vim lynx openssh bash-completion man-db man-pages reflector efibootmgr mtools dosfstools htop) # texinfo pacman-contrib rsync rebuild-detector
# Schriftarten
FONTS=()
# Codecs
CODECS=()
# Bluetooth
BLUETOOTH=(bluez bluez-utils)
# Office
OFFICE=(libreoffice-fresh-de)
# Audio/Video
AUDIO_VIDEO=(pipewire pipewire-audio pipewire-alsa pipewire-pulse pipewire-jack pipewire-zeroconf pipewire-v4l2 pipewire-docs pipewire-roc helvum wireplumber gstreamer gst-plugin-pipewire gst-libav gst-plugins-good gst-plugins-base)
# Drucken
PRINT=(cups)
# Development
DEV=(base-devel "${KERNEL}-headers")
# Netzwerk
WIFI_BACKEND=(wpa_supplicant) # iwd
NET=(iptables-nft firewalld inetutils avahi networkmanager networkmanager-openconnect networkmanager-openvpn networkmanager-pptp networkmanager-vpnc "${WIFI_BACKEND[@]}" modemmanager) # bind(dig,host,nslookup)
# Sontiges
BASE=(base) # -sudo
INITRD=(mkinitcpio) # dracut
OTHER=("${BASE[@]}" linux-firmware plymouth "${INITRD[@]}" xdg-utils)
# Grafik
GRAPHIC_DRIVER=()
if [[ "${GRAPHICS_CARD}" == "amd" ]]; then
GRAPHIC_DRIVER+=(xf86-video-amdgpu)
elif [[ "${GRAPHICS_CARD}" == "nvidia" ]]; then
GRAPHIC_DRIVER+=(nvidia nvidia-utils nvidia-settings)
fi
# dialog
# Drive: /dev/vda
DRIVE="/dev/vda"
# disklayout: ESP (512MiB), usr (15GiB), Root (100% - [512MiB + 15GiB])
ESP="512M"
USR="10G"
ROOT_LABEL="root"
USR_LABEL="usr"
ESP_LABEL="EFI"
#--------------------------#
###############################
# Erstellen der Partitionen #
# und mounten der Partitionen #
###############################
#Discoverable Partitions Specification
# /boot /dev/vda1
# /usr /dev/vda2
# (usr-hash) /dev/vda3
# /(root) /dev/vda4
#LSBLK_OPTIONEN="NAME,PARTUUID,UUID,PARTTYPE,PARTN,LABEL,MOUNTPOINTS"
# Prüfen ob die Platte existiert
#declare -i CHECK_EXISTENCE_OUTPUT=""
CHECK_EXISTENCE_OUTPUT=$(lsblk -o NAME | grep -c "^${DRIVE//\/dev\/}")
if [[ ${CHECK_EXISTENCE_OUTPUT} -lt 1 ]]; then
echo "Platte existiert nicht, breche ab."
exit 0
fi
RECREATE_PARTITIONS="1"
# Prüfe ob die Platte schon formatiert wurde und die Partitionen da sind
CHECK_PARTITIONS_OUTPUT=$(lsblk -o NAME,PARTTYPE | grep "${DRIVE//\/dev\/}" | grep "\(c12a7328-f81f-11d2-ba4b-00a0c93ec93b\|8484680c-9521-48c6-9c11-b0720656f69e\|77ff5f63-e7b6-4633-acf4-1565b864c0e6\|4f68bce3-e8cd-4db1-96e7-fbcaf984b709\)")
CHECK_ROOT=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "4f68bce3-e8cd-4db1-96e7-fbcaf984b709")
CHECK_ESP=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "c12a7328-f81f-11d2-ba4b-00a0c93ec93b")
CHECK_USR=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "8484680c-9521-48c6-9c11-b0720656f69e")
CHECK_USRHASH=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "77ff5f63-e7b6-4633-acf4-1565b864c0e6")
if [[ ${CHECK_ESP} -eq 1 && ${CHECK_USR} -eq 1 && ${CHECK_USRHASH} -eq 1 && ${CHECK_ROOT} -eq 1 ]]; then
read -r -p "Alle Partitionen sind vorhanden. Trotzdem neu erstellen? (j/N): " confirm
if [[ "${confirm}" == [jJ] ]];then
echo "Partitionen werden neu erstellt"
RECREATE_PARTITIONS="1"
else
echo "Partitionen werden nicht neu erstellt"
RECREATE_PARTITIONS="0"
fi
fi
if [[ ${RECREATE_PARTITIONS} -eq 1 ]]; then
# Reset Partition Table
sgdisk -og "${DRIVE}"
# EFI System Partition erstellen
sgdisk -n 0:0:+"${ESP}" -t 0:c12a7328-f81f-11d2-ba4b-00a0c93ec93b -c 0:"EFI System Partition" "${DRIVE}"
#sgdisk -n 0:0:+512M -t 0:ef00 -c 0:ESP "${DRIVE}"
# usr-Partition erstellen
sgdisk -n 0:0:+"${USR}" -t 0:8484680c-9521-48c6-9c11-b0720656f69e -c 0:"ArchOS_0.1" "${DRIVE}"
# usrhash-Partition erstellen
sgdisk -n 0:0:+512M -t 0:77ff5f63-e7b6-4633-acf4-1565b864c0e6 -c 0:"ArchOS_0.1" "${DRIVE}"
# Root-Partition erstellen
sgdisk -n 0:0:0 -t 0:4f68bce3-e8cd-4db1-96e7-fbcaf984b709 -c 0:"ArchOS Root" "${DRIVE}"
fi
# # UUIDs finden
# UUID_ESP=""
# UUID_ROOT=""
# UUID_USR=""
# UUID_USRHASH=""
# # Anzahl der Partitionen ermitteln
# DRIVE_NAME=${DRIVE//\/dev\/}
# declare -i NUMBER_OF_PARTITIONS;
# NUMBER_OF_PARTITIONS=$(lsblk | grep -c "${DRIVE_NAME}[0-9]")
# declare -i UNKNOWN_PARTITIONS
# NOCASEMATCH_UNSET=$(shopt -u | grep -c nocasematch)
# if [[ $NOCASEMATCH_UNSET ]]; then
# shopt -s nocasematch
# fi
# for (( i=NUMBER_OF_PARTITIONS; i > 0 ; i=i-1 )) ; do
# OUTPUT=$(sgdisk -i "${i}" "${DRIVE}")
# PARTITION_EXISTS=$(echo "${OUTPUT}" | grep -c "GUID")
# if [[ "${PARTITION_EXISTS}" != "0" ]]; then
# GUID_CODE=$(echo "${OUTPUT}" | grep "GUID code:" | cut -d ' ' -f 4)
# UUID=$(echo "${OUTPUT}" | grep "unique GUID:" | cut -d ' ' -f 4)
# case $GUID_CODE in
# "8484680c-9521-48c6-9c11-b0720656f69e" )
# echo "USR-Partition, UUID: ${UUID}"
# UUID_USR=${UUID}
# ;;
# "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" )
# echo "ESP-Partition, UUID: ${UUID}"
# UUID_ESP=${UUID}
# ;;
# "4f68bce3-e8cd-4db1-96e7-fbcaf984b709" )
# echo "Root-Partition, UUID: ${UUID}"
# UUID_ROOT=${UUID}
# ;;
# "77ff5f63-e7b6-4633-acf4-1565b864c0e6" )
# echo "Usrhash-Partition, UUID: ${UUID}"
# UUID_USRHASH=${UUID}
# ;;
# * )
# echo "Unbekannte Partition"
# UNKNOWN_PARTITIONS="${UNKNOWN_PARTITIONS}+1"
# ;;
# esac
# else
# echo "no partition found"
# fi
# NUMBER_OF_PARTITIONS="${NUMBER_OF_PARTITIONS}-1"
# done
# if [[ $NOCASEMATCH_UNSET ]]; then
# shopt -u nocasematch
# fi
# if [[ "${UNKNOWN_PARTITIONS}" -gt "0" ]]; then
# if [[ "${UNKNOWN_PARTITIONS}" -gt "1" ]]; then
# read -r -p "Mehrere Partitionen unbekannt. Trotzdem fortfahren? (j/N): " confirm
# [[ "${confirm}" == [jJ] ]] || echo "Abbrechen" && exit 0
# else
# read -r -p "Eine Partition unbekannt. Trotzdem fortfahren? (j/N): " confirm
# [[ "${confirm}" == [jJ] ]] || echo "Abbrechen" && exit 0
# fi
# fi
# # Großbuchstaben in UUIDs zu kleinbuchstaben umwandeln
# UUID_ESP="${UUID_ESP@L}"
# UUID_ROOT="${UUID_ROOT@L}"
# UUID_USR="${UUID_USR@L}"
# UUID_USRHASH="${UUID_USRHASH@L}"
# Informationen aus den Partitionen auslesen
PARTITIONEN_OUTPUT=$(lsblk -o NAME,PARTTYPE,PARTUUID,UUID,PARTN,LABEL,MOUNTPOINTS | grep "${DRIVE//\/dev\/}[0-9]" | sed 's/[[:blank:]]\+/ /g')
echo "PARTITIONEN_OUTPUT:"
echo "${PARTITIONEN_OUTPUT}"
PARTITION_NUMBERS=$(echo "${PARTITIONEN_OUTPUT}" | cut -d ' ' -f 5)
echo "Partition-Numbers:"
echo "${PARTITION_NUMBERS}"
declare -A ROOT_PARTITION=()
declare -A ESP_PARTITION=()
declare -A USR_PARTITION=()
declare -A USRHASH_PARTITION=()
for i in ${PARTITION_NUMBERS}; do
PARTN=$(echo "${PARTITIONEN_OUTPUT}" | grep "${DRIVE//\/dev\/}${i}" | cut -d ' ' -f 5)
PARTUUID=$(echo "${PARTITIONEN_OUTPUT}" | grep "${DRIVE//\/dev\/}${i}" | cut -d ' ' -f 3)
PARTTYPE=$(echo "${PARTITIONEN_OUTPUT}" | grep "${DRIVE//\/dev\/}${i}" | cut -d ' ' -f 2)
case $PARTTYPE in
"c12a7328-f81f-11d2-ba4b-00a0c93ec93b" )
echo "ESP"
ESP_PARTITION+=([PARTUUID]="${PARTUUID}")
ESP_PARTITION+=([PARTTYPE]="${PARTTYPE}")
ESP_PARTITION+=([PARTNUMBER]="${PARTN}")
;;
"8484680c-9521-48c6-9c11-b0720656f69e" )
echo "USR"
USR_PARTITION+=([PARTUUID]="${PARTUUID}")
USR_PARTITION+=([PARTTYPE]="${PARTTYPE}")
USR_PARTITION+=([PARTNUMBER]="${PARTN}")
;;
"77ff5f63-e7b6-4633-acf4-1565b864c0e6")
echo "USRHASH"
USRHASH_PARTITION+=([PARTUUID]="${PARTUUID}")
USRHASH_PARTITION+=([PARTTYPE]="${PARTTYPE}")
USRHASH_PARTITION+=([PARTNUMBER]="${PARTN}")
;;
"4f68bce3-e8cd-4db1-96e7-fbcaf984b709" )
echo "ROOT"
ROOT_PARTITION+=([PARTUUID]="${PARTUUID}")
ROOT_PARTITION+=([PARTTYPE]="${PARTTYPE}")
ROOT_PARTITION+=([PARTNUMBER]="${PARTN}")
;;
* )
echo "Unknown"
;;
esac
done
# Prüfen,ob die Dateisysteme schon korrekt sind
FILESYSTEM_OUTPUT=$(lsblk -o NAME,FSTYPE,FSVER,PARTUUIDi,LABEL | grep "${DRIVE//\/dev\/}[0-9]")
CHECK_FS_ESP=$(echo "${FILESYSTEM_OUTPUT}" | grep "${ESP_PARTITION["PARTUUID"]}" | grep -i "vfat" | grep -i "fat32" | grep -c -i "${ESP_LABEL}")
CHECK_FS_USR=$(echo "${FILESYSTEM_OUTPUT}" | grep "${USR_PARTITION["PARTUUID"]}" | grep -i "ext4" | grep -c -i "${USR_LABEL}")
CHECK_FS_USRHASH=$(echo "${FILESYSTEM_OUTPUT}" | grep "${USRHASH_PARTITION["PARTUUID"]}" | grep -c -i "dm_verity_hash")
CHECK_FS_ROOT=$(echo "${FILESYSTEM_OUTPUT}" | grep "${ROOT_PARTITION["PARTUUID"]}" | grep -i "ext4" | grep -c -i "${ROOT_LABEL}")
RECREATE_FILESYSTEMS="0"
if [[ ${CHECK_FS_ESP} -eq 1 && ${CHECK_FS_USR} -eq 1 && ${CHECK_FS_USRHASH} -eq 1 && ${CHECK_FS_ROOT} -eq 1 ]]; then
echo "Alles vorhanden"
read -r -p "Alle Dateisysteme vorhanden. Trotzdem neu erstellen? (j/N): " confirm
if [[ ${confirm} == [jJ] ]]; then
echo "Dateisysteme werden neuerstellt."
RECREATE_FILESYSTEMS="1"
else
echo "Dateisysteme werden nicht neu erstellt."
RECREATE_FILESYSTEMS="0"
fi
fi
if [[ (${CHECK_ESP} -eq 0 || ${RECREATE_FILESYSTEMS} -eq 1) && -n ${ESP_PARTITION["PARTUUID"]} ]]; then
echo "Erstelle ESP"
mkfs.vfat -n "${ESP_LABEL}" -F 32 "/dev/disk/by-partuuid/${ESP_PARTITION["PARTUUID"]}"
fi
if [[ (${CHECK_USR} -eq 0 || ${RECREATE_FILESYSTEMS} -eq 1) && -n ${USR_PARTITION["PARTUUID"]} ]]; then
echo "Erstelle USR"
mkfs.ext4 -L "${USR_LABEL}" "/dev/disk/by-partuuid/${USR_PARTITION["PARTUUID"]}"
fi
if [[ (${CHECK_ROOT} -eq 0 || ${RECREATE_FILESYSTEMS} -eq 1) && -n ${ROOT_PARTITION["PARTUUID"]} ]]; then
echo "Erstelle ROOT"
mkfs.ext4 -L "${ROOT_LABEL}" "/dev/disk/by-partuuid/${ROOT_PARTITION["PARTUUID"]}"
fi
mount /dev/disk/by-label/root /mnt
mkdir -p /mnt/{boot,usr}
mount /dev/disk/by-label/EFI /mnt/boot
mount /dev/disk/by-label/usr /mnt/usr
#--------------------------#
#######################
# Pakete installieren #
#######################
# Pacman im Live-System konfigurieren
sed -i 's/#\(Color\)/\1/' /etc/pacman.conf
# Umbruch notwendug
sed -i 's/#\(ParallelDownloads\s=\s5\)/\1\
ILoveCandy/' /etc/pacman.conf
pacstrap -i /mnt "${KERNEL}" "${MICROCODE}" "${GNOME[@]}" "${GRAPHIC_PROGRAMMS[@]}" "${CLI[@]}" "${FONTS[@]}" "${CODECS[@]}" "${BLUETOOTH[@]}" "${OFFICE[@]}" "${AUDIO_VIDEO[@]}" "${PRINT[@]}" "${DEV[@]}" "${NET[@]}" "${OTHER[@]}" "${GRAPHIC_DRIVER[@]}"
#--------------------------#
#################################
# Das neue System konfigurieren #
#################################
# ln -sf "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime -> L /etc/localtime - - - - "/usr/share/zoneinfo/${TIMEZONE}"
arch-chroot /mnt hwclock --systohc
arch-chroot /mnt rm -rf /etc/localtime
arch-chroot /mnt ln -sf "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime
sed -i 's/#\(Color\)/\1/' /mnt/etc/pacman.conf
# Umbruch notwendug
sed -i 's/#\(ParallelDownloads\s=\s5\)/\1\
ILoveCandy/' /mnt/etc/pacman.conf
sed -i "s/#\(${LANG}\)/\1/" /mnt/etc/locale.gen
arch-chroot /mnt locale-gen
echo "LANG=${LANG}" > /mnt/etc/locale.conf
echo "KEYMAP=${KEYMAP}" > /mnt/etc/vconsole.conf
echo "${HOSTNAME_NEW}" > /mnt/etc/hostname
cat > /mnt/etc/hosts << EOF
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
#echo "127.0.0.1 localhost" > /etc/hosts
#echo "::1 localhost" >> /etc/hosts
#echo "127.0.1.1 ${HOSTNAME_NEW}.localedomain ${HOSTNAME_NEW}" >> /etc/hosts
arch-chroot /mnt chpasswd <<< "root:${ROOTPASSWORD}"
#echo root:"${ROOTPASSWORD}" | chpasswd
arch-chroot /mnt useradd -mG wheel "${USERNAME}"
arch-chroot /mnt chpasswd <<< "${USERNAME}:${USERPASSWORD}"
#echo "${USERNAME}:${USERPASSWORD}" | chpasswd
#cat > /etc/NetworkManager/conf.d/wifi_backend.conf << EOF
#[device]
#wifi.backend=iwd
#EOF
sed -i 's/#\(CHARACTER_SET:\).*/\1utf-8/' /mnt/etc/lynx.cfg
2023-07-16 22:43:39 +00:00
sleep 2
# Tastatur layout auf Deutsch stellen
arch-chroot /mnt gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'de')]"
cat > /mnt/etc/xdg/reflector/reflector.conf << EOF
--save /etc/pacman.d/mirrorlist
--country Germany
--protocol https
--latest 5
EOF
cat > /mnt/etc/doas.conf << EOF
permit :wheel
permit persist eichehome as root
EOF
#echo "permit :wheel" > /etc/doas.conf
#echo "permit persist eichehome as root" >> /etc/doas.conf
#echo "" >> /etc/doas.conf
2023-07-16 22:43:39 +00:00
arch-chroot /mnt doas -C /etc/doas.conf && echo "config ok" || echo "config error"
sleep 2
mkdir -p /mnt/etc/systemd/resolved.conf.d
cat > /mnt/etc/systemd/resolved.conf.d/disable-multicastDNS.conf << EOF
[Resolve]
MulticastDNS=no
EOF
2023-07-16 22:43:39 +00:00
sleep 2
arch-chroot /mnt systemctl enable systemd-resolved
arch-chroot /mnt systemctl enable systemd-timesyncd
arch-chroot /mnt systemctl enable NetworkManager
arch-chroot /mnt systemctl enable reflector.timer
arch-chroot /mnt systemctl enable firewalld
arch-chroot /mnt systemctl enable fstrim.timer
arch-chroot /mnt systemctl enable gdm
arch-chroot /mnt systemctl enable avahi-daemon
arch-chroot /mnt systemctl enable bluetooth
#--------------------------#
########################################
# Initramfs konfigurieren und erzeugen #
########################################
if [[ "${GRAPHICS_CARD}" == "amd" ]]; then
sed -i 's/MODULES=()/MODULES=(amdgpu)/' /mnt/etc/mkinitcpio.conf #AMD
elif [[ "${GRAPHICS_CARD}" == "intel" ]]; then
sed -i 's/MODULES=()/MODULES=(i915)/' /mnt/etc/mkinitcpio.conf #Intel
elif [[ "${GRAPHICS_CARD}" == "nvidia" ]]; then
sed -i 's/MODULES=()/MODULES=(nvidia)/' /mnt/etc/mkinitcpio.conf #Nvidia
fi
sed -i 's/^HOOKS=(.*)/HOOKS=(base systemd keyboard plymouth autodetect sd-vconsole modconf kms block filesystems fsck)/' /mnt/etc/mkinitcpio.conf
arch-chroot /mnt mkinitcpio -p "${KERNEL}"
#--------------------------#
#############################################
# Bootloader installieren und konfigurieren #
#############################################
arch-chroot /mnt bootctl install
cat > /mnt/boot/loader/loader.conf << EOF
timeout 5
console-mode max
editor yes
default *
EOF
cat > /mnt/boot/loader/entries/arch.conf << EOF
title Arch Linux
version 0.1
linux /vmlinuz-${KERNEL}
initrd /${MICROCODE}.img
initrd /initramfs-${KERNEL}.img
options quiet splash rw
EOF
2023-07-23 18:19:49 +00:00
#--------------------------#
###############
# Veritysetup #
###############
echo "veritysetup"
OUTPUT_VERITYSETUP=$(veritysetup format /dev/vda2 /dev/vda3)
ROOT_HASH=$(echo "${OUTPUT_VERITYSETUP}" | grep "Root hash" | sed 's/[[:blank:]]\+/ /g' | cut -d ' ' -f 3)
ROOTHASH_TEIL="${ROOT_HASH:0:32}"
lsblk
#sgdisk -u (partnum /USR):(64 char roothash)(UUID_USRHASH)
#--------------------------#
##################
# Temporäre fixe #
##################
genfstab -U /mnt | grep "usr" > /mnt/etc/fstab
umount -R /mnt
2023-07-16 22:28:45 +00:00
exit 0