(
composefs_mnt_fd: std::os::fd::OwnedFd,
device: &bootc_blockdev::Device,
)
| 1212 | // TODO: install to all ESPs on multi-device setups |
| 1213 | #[context("Preparing image root for bootloader installation")] |
| 1214 | pub(crate) fn new( |
| 1215 | composefs_mnt_fd: std::os::fd::OwnedFd, |
| 1216 | device: &bootc_blockdev::Device, |
| 1217 | ) -> Result<Self> { |
| 1218 | let roots = device.find_all_roots()?; |
| 1219 | let mut esp_part = None; |
| 1220 | for root in &roots { |
| 1221 | if let Some(esp) = root.find_partition_of_esp_optional()? { |
| 1222 | esp_part = Some(esp); |
| 1223 | break; |
| 1224 | } |
| 1225 | } |
| 1226 | let esp_part = esp_part.ok_or_else(|| anyhow!("ESP partition not found"))?; |
| 1227 | |
| 1228 | // Attach the detached composefs fsmount fd to a real tmpdir path so |
| 1229 | // that mount(2) and bootctl --root can work with it. |
| 1230 | let composefs = TempMount::mount_fd(composefs_mnt_fd) |
| 1231 | .context("Attaching composefs image to temporary directory")?; |
| 1232 | |
| 1233 | // TODO: support XBOOTLDR. Per BLS, the ESP should be mounted at /efi |
| 1234 | // when a separate XBOOTLDR partition is present at /boot. bootc does |
| 1235 | // not yet detect or use XBOOTLDR in the composefs install path, so |
| 1236 | // unconditionally mount the ESP at /boot for now. |
| 1237 | let esp_subdir = "boot"; |
| 1238 | |
| 1239 | let esp_path = composefs.dir.path().join(esp_subdir); |
| 1240 | let esp = |
| 1241 | mount_esp_at(&esp_part.path(), esp_path).context("Mounting ESP into composefs root")?; |
| 1242 | |
| 1243 | // Mount a tmpfs over /tmp so that tools invoked with --root have a |
| 1244 | // writable scratch area without touching the read-only EROFS root. |
| 1245 | let tmp_path = composefs.dir.path().join("tmp"); |
| 1246 | let tmp = bootc_mount::tempmount::MountGuard::mount( |
| 1247 | "tmpfs", |
| 1248 | tmp_path, |
| 1249 | "tmpfs", |
| 1250 | MountFlags::NOEXEC | MountFlags::NOSUID | MountFlags::NODEV, |
| 1251 | None::<&std::ffi::CStr>, |
| 1252 | ) |
| 1253 | .context("Mounting tmpfs into composefs root")?; |
| 1254 | |
| 1255 | Ok(Self { |
| 1256 | _esp: esp, |
| 1257 | _tmp: tmp, |
| 1258 | composefs, |
| 1259 | esp_subdir, |
| 1260 | }) |
| 1261 | } |
| 1262 | |
| 1263 | /// The composefs image as a capability-safe directory (for file reads). |
| 1264 | pub(crate) fn dir(&self) -> &Dir { |
nothing calls this directly
no test coverage detected