Skip to content

Commit

Permalink
ksud: shrink image before resize
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Jan 30, 2024
1 parent cce423a commit ca960a2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions userspace/ksud/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,24 @@ 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)
.context("Failed to open ext4 image")?
.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)
Expand Down

0 comments on commit ca960a2

Please sign in to comment.