grub: remember selected menu entry

This commit is contained in:
Daniel Langbein 2021-05-03 16:12:27 +02:00
parent 66b26a20d2
commit c6ea86a21e
9 changed files with 103 additions and 18 deletions

15
pkg/de-p1st-grub/.install Normal file
View File

@ -0,0 +1,15 @@
## arg 1: the new package version
post_install() {
holo apply
}
## arg 1: the new package version
## arg 2: the old package version
post_upgrade() {
holo apply
}
## arg 1: the old package version
post_remove() {
holo apply
}

View File

@ -2,14 +2,14 @@
_pkgname=grub
_reponame=arch
pkgname="de-p1st-$_pkgname"
pkgver=0.0.2
pkgrel=2
pkgver=0.0.3
pkgrel=1
pkgdesc="grub with configuration"
arch=('any')
url="https://codeberg.org/privacy1st/${_reponame}"
license=('MIT')
groups=()
depends=('grub')
depends=('grub' 'holo')
makedepends=('git')
optdepends=()
provides=()
@ -17,7 +17,7 @@ conflicts=()
replaces=()
backup=()
options=()
install=
install='.install'
changelog=
source=("git+${url}.git")
noextract=()
@ -27,4 +27,6 @@ package() {
cd "${_reponame}/pkg/${pkgname}"
install -Dm0755 -o0 40_efi_setup "$pkgdir"/etc/grub.d/40_efi_setup
install -Dm0544 grub.holoscript "$pkgdir"/usr/share/holo/files/"$pkgname"/etc/default/grub.holoscript
}

View File

@ -0,0 +1,12 @@
# grub
## efi setup
See [/etc/grub.d/40_efi_setup](40_efi_setup)
## multiple entries
* disable submenu
* remember last selection
Archwiki: [GRUB/Tips_and_tricks#Multiple_entries](https://wiki.archlinux.org/title/GRUB/Tips_and_tricks#Multiple_entries)

View File

@ -0,0 +1,10 @@
#!/bin/sh
# stdin: default config
# stdout: modified config
# 1) and 2) remember last selected entry; 3) disable submenu
sed '
s|^GRUB_DEFAULT=0$|GRUB_DEFAULT=saved|;
s|^#GRUB_SAVEDEFAULT="true"$|#GRUB_SAVEDEFAULT="true"|;
s|^#GRUB_DISABLE_SUBMENU=y$|GRUB_DISABLE_SUBMENU=y|;
'

View File

@ -294,9 +294,29 @@ function user_and_pwd() {
printf "%s:%s" "root" "${ROOT_PWD}" | chpasswd --root /mnt || return $?
}
function gen_initramfs(){
function bootloader() {
# @pre
# TARGET_BLOCK_DEVICE
# LUKS_PART_UUID
case "${BIOS_TYPE}" in
uefi)
# portable fallback efi name for grub:
# * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming
# * arch-chroot /mnt cp /boot/EFI/GRUB/grubx64.efi /boot/EFI/BOOT/bootx64.efi
arch-chroot /mnt grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot --removable || return $?
;;
bios)
arch-chroot /mnt grub-install --target=i386-pc "${TARGET_BLOCK_DEVICE}" || return $?
;;
*)
echo "Not yet implemented!"
return 1
;;
esac
# TODO
true
}
function main() {
@ -322,7 +342,7 @@ function main() {
# out: BOOT_PART, LUKS_PART
partition || return $?
# in: BIOS_TYPE, BOOT_PART, LUKS_PART, LUKS_PWD, FS
# out: DATA_PART
# out: LUKS_PART_UUID, DATA_PART
format || return $?
# Combine default and chosen mount options
@ -347,7 +367,13 @@ function main() {
# in: USERNAME, USER_PWD, ROOT_PWD (optional)
user_and_pwd || return $?
gen_initramfs || return $?
mkinitcpio -P || return $?
# in: TARGET_BLOCK_DEVICE, LUKS_PART_UUID
bootloader || return $?
umount -R /mnt || return $?
cryptsetup luksClose "$(basename "${DATA_PART}")" || return $?
echo "Finished installation without errors!"
}
main "$@"

View File

@ -7,6 +7,14 @@
# -n, --noheadings
# -x, --sort column
function get_uuid() {
# arg $1: partition
# arg $2: variable name to store UUID
local -n ptr=$2 || return $?
ptr="$(blkid -o value -s UUID "${1}")" || return $?
}
function get_partitions(){
# arg $1: block-device
# @post
@ -14,7 +22,7 @@ function get_partitions(){
# Remove first line of output (which is just the block device $1 itself)
# with sed: sed 1d
PARTITIONS="$(lsblk -pln -o name "$1" | sed 1d)" || return $?
PARTITIONS="$(lsblk -pln -o name "${1}" | sed 1d)" || return $?
newline_separated_to_array PARTITIONS PARTITIONS || return $?
}
@ -110,6 +118,7 @@ function format() {
# LUKS_PWD
# FS
# @post
# LUKS_PART_UUID
# DATA_PART (variable set with value /dev/mapper/$(basename "${LUKS_PART}")
# boot partition formatted
# luks partition formatted and opened at DATA_PART
@ -129,6 +138,8 @@ function format() {
--cipher aes-xts-plain64 --key-size 512 --hash sha512 \
--iter-time 10000 --use-random "${LUKS_PART}" || return $?
get_uuid "${LUKS_PART}" LUKS_PART_UUID || return $?
local luks_name
luks_name=$(basename "${LUKS_PART}")
DATA_PART="/dev/mapper/${luks_name}"

View File

@ -2,14 +2,17 @@
pre_install() {
# Check if system is SSE4.2 capable
# lscpu is part of util-linux which is a dependency of mkinitcpio
lscpu | grep sse4_2 >/dev/null 2>&1
if ! lscpu | grep sse4_2 >/dev/null 2>&1; then
echo "Warning: mkinitcpio.conf has module 'crc32c_intel' enabled but this system is not SSE4.2 capable!"
return 1
fi
}
## arg 1: the new package version
post_install() {
holo apply
if ! mkinitcpio -P; then
echo "The previous error can be ignored on initial system installation. One should however execute 'mkinitcpio -P' after the kernel was installed.";
echo "Failed to generate initramfs. Please run 'mkinitcpio -P' manually. (This is normal during initial system installation).";
return 1;
fi
}
@ -18,11 +21,17 @@ post_install() {
## arg 2: the old package version
post_upgrade() {
holo apply
mkinitcpio -P
if ! mkinitcpio -P; then
echo "Failed to generate initramfs."
return 1
fi
}
## arg 1: the old package version
post_remove() {
holo apply
mkinitcpio -P
if ! mkinitcpio -P; then
echo "Failed to generate initramfs."
return 1
fi
}

View File

@ -2,7 +2,7 @@
_pkgname=mkinitcpio
_reponame=arch
pkgname="de-p1st-$_pkgname"
pkgver=0.0.3
pkgver=0.0.4
pkgrel=1
pkgdesc="mkinitcpio configuration"
arch=('any')

View File

@ -9,7 +9,7 @@ Special thanks to nachoparker for his article:
Install `de-p1st-repo` on your local machine as well as on
a remote server.
Adjust `/etc/de-p1st-repo/arch-repo.conf` according to your needs.
Adjust [/etc/de-p1st-repo/arch-repo.conf](arch-repo.cfg) according to your needs.
Run a webserver on the server to serve static content: