Skip to content

Commit

Permalink
initoverlayfs: Add initial initoverlayfs support
Browse files Browse the repository at this point in the history
This patch adds the option to use initoverlayfs project with
rpm-ostree. It adds InitOverlayFS as option in rpm-ostreed.conf
and when set it to true it will call initoverlayfs-install bin to
generate the initramfs and initoverlayfs images.

Signed-off-by: Douglas Schilling Landgraf <[email protected]>
  • Loading branch information
dougsland committed Dec 9, 2023
1 parent fc39c53 commit cab12f0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
31 changes: 31 additions & 0 deletions rust/src/cliwrap/cliutil.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use anyhow::Result;
use std::collections::HashMap;
use std::fs::File;
use std::io::{self, BufRead, BufReader, Error, ErrorKind};
use std::os::unix::process::CommandExt;
use std::{thread, time};

Expand Down Expand Up @@ -94,3 +97,31 @@ pub fn run_unprivileged<T: AsRef<str>>(
exec_real_binary(target_bin, &argv)
}
}

pub fn read_config_file(file_path: &str, key_to_check: &str) -> Result<Option<String>, io::Error> {
let file = File::open(file_path)?;
let reader = BufReader::new(file);

let mut config_map = HashMap::new();

for line in reader.lines() {
let line = line?;
// Ignore comments
if !line.trim().starts_with("#") {
// Split the line into key and value using '=' as a delimiter
let parts: Vec<&str> = line.splitn(2, '=').map(|s| s.trim()).collect();
if parts.len() == 2 {
config_map.insert(parts[0].to_string(), parts[1].to_string());
} else {
return Err(Error::new(ErrorKind::Other, "An example error occurred"));
}
}
}

// Check the value of the specified key
if let Some(value) = config_map.get(key_to_check) {
Ok(Some(value.clone()))
} else {
Ok(None)
}
}
29 changes: 29 additions & 0 deletions rust/src/cliwrap/kernel_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ fn redo_systemctl_wrap() -> Result<()> {
Ok(())
}

#[context("Running initoverlayfs")]
fn run_initoverlayfs() -> Result<()> {
const OSTREED_CONFIGFILE: &str = "/etc/ostreed.conf";
const INITOVERLAY_CONFIGNAME: &str = "InitOverlayFS";
const INITOVERLAY_INSTALL_CMD: &str = "initoverlayfs-install";

match crate::cliwrap::cliutil::read_config_file(OSTREED_CONFIGFILE, INITOVERLAY_CONFIGNAME) {
Ok(Some(value)) if value == "true" => {
let empty_argv: Vec<&str> = Vec::new();
if let Err(err) = cliutil::exec_real_binary(INITOVERLAY_INSTALL_CMD, &empty_argv) {
return Err(anyhow!(
"Error: Command '{}' failed with: {}",
INITOVERLAY_INSTALL_CMD,
err
));
}
}
_ => {
// Ignore all other cases (key not found or value not equal to "true")
}
}
Ok(())
}

#[context("Running dracut")]
fn run_dracut(kernel_dir: &str) -> Result<()> {
let root_fs = Utf8Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
Expand Down Expand Up @@ -108,5 +132,10 @@ fn run_dracut(kernel_dir: &str) -> Result<()> {
&root_fs,
(Utf8Path::new("lib/modules").join(kernel_dir)).join("initramfs.img"),
)?;

if let Err(error) = run_initoverlayfs() {
return Err(anyhow!("Failed to execute initoverlayfs: {}", error));
}

Ok(())
}
1 change: 1 addition & 0 deletions src/daemon/rpm-ostreed.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
#AutomaticUpdatePolicy=none
#IdleExitTimeout=60
#LockLayering=false
#InitOverlayFS=false

0 comments on commit cab12f0

Please sign in to comment.