Bound deployment retention and harden ESP synchronization (D-103)
This commit is contained in:
parent
b93fb280b7
commit
a87a554b2f
3 changed files with 76 additions and 9 deletions
|
|
@ -1,13 +1,73 @@
|
|||
[[ $EUID == 0 ]] || { echo 'Run as root' >&2; exit 1; }
|
||||
if [[ $1 == boot-sync ]]; then
|
||||
set -euo pipefail
|
||||
[[ ${SERVICE_RESULT:-success} == success ]] || { echo 'OSTree finalization failed; ESP unchanged' >&2; exit 1; }
|
||||
[[ -e /run/ostree-booted ]]
|
||||
mountpoint -q /efi
|
||||
# Copy new artifacts before changing entry selection; retain old artifacts.
|
||||
cp -a /sysroot/boot/ostree/. /efi/ostree/
|
||||
mkdir -p /efi/loader/entries
|
||||
cp -aL /sysroot/boot/loader/entries/. /efi/loader/entries/
|
||||
mountpoint -q /efi || { echo '/efi is not mounted; ESP unchanged' >&2; exit 1; }
|
||||
# D-103: an XBOOTLDR /boot mount is written by OSTree directly; nothing to mirror.
|
||||
mountpoint -q /boot && exit 0
|
||||
src=/sysroot/boot/ostree
|
||||
dst=/efi/ostree
|
||||
esrc=/sysroot/boot/loader/entries
|
||||
edst=/efi/loader/entries
|
||||
mkdir -p "$dst" "$edst"
|
||||
# Never retain artifacts of a deployment OSTree has already pruned.
|
||||
for d in "$dst"/archipelago-*; do
|
||||
[[ -d $d ]] || continue
|
||||
b=${d##*/}
|
||||
[[ -d $src/$b ]] || { echo "prune stale ESP copy $b"; rm -rf "$d"; }
|
||||
done
|
||||
for e in "$edst"/*.conf; do
|
||||
[[ -f $e ]] || continue
|
||||
b=${e##*/}
|
||||
[[ -f $esrc/$b ]] || { echo "drop stale loader entry $b"; rm -f "$e"; }
|
||||
done
|
||||
# Check space before touching valid artifacts; publish entries only afterwards.
|
||||
need=0
|
||||
incomplete=()
|
||||
for d in "$src"/archipelago-*; do
|
||||
[[ -d $d ]] || continue
|
||||
b=${d##*/}
|
||||
bad=0
|
||||
if [[ -d $dst/$b ]]; then
|
||||
while IFS= read -r -d '' f; do
|
||||
rel=${f#"$d"/}
|
||||
if [[ ! -f $dst/$b/$rel || $(stat -c %s "$f") != $(stat -c %s "$dst/$b/$rel") ]]; then bad=1; break; fi
|
||||
done < <(find "$d" -type f -print0)
|
||||
else
|
||||
bad=1
|
||||
fi
|
||||
if (( bad )); then
|
||||
incomplete+=("$b")
|
||||
need=$((need + $(du -sb "$d" | cut -f1)))
|
||||
fi
|
||||
done
|
||||
avail=$(df --output=avail -B1 /efi | tail -1)
|
||||
if (( need > avail )); then
|
||||
echo "refusing to publish boot entries: need $need bytes, ESP has $avail" >&2
|
||||
exit 1
|
||||
fi
|
||||
for b in "${incomplete[@]}"; do
|
||||
d=$src/$b
|
||||
rm -rf "$dst/.$b.tmp"
|
||||
cp -a "$d" "$dst/.$b.tmp"
|
||||
for f in "$d"/*; do
|
||||
[[ -f $f ]] || continue
|
||||
cmp -s "$f" "$dst/.$b.tmp/${f##*/}" || { echo "copy verification failed for $b/${f##*/}" >&2; rm -rf "$dst/.$b.tmp"; exit 1; }
|
||||
done
|
||||
rm -rf "$dst/$b"
|
||||
mv "$dst/.$b.tmp" "$dst/$b"
|
||||
echo "copied boot artifacts $b"
|
||||
done
|
||||
for e in "$esrc"/*.conf; do
|
||||
[[ -f $e ]] || continue
|
||||
linux=$(awk '$1=="linux"{print $2}' "$e")
|
||||
initrd=$(awk '$1=="initrd"{print $2}' "$e")
|
||||
[[ -f /efi$linux && -f /efi$initrd ]] || { echo "missing kernel/initrd for ${e##*/}; entries not updated" >&2; exit 1; }
|
||||
done
|
||||
for e in "$esrc"/*.conf; do [[ -f $e ]] || continue; cp -f "$e" "$edst/"; done
|
||||
sync -f /efi
|
||||
echo 'boot artifacts synchronized'
|
||||
exit 0
|
||||
fi
|
||||
[[ -e /run/ostree-booted ]] || { echo 'Not an installed OSTree deployment' >&2; exit 1; }
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ mod tests {
|
|||
{"staged":true,"arguments":["console=tty0","console=ttyS0,115200","example=two words"]}]);
|
||||
let args = deploy_args(&"a".repeat(64), &selected(&rows).unwrap()["arguments"]).unwrap();
|
||||
assert_eq!(&args[6..9], ["--karg-append=console=tty0", "--karg-append=console=ttyS0,115200", "--karg-append=example=two words"]);
|
||||
assert!(args.contains(&"--stage".into()) && args.contains(&"--retain".into()));
|
||||
assert!(args.contains(&"--stage".into()) && !args.contains(&"--retain".into()));
|
||||
assert!(!args.iter().any(|a| a == "--karg-append=quiet"));
|
||||
assert!(deploy_args("stable/kde", &json!([])).is_err());
|
||||
assert!(deploy_args(&"a".repeat(64), &json!([false])).is_err());
|
||||
|
|
@ -77,7 +77,8 @@ pub fn deployment_args(target: &str) -> Result<(Vec<String>, Value)> {
|
|||
|
||||
fn deploy_args(target: &str, arguments: &Value) -> Result<Vec<String>> {
|
||||
if !archipelago_contracts::system_bus::checksum(target) { return Err(fail("Invalid deployment checksum")); }
|
||||
let mut args: Vec<String> = ["admin", "deploy", "--stage", "--retain", "--os=archipelago", "--karg-none"].iter().map(|s| (*s).into()).collect();
|
||||
// D-103: keep OSTree's default booted/previous/pending/pinned retention.
|
||||
let mut args: Vec<String> = ["admin", "deploy", "--stage", "--os=archipelago", "--karg-none"].iter().map(|s| (*s).into()).collect();
|
||||
for arg in arguments.as_array().ok_or_else(|| fail("Missing argument vector"))? {
|
||||
let arg = arg.as_str().ok_or_else(|| fail("Invalid argument vector"))?;
|
||||
args.push(format!("--karg-append={arg}"));
|
||||
|
|
|
|||
|
|
@ -193,12 +193,18 @@ fn require_newer(base: &str, target: &str) -> Result<(), String> {
|
|||
}
|
||||
pub(crate) fn stage_deployment(commit: &str) -> Result<(), String> {
|
||||
crate::progress::phase("Staging deployment and boot entry", "Подготовка deployment и загрузочной записи");
|
||||
let mut args = vec!["admin", "deploy", "--stage", "--retain", "--os=archipelago"];
|
||||
// D-103: OSTree default retention keeps booted/previous/pending/pinned.
|
||||
// --retain kept every previous deployment forever; do not use it.
|
||||
let mut args = vec!["admin", "deploy", "--stage", "--os=archipelago"];
|
||||
if matches!(variant()?, "gnome" | "kde") {
|
||||
args.extend(["--karg=quiet", "--karg=splash", "--karg=plymouth.ignore-serial-consoles"]);
|
||||
}
|
||||
args.push(commit);
|
||||
output("ostree", &args).map(|_| ())
|
||||
let result = output("ostree", &args).map(|_| ());
|
||||
// Best effort: remove unpinned deployments after a successful stage so the
|
||||
// boot filesystem cannot accumulate one initramfs per historical update.
|
||||
if result.is_ok() { let _ = output("ostree", &["admin", "cleanup"]); }
|
||||
result
|
||||
}
|
||||
fn reconcile_operations() -> Result<(), String> {
|
||||
// Caller owns the shared host-operation lock: no prior CLI operation can run.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue