Add citadel.revert-rootfs boot option

Forces booting from the older rootfs partition in case the newer
partition is broken or unbootable.
This commit is contained in:
Bruce Leidl 2021-10-04 06:09:26 -04:00
parent 9fa6b5c9cb
commit 8d8f9b69ee
2 changed files with 28 additions and 2 deletions

View File

@ -5,7 +5,7 @@ use libcitadel::{BlockDev, ResourceImage, CommandLine, ImageHeader, Partition, R
use libcitadel::verity::Verity; use libcitadel::verity::Verity;
pub fn setup_rootfs() -> Result<()> { pub fn setup_rootfs() -> Result<()> {
let mut p = choose_boot_partiton(true)?; let mut p = choose_boot_partiton(true, CommandLine::revert_rootfs())?;
if CommandLine::noverity() { if CommandLine::noverity() {
setup_partition_unverified(&p) setup_partition_unverified(&p)
} else { } else {
@ -75,7 +75,26 @@ fn setup_linear_mapping(blockdev: &Path) -> Result<()> {
Ok(()) Ok(())
} }
fn choose_boot_partiton(scan: bool) -> Result<Partition> { fn is_revertible_partition(best: &Option<Partition>, partition: &Partition) -> bool {
if !is_bootable(partition) {
return false;
}
match best {
Some(p) => p.path() != partition.path(),
None => true,
}
}
fn choose_revert_partition(best: Option<Partition>) -> Option<Partition> {
for p in Partition::rootfs_partitions().unwrap_or(Vec::new()) {
if is_revertible_partition(&best, &p) {
return Some(p);
}
}
best
}
fn choose_boot_partiton(scan: bool, revert_rootfs: bool) -> Result<Partition> {
let mut partitions = Partition::rootfs_partitions()?; let mut partitions = Partition::rootfs_partitions()?;
if scan { if scan {
@ -88,6 +107,11 @@ fn choose_boot_partiton(scan: bool) -> Result<Partition> {
for p in partitions { for p in partitions {
best = compare_boot_partitions(best, p); best = compare_boot_partitions(best, p);
} }
if revert_rootfs {
best = choose_revert_partition(best);
}
best.ok_or_else(|| format_err!("No partition found to boot from").into()) best.ok_or_else(|| format_err!("No partition found to boot from").into())
} }

View File

@ -61,6 +61,8 @@ impl CommandLine {
pub fn overlay() -> bool { Self::var_exists("citadel.overlay") } pub fn overlay() -> bool { Self::var_exists("citadel.overlay") }
pub fn revert_rootfs() -> bool { Self::var_exists("citadel.revert-rootfs") }
/// Return `true` if sealed realmfs images are enabled on kernel command line /// Return `true` if sealed realmfs images are enabled on kernel command line
pub fn sealed() -> bool { Self::var_exists("citadel.sealed") } pub fn sealed() -> bool { Self::var_exists("citadel.sealed") }