Compare commits
No commits in common. "c666eb8e3fdf5e4d26f8ba11fe3ed1a15bac584b" and "38745b9d447eb0a04d51931cf8f264a2f5d967ed" have entirely different histories.
c666eb8e3f
...
38745b9d44
23
README.md
23
README.md
@ -13,17 +13,20 @@ required (though the name remains).
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
While not depending on it directly, this tool expects that you already set up
|
This tool expects that you already set up snapper. It also expects that each
|
||||||
snapper. It expects, that each snapshot contains its kernel
|
snapshots linux and initramfs files (`/boot/vmlinuz-linux` and
|
||||||
(`/boot/vmlinuz-linux`) and initramfs (`/boot/intitramfs-linux.img`), as well as
|
`/boot/initramfs-linux.img`) as well as a kernel command line file
|
||||||
a kernel command line file (`/etc/snap-pac-uki/kernel-cmd`).
|
(`/etc/snap-pac-uki/kernel-cmd`) are available within each snapshot.
|
||||||
|
|
||||||
For generating the current and fallback UKIs, the kernel and initramfs files of
|
The fallback initramfs (`/boot/initramfs-linux-fallback.img`) and fallback
|
||||||
the currently running system are used. For a kernel cmd, it uses
|
command line file (`/etc/snap-pac-uki/kernel-cmd-fallback`) are only required
|
||||||
`/etc/snap-pac-uki/kernel-cmd-current` and `/etc/snap-pac-uki/kernel-cmd-fallback`.
|
on the current system.
|
||||||
|
|
||||||
If you want to boot a UKI directly, use the `efibootmgr` command to create an
|
Also the current command line file (`/etc/snap-pac-uki/kernel-cmd-current`)
|
||||||
entry.
|
needs is only required on the current system.
|
||||||
|
|
||||||
|
EFI boot options are only created for each snapshot. If you want the UKIs
|
||||||
|
created for the current system, you'll need to add boot entries yourself:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# template
|
# template
|
||||||
@ -53,7 +56,7 @@ efibootmgr -c \
|
|||||||
1. You can install the dependencies of this program with the following command:
|
1. You can install the dependencies of this program with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pacman -S fish ripgrep sbsigntools sed
|
pacman -S fish efibootmgr jq ripgrep sbsigntools sed snapper
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Download the latest release from [here][releases] and unpack it.
|
2. Download the latest release from [here][releases] and unpack it.
|
||||||
|
@ -2,7 +2,7 @@ function config -d "sets some configuration variables"
|
|||||||
|
|
||||||
# If this is not set to "yes", snap-pac-uki will not do anything when
|
# If this is not set to "yes", snap-pac-uki will not do anything when
|
||||||
# executed.
|
# executed.
|
||||||
#
|
|
||||||
# This is to make sure that this program can be installed with pacman. If
|
# This is to make sure that this program can be installed with pacman. If
|
||||||
# this wasn't done, pacman would install this program with an default
|
# this wasn't done, pacman would install this program with an default
|
||||||
# config, which most likely wouldn't work correctly. Therefore this needs
|
# config, which most likely wouldn't work correctly. Therefore this needs
|
||||||
@ -21,6 +21,21 @@ function config -d "sets some configuration variables"
|
|||||||
# images.
|
# images.
|
||||||
set -g CFG_DEFAULT_SUBVOL "@"
|
set -g CFG_DEFAULT_SUBVOL "@"
|
||||||
|
|
||||||
|
# Wheter to add a new EFI entry for a new snapshot uki
|
||||||
|
set -g CFG_EFI "yes"
|
||||||
|
|
||||||
|
# The device the EFI partition resides on
|
||||||
|
set -g CFG_EFI_DEV "/dev/nvme0n1"
|
||||||
|
|
||||||
|
# The "efi directory" that will contain the ukis
|
||||||
|
set -g CFG_EFI_PATH "\EFI\Linux"
|
||||||
|
|
||||||
|
# The efi partitions number on the device
|
||||||
|
set -g CFG_EFI_PART "1"
|
||||||
|
|
||||||
|
# The snapper config name
|
||||||
|
set -g CFG_SNAPSHOT_CONFIG "root"
|
||||||
|
|
||||||
# The linux fs path containing all snapshot data
|
# The linux fs path containing all snapshot data
|
||||||
set -g CFG_SNAPSHOT_PATH "/.snapshots"
|
set -g CFG_SNAPSHOT_PATH "/.snapshots"
|
||||||
|
|
||||||
|
@ -7,8 +7,10 @@ end
|
|||||||
|
|
||||||
function check_deps -d "checks if all dependencies are available"
|
function check_deps -d "checks if all dependencies are available"
|
||||||
set -l dependencies \
|
set -l dependencies \
|
||||||
|
"jq" \
|
||||||
"rg" \
|
"rg" \
|
||||||
"sed" \
|
"sed" \
|
||||||
|
"snapper" \
|
||||||
|
|
||||||
for dep in $dependencies
|
for dep in $dependencies
|
||||||
which $dep >/dev/null 2>/dev/null
|
which $dep >/dev/null 2>/dev/null
|
||||||
@ -18,6 +20,12 @@ function check_deps -d "checks if all dependencies are available"
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
which "efibootmgr" >/dev/null 2>/dev/null
|
||||||
|
if test $status != "0" -a $CFG_EFI = "yes"
|
||||||
|
set -g CFG_EFI "no"
|
||||||
|
echo "CFG_EFI overwriten to \"no\": 'efibootmgr' not available"
|
||||||
|
end
|
||||||
|
|
||||||
which "sbsign" >/dev/null 2>/dev/null
|
which "sbsign" >/dev/null 2>/dev/null
|
||||||
if test $status != "0" -a $CFG_SECUREBOOT = "yes"
|
if test $status != "0" -a $CFG_SECUREBOOT = "yes"
|
||||||
set -g CFG_SECUREBOOT "no"
|
set -g CFG_SECUREBOOT "no"
|
||||||
@ -25,11 +33,11 @@ function check_deps -d "checks if all dependencies are available"
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function find_ukiless_snapshots -d "find"
|
function find_tasks -d "finds out what the program needs to do"
|
||||||
set -ge TASK_UKI
|
set -ge TASK_UKI
|
||||||
|
|
||||||
for id in (ls $CFG_SNAPSHOT_PATH)
|
for id in (snapper -c $CFG_SNAPSHOT_CONFIG --jsonout ls | jq ".$CFG_SNAPSHOT_CONFIG [] | .number")
|
||||||
if test $id = "0"
|
if test "$id" = "0"
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -58,7 +66,16 @@ function create_uki -d "creates a new uki" -a variant id
|
|||||||
end
|
end
|
||||||
|
|
||||||
# create initrd
|
# create initrd
|
||||||
|
set amd "$prefix/boot/amd-ucode.img"
|
||||||
|
set intel "$prefix/boot/intel-ucode.img"
|
||||||
set initrd "$bd/initramfs-linux$fallback.img"
|
set initrd "$bd/initramfs-linux$fallback.img"
|
||||||
|
|
||||||
|
if test -f $amd
|
||||||
|
cat $amd >> $initrd
|
||||||
|
end
|
||||||
|
if test -f $intel
|
||||||
|
cat $intel >> $initrd
|
||||||
|
end
|
||||||
cat "$prefix/boot/initramfs-linux$fallback.img" >> $initrd
|
cat "$prefix/boot/initramfs-linux$fallback.img" >> $initrd
|
||||||
|
|
||||||
# create uki
|
# create uki
|
||||||
@ -122,13 +139,19 @@ function create_current_uki -d "creates an uki for the current system"
|
|||||||
create_uki fallback
|
create_uki fallback
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function add_efi_entry -d "adds an efi boot entry for a snapshot uki" -a id
|
||||||
|
efibootmgr -q -C -d $CFG_EFI_DEV -p $CFG_EFI_PART \
|
||||||
|
-l "$CFG_EFI_PATH\arch-linux-$id.efi" \
|
||||||
|
-L "Arch Linux (Snapshot $id)"
|
||||||
|
end
|
||||||
|
|
||||||
function main
|
function main
|
||||||
# prepare for execution
|
# prepare for execution
|
||||||
source "/etc/snap-pac-uki/config.fish"
|
source "/etc/snap-pac-uki/config.fish"
|
||||||
config
|
config
|
||||||
|
|
||||||
if test "$CFG_ENABLED" != "yes"
|
if test "$CFG_ENABLED" != "yes"
|
||||||
echo "==> snap-pac-uki not enabled in config file" 1>&2
|
echo "not enabled in config file" 1>&2
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,7 +159,7 @@ function main
|
|||||||
|
|
||||||
switch $argv[1]
|
switch $argv[1]
|
||||||
case "snapshots"
|
case "snapshots"
|
||||||
find_ukiless_snapshots
|
find_tasks
|
||||||
for id in $TASK_UKI
|
for id in $TASK_UKI
|
||||||
echo "==> found snapshot without uki: $id"
|
echo "==> found snapshot without uki: $id"
|
||||||
|
|
||||||
@ -145,6 +168,11 @@ function main
|
|||||||
|
|
||||||
cp "$CFG_BUILD_DIR/$id/arch-linux-$id.efi" "$CFG_UKI_DIR"
|
cp "$CFG_BUILD_DIR/$id/arch-linux-$id.efi" "$CFG_UKI_DIR"
|
||||||
echo " -> copied uki for snapshot $id into uki directory"
|
echo " -> copied uki for snapshot $id into uki directory"
|
||||||
|
|
||||||
|
if test "$CFG_EFI" = "yes"
|
||||||
|
add_efi_entry $id
|
||||||
|
echo " -> created efi boot entry for uki of snapshot $id"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
case "current"
|
case "current"
|
||||||
@ -160,11 +188,15 @@ function main
|
|||||||
case "clean"
|
case "clean"
|
||||||
echo "==> cleaning ukis"
|
echo "==> cleaning ukis"
|
||||||
|
|
||||||
set ids (ls $CFG_SNAPSHOT_PATH)
|
set ids (snapper -c $CFG_SNAPSHOT_CONFIG --jsonout ls | jq ".$CFG_SNAPSHOT_CONFIG [] | .number")
|
||||||
for uki in (ls "$CFG_UKI_DIR" | rg "[0-9]" | sed "s/arch-linux-\([0-9]*\).efi/\1/")
|
for uki in (ls "$CFG_UKI_DIR" | rg "[0-9]" | sed "s/arch-linux-\([0-9]*\).efi/\1/")
|
||||||
if not contains "$uki" $ids
|
if not contains "$uki" $ids
|
||||||
echo " -> cleaning uki and boot entry for removed snapshot $uki"
|
echo " -> cleaning uki and boot entry for removed snapshot $uki"
|
||||||
rm "$CFG_UKI_DIR/arch-linux-$uki.efi"
|
rm "$CFG_UKI_DIR/arch-linux-$uki.efi"
|
||||||
|
|
||||||
|
if test "$CFG_EFI" = "yes"
|
||||||
|
efibootmgr -q -b (efibootmgr -v | rg "arch-linux-$uki.efi" | sed "s/\*//;s/Boot0*\(.*\) Arch .*/\1/") -B
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user