From ca960a2a8f0c7ad435e55d474202267e3a1b6c10 Mon Sep 17 00:00:00 2001 From: weishu Date: Tue, 30 Jan 2024 12:56:42 +0800 Subject: [PATCH] ksud: shrink image before resize --- userspace/ksud/src/module.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/userspace/ksud/src/module.rs b/userspace/ksud/src/module.rs index baae5943..e3c45b43 100644 --- a/userspace/ksud/src/module.rs +++ b/userspace/ksud/src/module.rs @@ -387,6 +387,16 @@ fn _install_module(zip: &str) -> Result<()> { // legacy image, truncate it to new size. if std::fs::metadata(modules_img)?.len() < sparse_image_size { println!("- Truncate legacy image to new size"); + + // shrink it to minimum size + check_image(tmp_module_img)?; + Command::new("resize2fs") + .arg("-M") + .arg(tmp_module_img) + .stdout(Stdio::piped()) + .status()?; + + // truncate the file to new size OpenOptions::new() .write(true) .open(tmp_module_img) @@ -394,6 +404,7 @@ fn _install_module(zip: &str) -> Result<()> { .set_len(sparse_image_size) .context("Failed to truncate ext4 image")?; + // resize the image to new size check_image(tmp_module_img)?; Command::new("resize2fs") .arg(tmp_module_img)