From 54861b025565f527a35ee0628365bf62769577d0 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 22 Mar 2020 14:10:42 +0100 Subject: First complete Version of Rewrite --- stages/second_stage.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 8 deletions(-) (limited to 'stages/second_stage.sh') diff --git a/stages/second_stage.sh b/stages/second_stage.sh index 5800828..abf407a 100644 --- a/stages/second_stage.sh +++ b/stages/second_stage.sh @@ -23,47 +23,98 @@ set -e -# debug output - -print_ok "Entering second_stage.sh" - - # set timezone +print_ok "Setting timezone ..." ln -sf $path_to_timezone /etc/localtime hwclock --systohc +print_ok "Timezone set" # localization +print_ok "Generating locales ..." echo "$locales_to_generate" >> /etc/locale.gen locale-gen touch /etc/locale.conf echo "LANG=$language" >> /etc/locale.conf touch /etc/vconsole.conf echo "KEYMAP=$keymap" >> /etc/vconsole.conf +print_ok "Locales generated" # network configuration +print_ok "Setting /etc/hostname and /etc/hosts file ..." touch /etc/hostname echo "$hostname" > /etc/hostname touch /etc/hosts echo "127.0.0.1 localhost" >> /etc/hosts echo "::1 localhost" >> /etc/hosts +print_ok "/etc/hostname and /etc/hosts configured" # initramfs -### to be implemented +if [ "$luks_encryption" == "yes" ];then + + print_ok "Re-generating initramfs ..." + + old_hooks_config_line=$(cat /etc/mkinitcpio.conf | grep "^HOOKS=") + print_ok "Old 'HOOKS' line in /etc/mkinitcpio : $old_hooks_config_line" + new_hooks_config_line="HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)" + print_ok "New 'HOOKS' line in /etc/mkinitcpio : $new_hooks_config_line" + + sed -i "s|$old_hooks_config_line|$new_hooks_config_line|" /etc/mkinitcpio.conf + mkinitcpio -P + + print_ok "Initramfs re-generated" + +fi # setting root password +print_ok "Setting default password for user 'root' ..." echo "root:${DEFAULT_PASSWORD}" | chpasswd +print_ok "Default password for user 'root' set" + + +# install and configure bootloader + +print_ok "Installing grub bootloader ..." +if [ "$boot_mode" == "uefi" ]; then + grub-install --target=x86_64-efi --efi-directory=/mnt --bootloader-id=GRUB \ + --removable +else + grub-install --target=i386-pc $path_to_disk +fi +print_ok "Grub bootloader installed" + +if [ $luks_encryption == "yes" ];then + + print_ok "Setup of /etc/default/grub for LUKS encryption ..." + + if [ "$boot_mode" == "uefi" ]; then + crypto_partition=${path_to_disk}3 + else + crypto_partition=${path_to_disk}2 + fi + + cryptdevice_uuid=$(lsblk --fs | grep "$(basename $crypto_partition)" | awk '{print $3}') + print_ok "cryptdevice_uuid: $cryptdevice_uuid" + old_kernel_param_line=$(cat /etc/default/grub | grep "GRUB_CMDLINE_LINUX_DEFAULT") + print_ok "old_kernel_param_line: $old_kernel_param_line" + new_kernal_param_line="GRUB_CMDLINE_LINUX_DEFAULT=\"loglevel=3 quiet cryptdevice=UUID=${cryptdevice_uuid}:main root=/dev/mapper/main\"" + print_ok "new_kernel_param_line: $new_kernal_param_line" + print_ok "Adding kernel parameters to /etc/default/grub ..." + sed -i "s|$old_kernel_param_line|$new_kernal_param_line|" /etc/default/grub + print_ok "Kernel parameters added to /etc/default/grub" + print_ok "Setup of /etc/default/grub for LUKS encryption done" -# install bootloader +fi -grub-install --target=i386-pc $path_to_disk +print_ok "Generating /boot/grub/grub.cfg from /etc/default/grub ..." grub-mkconfig -o /boot/grub/grub.cfg +print_ok "/boot/grub/grub.cfg generated" -- cgit v1.2.3-70-g09d2