MCPcopy Create free account
hub / github.com/bootc-dev/bootc / initialize_ostree_root

Function initialize_ostree_root

crates/lib/src/install.rs:894–1022  ·  view source on GitHub ↗
(state: &State, root_setup: &RootSetup)

Source from the content-addressed store, hash-verified

892
893#[context("Creating ostree deployment")]
894async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result<(Storage, bool)> {
895 let sepolicy = state.load_policy()?;
896 let sepolicy = sepolicy.as_ref();
897 // Load a fd for the mounted target physical root
898 let rootfs_dir = &root_setup.physical_root;
899 let cancellable = gio::Cancellable::NONE;
900
901 let stateroot = state.stateroot();
902
903 let has_ostree = rootfs_dir.try_exists("ostree/repo")?;
904 if !has_ostree {
905 Task::new("Initializing ostree layout", "ostree")
906 .args(["admin", "init-fs", "--modern", "."])
907 .cwd(rootfs_dir)?
908 .run()?;
909 } else {
910 println!("Reusing extant ostree layout");
911
912 let path = ".".into();
913 let _ = crate::utils::open_dir_remount_rw(rootfs_dir, path)
914 .context("remounting target as read-write")?;
915 crate::utils::remove_immutability(rootfs_dir, path)?;
916 }
917
918 // Ensure that the physical root is labeled.
919 // Another implementation: https://github.com/coreos/coreos-assembler/blob/3cd3307904593b3a131b81567b13a4d0b6fe7c90/src/create_disk.sh#L295
920 crate::lsm::ensure_dir_labeled(rootfs_dir, "", Some("/".into()), 0o755.into(), sepolicy)?;
921
922 // If we're installing alongside existing ostree and there's a separate boot partition,
923 // we need to mount it to the sysroot's /boot so ostree can write bootloader entries there
924 if has_ostree && root_setup.boot.is_some() {
925 if let Some(boot) = &root_setup.boot {
926 let source_boot = &boot.source;
927 let target_boot = root_setup.physical_root_path.join(BOOT);
928 tracing::debug!("Mount {source_boot} to {target_boot} on ostree");
929 bootc_mount::mount(source_boot, &target_boot)?;
930 }
931 }
932
933 // And also label /boot AKA xbootldr, if it exists
934 if rootfs_dir.try_exists("boot")? {
935 crate::lsm::ensure_dir_labeled(rootfs_dir, "boot", None, 0o755.into(), sepolicy)?;
936 }
937
938 // Build the list of ostree repo config options: defaults + install config
939 let ostree_opts = state
940 .install_config
941 .as_ref()
942 .and_then(|c| c.ostree.as_ref())
943 .into_iter()
944 .flat_map(|o| o.to_config_tuples());
945
946 let repo_config: Vec<_> = DEFAULT_REPO_CONFIG
947 .iter()
948 .copied()
949 .chain(ostree_opts)
950 .collect();
951

Callers 1

ostree_installFunction · 0.85

Calls 15

open_dir_remount_rwFunction · 0.85
remove_immutabilityFunction · 0.85
ensure_dir_labeledFunction · 0.85
mountFunction · 0.85
is_verity_enabledFunction · 0.85
ensure_verityFunction · 0.85
sysroot_dirFunction · 0.85
load_policyMethod · 0.80
cwdMethod · 0.80
argsMethod · 0.80
to_config_tuplesMethod · 0.80
run_capture_stderrMethod · 0.80

Tested by

no test coverage detected