From 885f8119b4bc45805522c51428243e7928d13093 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 3 Jul 2022 02:31:59 +0700 Subject: all: replace grub with systemd-boot Now that we use UEFI based partition, we can replace the grub with systemd-boot. This option have several advantages, - minimize installed package and dependencies - allow future customization (e.g. automounting, secure boot) The pacman hook 00-systemd-boot is required to re-install the systemd boot loader automatically when package systemd updated. --- README.md | 2 +- build-arch-gce | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1319dd4..1cd3923 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ installation, while still allowing it to be fully functional and optimized for Compute Engine. Notable choices made and differences compared to a standard Arch Linux installation are the following: -- GRUB is used with a UEFI-based boot and a GPT partition table. +- systemd-boot is used with UEFI-based boot and a GPT partition table. - Serial console logging is enabled from kernel command line and journald is configured to forward to it. - Block multiqueue is configured from the kernel command line to optimize diff --git a/build-arch-gce b/build-arch-gce index d92bdcf..8881ed7 100755 --- a/build-arch-gce +++ b/build-arch-gce @@ -59,8 +59,8 @@ mkdir -- "$mount_dir" mount -- "$root_dev" "$mount_dir" echo '- Mounting the EFI partition.' -mkdir -- "$mount_dir/efi" -mount -- "$efi_dev" "$mount_dir/efi" +mkdir -p -- "$mount_dir/boot" +mount -- "$efi_dev" "$mount_dir/boot" echo '- Installing Arch Linux.' append_gce_repo() { @@ -76,7 +76,7 @@ append_gce_repo() { cp /etc/pacman.conf "$work_dir" append_gce_repo "$work_dir/pacman.conf" pacstrap -G -M -C "$work_dir/pacman.conf" -- "$mount_dir" \ - base linux grub dosfstools e2fsprogs dhclient openssh sudo google-compute-engine + base linux dosfstools e2fsprogs dhclient openssh sudo google-compute-engine append_gce_repo "$mount_dir/etc/pacman.conf" echo '- Configuring fstab.' @@ -91,7 +91,7 @@ print_fstab() { } >> "$mount_dir/etc/fstab" { print_fstab root "$root_uuid" / ext4 rw,discard,errors=remount-ro,x-systemd.growfs 0 1 - print_fstab efi "$efi_uuid" /efi vfat uid=root,gid=root,umask=022,showexec 0 0 + print_fstab efi "$efi_uuid" /boot vfat uid=root,gid=root,umask=022,showexec 0 0 } echo '- Running additional setup in chroot.' @@ -148,12 +148,12 @@ arch-chroot -- "$mount_dir" /bin/bash -s <<-'EOS' systemctl --quiet enable pacman-init.service echo '-- Configuring systemd-repart.' - mkdir /etc/repart.d + mkdir -p /etc/repart.d cat <<-'EOF' > /etc/repart.d/root.conf [Partition] Type=root EOF - mkdir /etc/systemd/system/systemd-repart.service.d + mkdir -p /etc/systemd/system/systemd-repart.service.d cat <<-'EOF' > /etc/systemd/system/systemd-repart.service.d/override.conf [Unit] Before=systemd-growfs@-.service @@ -175,16 +175,32 @@ arch-chroot -- "$mount_dir" /bin/bash -s <<-'EOS' rm /boot/initramfs-linux-fallback.img mkinitcpio --nocolor --preset linux - echo '-- Configuring grub.' - grub-install --target=x86_64-efi --efi-directory=/efi --no-nvram --removable - cat <<-'EOF' > /etc/default/grub - # GRUB boot loader configuration - GRUB_CMDLINE_LINUX="console=ttyS0,38400n8 net.ifnames=0 scsi_mod.use_blk_mq=Y" - GRUB_PRELOAD_MODULES="part_gpt" - GRUB_TIMEOUT=0 - GRUB_DISABLE_RECOVERY=true + echo '-- Running boot loader.' + bootctl install --no-variables --quiet + + echo '-- Configuring boot loader.' + cat <<-'EOF' > /boot/loader/loader.conf + default arch.conf + editor no + EOF + cat <<-'EOF' > /boot/loader/entries/arch.conf + title Arch Linux + linux /vmlinuz-linux + initrd /initramfs-linux.img + options rw console=ttyS0,38400n8 net.ifnames=0 scsi_mod.use_blk_mq=Y + EOF + mkdir -p -- "/etc/pacman.d/hooks" + cat <<-'EOF' > /etc/pacman.d/hooks/00-systemd-boot.hook + [Trigger] + Type = Package + Operation = Upgrade + Target = systemd + + [Action] + Description = Gracefully upgrading systemd-boot... + When = PostTransaction + Exec = /usr/bin/systemctl restart systemd-boot-update.service EOF - grub-mkconfig -o /boot/grub/grub.cfg EOS echo '- Cleaning up and finalizing the image.' -- cgit v1.3