Skip to content

Commit 6526fb8

Browse files
committed
install: Write /etc/fstab entry for /boot
So that things work on reboot by default. Signed-off-by: Colin Walters <[email protected]>
1 parent 7ed4606 commit 6526fb8

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

lib/src/install.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::fmt::Display;
2+
use std::io::BufWriter;
3+
use std::io::Write;
24
use std::process::Command;
35
use std::process::Stdio;
46
use std::sync::Arc;
@@ -245,9 +247,10 @@ fn bind_mount_from_host(src: impl AsRef<Utf8Path>, dest: impl AsRef<Utf8Path>) -
245247
async fn initialize_ostree_root_from_self(
246248
state: &State,
247249
containerstate: &ContainerExecutionInfo,
248-
rootfs: &Utf8Path,
250+
root_setup: &RootSetup,
249251
kargs: &[&str],
250252
) -> Result<InstallAleph> {
253+
let rootfs = root_setup.rootfs.as_path();
251254
let opts = &state.opts;
252255
let cancellable = gio::Cancellable::NONE;
253256

@@ -358,6 +361,32 @@ async fn initialize_ostree_root_from_self(
358361

359362
drop(temporary_dir);
360363

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+
361390
let uname = cap_std_ext::rustix::process::uname();
362391

363392
let aleph = InstallAleph {
@@ -422,6 +451,7 @@ fn skopeo_supports_containers_storage() -> Result<bool> {
422451
struct RootSetup {
423452
device: Utf8PathBuf,
424453
rootfs: Utf8PathBuf,
454+
bootfs_type: Filesystem,
425455
boot_uuid: uuid::Uuid,
426456
kargs: Vec<String>,
427457
}
@@ -550,10 +580,12 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
550580
BlockSetup::Tpm2Luks => anyhow::bail!("tpm2-luks is not implemented yet"),
551581
}
552582

583+
// TODO: make this configurable
584+
let bootfs_type = Filesystem::Ext4;
585+
553586
// Initialize the /boot filesystem
554587
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")?;
557589

558590
// Initialize rootfs
559591
let rootdev = &format!("{device}{ROOTPN}");
@@ -586,6 +618,7 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
586618
Ok(RootSetup {
587619
device,
588620
rootfs,
621+
bootfs_type,
589622
boot_uuid,
590623
kargs,
591624
})
@@ -713,13 +746,9 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
713746
kargs.push(crate::bootloader::IGNITION_VARIABLE);
714747
}
715748

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?;
723752

724753
let aleph = serde_json::to_string(&aleph)?;
725754
std::fs::write(rootfs.rootfs.join(BOOTC_ALEPH_PATH), aleph).context("Writing aleph version")?;

0 commit comments

Comments
 (0)