diff --git a/src/vmm/src/service.rs b/src/vmm/src/service.rs index bd1dfac..c6c3126 100644 --- a/src/vmm/src/service.rs +++ b/src/vmm/src/service.rs @@ -5,6 +5,7 @@ use crate::core::vmm::VMM; use crate::VmmErrors; use std::{ convert::From, + env::current_dir, net::Ipv4Addr, path::{Path, PathBuf}, process::{Command, Stdio}, @@ -42,9 +43,16 @@ impl VmmServiceTrait for VmmService { const HOST_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 1); const HOST_NETMASK: Ipv4Addr = Ipv4Addr::new(255, 255, 0, 0); + // get current directory + let mut curr_dir = current_dir()?; + + // define kernel path + let mut kernel_entire_path = curr_dir.as_os_str().to_owned(); + kernel_entire_path.push("/tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin"); + // Check if the kernel is on the system, else build it - if !Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin") - .exists() + let kernel_exists = Path::new(&kernel_entire_path).try_exists().expect(&format!("Could not access folder {:?}", &kernel_entire_path)); + if !kernel_exists { info!("Kernel not found, building kernel"); // Execute the script using sh and capture output and error streams @@ -56,19 +64,35 @@ impl VmmServiceTrait for VmmService { .expect("Failed to execute the kernel build script"); // Print output and error streams - error!("Script output: {}", String::from_utf8_lossy(&output.stdout)); + info!("Script output: {}", String::from_utf8_lossy(&output.stdout)); error!("Script errors: {}", String::from_utf8_lossy(&output.stderr)); }; + let kernel_path = Path::new(&kernel_entire_path); + + // define initramfs file placement + let initramfs_entire_file_path = curr_dir.as_mut_os_string(); + initramfs_entire_file_path.push("/tools/rootfs/initramfs.img"); + + // Check if the initramfs is on the system, else build it + let initramfs_exists = Path::new(&initramfs_entire_file_path).try_exists().expect(&format!("Could not access folder {:?}", &initramfs_entire_file_path)); + if !initramfs_exists + { + info!("Initramfs not found, building initramfs"); + // Execute the script using sh and capture output and error streams + let output = Command::new("sh") + .arg("./tools/rootfs/mkrootfs.sh") + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("Failed to execute the initramfs build script"); - let kernel_path = &Path::new( - "./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin", - ); - let mut initramfs_path: PathBuf = PathBuf::new(); - - // Todo - Check if the initramfs for the specified language is on the system, else build it - initramfs_path.push("./tools/rootfs/initramfs.img"); + // Print output and error streams + info!("Script output: {}", String::from_utf8_lossy(&output.stdout)); + error!("Script errors: {}", String::from_utf8_lossy(&output.stderr)); + }; + let initramfs_path = PathBuf::from(&initramfs_entire_file_path); - // // Create a new VMM + // Create a new VMM let mut vmm = VMM::new(HOST_IP, HOST_NETMASK).map_err(VmmErrors::VmmNew)?; // Configure the VMM parameters might need to be calculated rather than hardcoded diff --git a/tools/kernel/linux-config-x86_64 b/tools/kernel/linux-config-x86_64 index 22a815f..dc37c75 100644 --- a/tools/kernel/linux-config-x86_64 +++ b/tools/kernel/linux-config-x86_64 @@ -1475,6 +1475,8 @@ CONFIG_VIRTIO_NET=y # CONFIG_PPP is not set CONFIG_SLIP=y CONFIG_SLIP_COMPRESSED=y +CONFIG_SLIP_SMART=n +CONFIG_SLIP_MODE_SLIP6=n # # Host-side USB support is needed for USB Network Adapter support diff --git a/tools/kernel/mkkernel.sh b/tools/kernel/mkkernel.sh index ef85deb..9046a3f 100755 --- a/tools/kernel/mkkernel.sh +++ b/tools/kernel/mkkernel.sh @@ -1,13 +1,13 @@ #!/usr/bin/bash LINUX_REPO=linux-cloud-hypervisor +cd ./tools/kernel/ if [ ! -d $LINUX_REPO ] then git clone --depth 1 "https://github.com/cloud-hypervisor/linux.git" -b "ch-6.2" $LINUX_REPO fi -pushd $LINUX_REPO +cd $LINUX_REPO cp ../linux-config-x86_64 .config KCFLAGS="-Wa,-mx86-used-note=no" make bzImage -j `nproc` -popd diff --git a/tools/rootfs/mkrootfs.sh b/tools/rootfs/mkrootfs.sh index 5c63ccb..10929ac 100755 --- a/tools/rootfs/mkrootfs.sh +++ b/tools/rootfs/mkrootfs.sh @@ -1,41 +1,14 @@ #!/usr/bin/bash - -if [ ! -d alpine-minirootfs ] +# test if its already in src folder => fs-gen available +# launch from src folder at the same level as tools +if [ -d src ] then - curl -O https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-minirootfs-3.14.2-x86_64.tar.gz - - mkdir alpine-minirootfs - tar xf alpine-minirootfs-3.14.2-x86_64.tar.gz -C alpine-minirootfs + cd src fi -pushd alpine-minirootfs -cat > init < /dev/null; do - sleep 1 -done - -ifconfig sl0 172.30.0.11 netmask 255.255.0.0 up - -exec /sbin/getty -n -l /bin/sh 115200 /dev/console -poweroff -f -EOF - -chmod +x init - -find . -print0 | - cpio --null --create --verbose --owner root:root --format=newc | - xz -9 --format=lzma > ../initramfs.img - -popd +if [ -d fs-gen ] +then + cargo run --bin fs-gen -- alpine:latest ./fs-gen/test -o ../tools/rootfs/initramfs.img +else + echo "Module fs-gen not found" +fi \ No newline at end of file