-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install: Support gathering more info for host root (including LVM)
Teach `install to-existing-root` how to gather kernel arguments and information we need from `/proc/cmdline` (such as `rd.lvm.lv`). In this case too, we need to adjust the args to use `-v /dev:/dev` because we need the stuff udev generates from the real host root. With these things together, I can do a bootc alongside install targeting a Fedora Server instance. Closes: #175 Signed-off-by: Colin Walters <[email protected]>
- Loading branch information
Showing
5 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use anyhow::Result; | ||
use fn_error_context::context; | ||
|
||
/// This is used by dracut. | ||
pub(crate) const INITRD_ARG_PREFIX: &str = "rd."; | ||
/// The kernel argument for configuring the rootfs flags. | ||
pub(crate) const ROOTFLAGS: &str = "rootflags="; | ||
|
||
/// Parse the kernel command line. This is strictly | ||
/// speaking not a correct parser, as the Linux kernel | ||
/// supports quotes. However, we don't yet need that here. | ||
/// | ||
/// See systemd's code for one userspace parser. | ||
#[context("Reading /proc/cmdline")] | ||
pub(crate) fn parse_cmdline() -> Result<Vec<String>> { | ||
let cmdline = std::fs::read_to_string("/proc/cmdline")?; | ||
let r = cmdline | ||
.split_ascii_whitespace() | ||
.map(ToOwned::to_owned) | ||
.collect(); | ||
Ok(r) | ||
} | ||
|
||
/// Return the value for the string in the vector which has the form target_key=value | ||
pub(crate) fn find_first_cmdline_arg<'a>( | ||
args: impl Iterator<Item = &'a str>, | ||
target_key: &str, | ||
) -> Option<&'a str> { | ||
args.filter_map(|arg| { | ||
if let Some((k, v)) = arg.split_once('=') { | ||
if target_key == k { | ||
return Some(v); | ||
} | ||
} | ||
None | ||
}) | ||
.next() | ||
} | ||
|
||
#[test] | ||
fn test_find_first() { | ||
let kargs = &["foo=bar", "root=/dev/vda", "blah", "root=/dev/other"]; | ||
let kargs = || kargs.iter().map(|&s| s); | ||
assert_eq!(find_first_cmdline_arg(kargs(), "root"), Some("/dev/vda")); | ||
assert_eq!(find_first_cmdline_arg(kargs(), "nonexistent"), None); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters