Skip to content

Commit

Permalink
feat: create init file
Browse files Browse the repository at this point in the history
Signed-off-by: BioTheWolff <[email protected]>
  • Loading branch information
BioTheWolff committed Apr 22, 2024
1 parent b4ab148 commit 0a6c6a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/fs-gen/src/initramfs_generator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::fs::{File, Permissions};
use std::os::unix::fs::PermissionsExt;
use std::io::Write;
use std::path::Path;

const INIT_FILE: &[u8;220] = b"#! /bin/sh
#
# /init executable file in the initramfs
#
mount -t devtmpfs dev /dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys
ip link set up dev lo
exec /sbin/getty -n -l /bin/sh 115200 /dev/console
poweroff -f
";

pub fn create_init_file(path: &Path) {
let file_path = path.join("init");
let mut file = File::create(file_path).unwrap();

file.write_all(INIT_FILE).expect("Could not write init file");
file.set_permissions(Permissions::from_mode(0o755)).unwrap();
}
3 changes: 3 additions & 0 deletions src/fs-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::{fs, path::{Path, PathBuf}, str::FromStr};

use image_builder::merge_layer;
use crate::initramfs_generator::create_init_file;

mod cli_args;
mod image_builder;
mod image_loader;
mod initramfs_generator;

fn main() {
let args = cli_args::CliArgs::get_args();
Expand All @@ -26,6 +28,7 @@ fn main() {
println!(" - {}", path.display());
}
merge_layer(&layers_paths, Path::new("/tmp/cloudlet"));
create_init_file(Path::new("/tmp/cloudlet"));
}
}
}

0 comments on commit 0a6c6a5

Please sign in to comment.