diff --git a/src/fs-gen/src/initramfs_generator.rs b/src/fs-gen/src/initramfs_generator.rs new file mode 100644 index 0000000..d9cfd26 --- /dev/null +++ b/src/fs-gen/src/initramfs_generator.rs @@ -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(); +} diff --git a/src/fs-gen/src/main.rs b/src/fs-gen/src/main.rs index 91faa78..2b05e67 100644 --- a/src/fs-gen/src/main.rs +++ b/src/fs-gen/src/main.rs @@ -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(); @@ -26,6 +28,7 @@ fn main() { println!(" - {}", path.display()); } merge_layer(&layers_paths, Path::new("/tmp/cloudlet")); + create_init_file(Path::new("/tmp/cloudlet")); } } }