|
1 | 1 | use std::fmt::Display;
|
| 2 | +use std::io::BufWriter; |
| 3 | +use std::io::Write; |
2 | 4 | use std::process::Command;
|
3 | 5 | use std::process::Stdio;
|
4 | 6 | use std::sync::Arc;
|
@@ -245,9 +247,10 @@ fn bind_mount_from_host(src: impl AsRef<Utf8Path>, dest: impl AsRef<Utf8Path>) -
|
245 | 247 | async fn initialize_ostree_root_from_self(
|
246 | 248 | state: &State,
|
247 | 249 | containerstate: &ContainerExecutionInfo,
|
248 |
| - rootfs: &Utf8Path, |
| 250 | + root_setup: &RootSetup, |
249 | 251 | kargs: &[&str],
|
250 | 252 | ) -> Result<InstallAleph> {
|
| 253 | + let rootfs = root_setup.rootfs.as_path(); |
251 | 254 | let opts = &state.opts;
|
252 | 255 | let cancellable = gio::Cancellable::NONE;
|
253 | 256 |
|
@@ -358,6 +361,32 @@ async fn initialize_ostree_root_from_self(
|
358 | 361 |
|
359 | 362 | drop(temporary_dir);
|
360 | 363 |
|
| 364 | + // Write the entry for /boot to /etc/fstab. TODO: Encourage OSes to use the karg? |
| 365 | + // Or better bind this with the grub data. |
| 366 | + sysroot.load(cancellable)?; |
| 367 | + let deployment = sysroot |
| 368 | + .deployments() |
| 369 | + .into_iter() |
| 370 | + .next() |
| 371 | + .ok_or_else(|| anyhow::anyhow!("Failed to find deployment"))?; |
| 372 | + // SAFETY: There must be a path |
| 373 | + let path = sysroot.deployment_dirpath(&deployment).unwrap(); |
| 374 | + let sysroot_dir = cap_std::fs::Dir::open_ambient_dir(rootfs, cap_std::ambient_authority()) |
| 375 | + .context("Opening rootfs")?; |
| 376 | + let root = sysroot_dir |
| 377 | + .open_dir(path.as_str()) |
| 378 | + .context("Opening deployment dir")?; |
| 379 | + let mut f = { |
| 380 | + let mut opts = cap_std::fs::OpenOptions::new(); |
| 381 | + root.open_with("etc/fstab", opts.append(true).write(true).create(true)) |
| 382 | + .context("Opening etc/fstab") |
| 383 | + .map(BufWriter::new)? |
| 384 | + }; |
| 385 | + let boot_uuid = &root_setup.boot_uuid; |
| 386 | + let bootfs_type_str = root_setup.bootfs_type.to_string(); |
| 387 | + writeln!(f, "UUID={boot_uuid} /boot {bootfs_type_str} defaults 1 2")?; |
| 388 | + f.flush()?; |
| 389 | + |
361 | 390 | let uname = cap_std_ext::rustix::process::uname();
|
362 | 391 |
|
363 | 392 | let aleph = InstallAleph {
|
@@ -422,6 +451,7 @@ fn skopeo_supports_containers_storage() -> Result<bool> {
|
422 | 451 | struct RootSetup {
|
423 | 452 | device: Utf8PathBuf,
|
424 | 453 | rootfs: Utf8PathBuf,
|
| 454 | + bootfs_type: Filesystem, |
425 | 455 | boot_uuid: uuid::Uuid,
|
426 | 456 | kargs: Vec<String>,
|
427 | 457 | }
|
@@ -550,10 +580,12 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
|
550 | 580 | BlockSetup::Tpm2Luks => anyhow::bail!("tpm2-luks is not implemented yet"),
|
551 | 581 | }
|
552 | 582 |
|
| 583 | + // TODO: make this configurable |
| 584 | + let bootfs_type = Filesystem::Ext4; |
| 585 | + |
553 | 586 | // Initialize the /boot filesystem
|
554 | 587 | let bootdev = &format!("{device}{BOOTPN}");
|
555 |
| - let boot_uuid = |
556 |
| - mkfs(bootdev, Filesystem::Ext4, Some("boot"), []).context("Initializing /boot")?; |
| 588 | + let boot_uuid = mkfs(bootdev, bootfs_type, Some("boot"), []).context("Initializing /boot")?; |
557 | 589 |
|
558 | 590 | // Initialize rootfs
|
559 | 591 | let rootdev = &format!("{device}{ROOTPN}");
|
@@ -586,6 +618,7 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
|
586 | 618 | Ok(RootSetup {
|
587 | 619 | device,
|
588 | 620 | rootfs,
|
| 621 | + bootfs_type, |
589 | 622 | boot_uuid,
|
590 | 623 | kargs,
|
591 | 624 | })
|
@@ -713,13 +746,9 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
|
713 | 746 | kargs.push(crate::bootloader::IGNITION_VARIABLE);
|
714 | 747 | }
|
715 | 748 |
|
716 |
| - let aleph = initialize_ostree_root_from_self( |
717 |
| - &state, |
718 |
| - &container_state, |
719 |
| - &rootfs.rootfs, |
720 |
| - kargs.as_slice(), |
721 |
| - ) |
722 |
| - .await?; |
| 749 | + let aleph = |
| 750 | + initialize_ostree_root_from_self(&state, &container_state, &rootfs, kargs.as_slice()) |
| 751 | + .await?; |
723 | 752 |
|
724 | 753 | let aleph = serde_json::to_string(&aleph)?;
|
725 | 754 | std::fs::write(rootfs.rootfs.join(BOOTC_ALEPH_PATH), aleph).context("Writing aleph version")?;
|
|
0 commit comments