ksud: shrink image before resize

This commit is contained in:
weishu
2024-01-30 12:56:42 +08:00
parent cce423a2f6
commit ca960a2a8f

View File

@@ -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)