Skip to content

Commit a7176cd

Browse files
jeckersbjmarrero
authored andcommitted
install: Pass explicit filesystem type to mount after mkfs
When mounting a freshly-created filesystem during install, pass -t <fstype> to mount rather than relying on auto-detection. util-linux 2.42 introduced an optimization (commit 8bdc2546d) where libmount reads device properties from the udev database instead of probing the device superblock with libblkid. When mkfs runs inside a container, the udev database is stale for the filesystem type because mkfs does not generate a kernel uevent — udev only re-probes devices on kernel-generated events (such as partition table changes from sfdisk), not on arbitrary block device writes. As a result, the udev database has partition tags (PARTUUID, PARTLABEL) from sfdisk but lacks ID_FS_TYPE. libmount's read_from_udev() returns success after finding those partition tags, so the libblkid direct-probe fallback is never called. Without a filesystem type, mount falls back to iterating /etc/filesystems and /proc/filesystems, which fails for filesystem modules (like xfs with CONFIG_XFS_FS=m) that are not yet loaded. Since bootc already knows the filesystem type (it just ran mkfs), passing -t avoids the auto-detection path entirely. Closes: #2148 Assisted-by: OpenCode (claude-opus-4-6) Signed-off-by: John Eckersberg <jeckersb@redhat.com>
1 parent 9e5d015 commit a7176cd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

crates/lib/src/install/baseline.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,16 @@ pub(crate) fn install_create_rootfs(
484484
}
485485
}
486486

487-
bootc_mount::mount(&rootdev_path, &physical_root_path)?;
487+
let fstype = &root_filesystem.to_string();
488+
bootc_mount::mount_typed(&rootdev_path, fstype, &physical_root_path)?;
488489
let target_rootfs = Dir::open_ambient_dir(&physical_root_path, cap_std::ambient_authority())?;
489490
crate::lsm::ensure_dir_labeled(&target_rootfs, "", Some("/".into()), 0o755.into(), sepolicy)?;
490491
let physical_root = Dir::open_ambient_dir(&physical_root_path, cap_std::ambient_authority())?;
491492
let bootfs = physical_root_path.join("boot");
492493
// Create the underlying mount point directory, which should be labeled
493494
crate::lsm::ensure_dir_labeled(&target_rootfs, "boot", None, 0o755.into(), sepolicy)?;
494495
if let Some(bootdev) = bootdev {
495-
bootc_mount::mount(&bootdev.path(), &bootfs)?;
496+
bootc_mount::mount_typed(&bootdev.path(), fstype, &bootfs)?;
496497
}
497498
// And we want to label the root mount of /boot
498499
crate::lsm::ensure_dir_labeled(&target_rootfs, "boot", None, 0o755.into(), sepolicy)?;

crates/mount/src/mount.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ pub fn mount(dev: &str, target: &Utf8Path) -> Result<()> {
145145
.run_inherited_with_cmd_context()
146146
}
147147

148+
/// Mount a device with an explicit filesystem type.
149+
///
150+
/// This avoids relying on the `mount` utility's blkid auto-detection,
151+
/// which can fail in certain container environments (e.g. when the
152+
/// required filesystem kernel module is not yet loaded and the blkid
153+
/// probe doesn't work, causing mount to fall back to iterating
154+
/// `/etc/filesystems` and `/proc/filesystems`).
155+
pub fn mount_typed(dev: &str, fstype: &str, target: &Utf8Path) -> Result<()> {
156+
Command::new("mount")
157+
.args(["-t", fstype, dev, target.as_str()])
158+
.run_inherited_with_cmd_context()
159+
}
160+
148161
/// If the fsid of the passed path matches the fsid of the same path rooted
149162
/// at /proc/1/root, it is assumed that these are indeed the same mounted
150163
/// filesystem between container and host.

0 commit comments

Comments
 (0)