Skip to content

Commit 9b6126a

Browse files
committed
efi: to safely unmount a filesystem (like /boot/efi), first
ensure all pending writes are flushed to disk using `sync` Fix error: ``` umount: /boot/efi: target is busy. error: unmount after validate: Failed to unmount "/boot/efi": Child ["umount" "/boot/efi"] exited: exit status: 32 ```
1 parent 5ec2b6a commit 9b6126a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/efi.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};
1010
use std::process::Command;
1111

1212
use anyhow::{bail, Context, Result};
13+
use bootc_utils::CommandRunExt;
1314
use cap_std::fs::Dir;
1415
use cap_std_ext::cap_std;
1516
use fn_error_context::context;
@@ -22,7 +23,7 @@ use widestring::U16CString;
2223
use crate::bootupd::RootContext;
2324
use crate::model::*;
2425
use crate::ostreeutil;
25-
use crate::util::{self, CommandRunExt};
26+
use crate::util;
2627
use crate::{blockdev, filetree};
2728
use crate::{component::*, packagesystem};
2829

@@ -123,6 +124,14 @@ impl Efi {
123124

124125
fn unmount(&self) -> Result<()> {
125126
if let Some(mount) = self.mountpoint.borrow_mut().take() {
127+
// To safely unmount a filesystem (like `/boot/efi`),
128+
// first ensure all pending writes are flushed to disk using `sync`.
129+
Command::new("sync")
130+
.arg("--file-system")
131+
.arg(&mount)
132+
.run_with_cmd_context()
133+
.with_context(|| format!("Failed to sync before unmounting {mount:?}"))?;
134+
126135
Command::new("umount")
127136
.arg(&mount)
128137
.run()

0 commit comments

Comments
 (0)