From 754eae3726beb68b1e117131ec7332116dca209c Mon Sep 17 00:00:00 2001 From: Sachin Sant Date: Tue, 23 Jul 2024 21:11:28 +0530 Subject: [PATCH] install: Force mkfs.xfs to overwrite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reusing a disk (after manually deleting partitions on it) with xfs as file system, install to-disk command fails complaning about existing file system on root partition. Creating root filesystem (xfs) on device /dev/sdb2 (size=107.4 GB) > mkfs.xfs -m uuid=4826aa5b-0dd0-4382-a0c1-7c0b77cfd47d -L root /dev/sdb2 mkfs.xfs: /dev/sdb2 appears to contain an existing filesystem (xfs). mkfs.xfs: Use the -f option to force overwrite. Use the -f option with mkfs.xfs to force overwrite when --wipe is used. Signed-off-by: Sachin Sant Signed-off-by: Colin Walters --- lib/src/install/baseline.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/src/install/baseline.rs b/lib/src/install/baseline.rs index 180a3a15d..0aa86128c 100644 --- a/lib/src/install/baseline.rs +++ b/lib/src/install/baseline.rs @@ -124,6 +124,7 @@ fn mkfs<'a>( dev: &str, fs: Filesystem, label: &str, + wipe: bool, opts: impl IntoIterator, ) -> Result { let devinfo = crate::blockdev::list_dev(dev.into())?; @@ -135,6 +136,9 @@ fn mkfs<'a>( ); match fs { Filesystem::Xfs => { + if wipe { + t.cmd.arg("-f"); + } t.cmd.arg("-m"); t.cmd.arg(format!("uuid={u}")); } @@ -381,15 +385,21 @@ pub(crate) fn install_create_rootfs( }; let boot_uuid = if let Some(bootdev) = bootdev { Some( - mkfs(bootdev.node.as_str(), root_filesystem, "boot", []) - .context("Initializing /boot")?, + mkfs( + bootdev.node.as_str(), + root_filesystem, + "boot", + opts.wipe, + [], + ) + .context("Initializing /boot")?, ) } else { None }; // Initialize rootfs - let root_uuid = mkfs(&rootdev, root_filesystem, "root", [])?; + let root_uuid = mkfs(&rootdev, root_filesystem, "root", opts.wipe, [])?; let rootarg = format!("root=UUID={root_uuid}"); let bootsrc = boot_uuid.as_ref().map(|uuid| format!("UUID={uuid}")); let bootarg = bootsrc.as_deref().map(|bootsrc| format!("boot={bootsrc}"));