Skip to content

Commit

Permalink
feat(fs-gen, vmm): disable compression (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias-Boulay <[email protected]>
  • Loading branch information
Mathias-Boulay authored May 30, 2024
1 parent 025a997 commit 9ab2b92
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/fs-gen/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ pub struct CliArgs {
/// Allow invalid TLS certificates
#[arg(long="insecure", action=ArgAction::SetTrue)]
pub insecure: bool,

/// Disable the compression of the final image
#[arg(short, long, action=ArgAction::SetTrue)]
pub no_compression: bool,
}

impl CliArgs {
Expand Down
15 changes: 13 additions & 2 deletions src/fs-gen/src/initramfs_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,30 @@ pub fn insert_agent(destination: &Path, agent_path: PathBuf) -> Result<()> {
Ok(())
}

pub fn generate_initramfs(root_directory: &Path, output: &Path) -> Result<()> {
pub fn generate_initramfs(
root_directory: &Path,
output: &Path,
enable_compression: bool,
) -> Result<()> {
let file = File::create(output)
.with_context(|| "Could not open output file to write initramfs".to_string())?;
file.set_permissions(Permissions::from_mode(0o644))
.with_context(|| "Failed to set permissions for output file".to_string())?;

info!("Generating initramfs...");

let mut command_string: String =
"find . -print0 | cpio -0 --create --owner=root:root --format=newc".into();

if enable_compression {
command_string += " | xz -9 -T0 --format=lzma";
}

let mut command = Command::new("sh")
.current_dir(root_directory)
.stdout(Stdio::from(file))
.arg("-c")
.arg("find . -print0 | cpio -0 --create --owner=root:root --format=newc | xz -9 -T0 --format=lzma")
.arg(&command_string)
.spawn()
.with_context(|| "Failed to package initramfs into bundle".to_string())?;

Expand Down
6 changes: 5 additions & 1 deletion src/fs-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ fn run(args: CliArgs) -> Result<()> {
// building initramfs
create_init_file(output_subdir, args.initfile_path)?;
insert_agent(output_subdir, args.agent_host_path)?;
generate_initramfs(output_subdir, Path::new(args.output_file.as_path()))?;
generate_initramfs(
output_subdir,
Path::new(args.output_file.as_path()),
!args.no_compression,
)?;

// cleanup of temporary directory
remove_dir_all(args.temp_directory.clone())
Expand Down
2 changes: 1 addition & 1 deletion tools/rootfs/mkrootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ulimit -Sn 8192

if [ -d fs-gen ]
then
cargo run --bin fs-gen -- $1 $2 -o $3
cargo run --bin fs-gen -- $1 $2 -o $3 --no-compression
else
echo "Module fs-gen not found"
fi

0 comments on commit 9ab2b92

Please sign in to comment.