(state: &State, root_setup: &RootSetup)
| 892 | |
| 893 | #[context("Creating ostree deployment")] |
| 894 | async 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 |
no test coverage detected