feat: use uncompressed initramfs

This commit is contained in:
2026-06-17 16:35:28 +02:00
parent 503578d648
commit 09661ec9e0
+10 -36
View File
@@ -160,56 +160,30 @@ fn get_arch_package_suffix(arch: &str) -> &str {
} }
} }
/// Create a gzipped cpio initramfs from a directory /// Create an uncompressed cpio initramfs from a directory
fn create_initramfs(rootfs: &PathBuf) -> Result<PathBuf> { fn create_initramfs(rootfs: &PathBuf) -> Result<PathBuf> {
// Create a temporary file for the initramfs // Create a temporary file for the initramfs (uncompressed cpio)
let initramfs_path = rootfs.parent().unwrap().join("initramfs.cpio.gz"); let initramfs_path = rootfs.parent().unwrap().join("initramfs.cpio");
// Create progress bar // Create progress bar
let pb = ProgressBar::new_spinner(); let pb = ProgressBar::new_spinner();
pb.set_style(ProgressStyle::default_spinner() pb.set_style(ProgressStyle::default_spinner()
.template("{spinner:.green} {msg} ({pos} files)") .template("{spinner:.green} {msg} ({pos} files)")
.unwrap()); .unwrap());
pb.set_message("Scanning rootfs..."); pb.set_message("Creating initramfs...");
// Create the cpio archive with progress // Create the cpio archive with progress
let cpio_data = create_cpio_archive(rootfs, &pb)?; let cpio_data = create_cpio_archive(rootfs, &pb)?;
let total_bytes = cpio_data.len() as u64; let total_bytes = cpio_data.len() as u64;
let file_count = pb.position(); let file_count = pb.position();
// Finish the scanning progress bar // Write directly to file (no compression)
std::fs::write(&initramfs_path, &cpio_data)
.context("Failed to write initramfs file")?;
// Finish progress bar
pb.finish_and_clear(); pb.finish_and_clear();
veprintln!("Initramfs created: {} bytes, {} files", total_bytes, file_count);
// Create progress bar for compression
let compress_pb = ProgressBar::new(total_bytes);
compress_pb.set_style(ProgressStyle::default_bar()
.template("{spinner:.green} Compressing initramfs... {bytes}/{total_bytes} ({eta})")
.unwrap()
.progress_chars("##-"));
// Compress with gzip, writing in chunks to update progress
let mut output_file = std::fs::File::create(&initramfs_path)
.context("Failed to create initramfs file")?;
let mut encoder = flate2::write::GzEncoder::new(&mut output_file, flate2::Compression::fast());
// Write in 64KB chunks to provide progress updates
const CHUNK_SIZE: usize = 64 * 1024;
let mut offset = 0;
while offset < cpio_data.len() {
let end = std::cmp::min(offset + CHUNK_SIZE, cpio_data.len());
encoder.write_all(&cpio_data[offset..end])
.context("Failed to write compressed initramfs")?;
offset = end;
compress_pb.set_position(offset as u64);
}
encoder.finish()
.context("Failed to finalize gzip compression")?;
// Clear progress bar and print message only in verbose mode
compress_pb.finish_and_clear();
veprintln!("Initramfs created: {} bytes -> {} bytes compressed, {} files",
total_bytes, output_file.metadata().ok().map(|m| m.len()).unwrap_or(0), file_count);
Ok(initramfs_path) Ok(initramfs_path)
} }