pub fn prepare_initrd_image(&self) -> Result<File> {
        let mut initrd = File::open(&self.initrd_path.0)
            .with_context(|| format!("while opening initrd {}", self.initrd_path.0.display()))?;

        let mut modules = File::open(&self.disk_boot_modules_path.0).with_context(|| {
            format!(
                "while opening kernel modules {}",
                self.disk_boot_modules_path.0.display()
            )
        })?;

        // Create a temporary FD for the new initrd + modules
        let memfd = nix::sys::memfd::memfd_create(
            &CString::new("kexec_initrd_plus_modules")
                .expect("creating cstr can never fail with this static input"),
            nix::sys::memfd::MemFdCreateFlag::empty(),
        )
        .context("Failed to create memfd")?;

        let mut dest = unsafe {
            use std::os::unix::io::FromRawFd;
            File::from_raw_fd(memfd)
        };

        // Copy over the initrd + modules
        std::io::copy(&mut initrd, &mut dest)
            .context("failed to write initrd to temporary file")?;
        std::io::copy(&mut modules, &mut dest)
            .context("failed to write modules to temporary file")?;

        // Prepare the output file for our caller
        dest.rewind()
            .context("Failed to seek back to start of combined initrd file")?;

        Ok(dest)
    }
/// Prepare the joined initrd + modules image on disk and return the path to it
Prepare the joined initrd + modules image on disk and return the path to it
Prepare the joined initrd + modules image on disk and return the path to it
pub fn prepare_initrd_image(&self) -> Result<File> {
        let mut initrd = File::open(&self.initrd_path.0)
            .with_context(|| format!("while opening initrd {}", self.initrd_path.0.display()))?;
        let mut modules = File::open(&self.disk_boot_modules_path.0).with_context(|| {
            format!(
                "while opening kernel modules {}",
                self.disk_boot_modules_path.0.display()
            )
        })?;
        // Create a temporary FD for the new initrd + modules
        let memfd = nix::sys::memfd::memfd_create(
            &CString::new("kexec_initrd_plus_modules")
                .expect("creating cstr can never fail with this static input"),
            nix::sys::memfd::MemFdCreateFlag::empty(),
        )
        .context("Failed to create memfd")?;
        let mut dest = unsafe {
            use std::os::unix::io::FromRawFd;
            File::from_raw_fd(memfd)
        };
        // Copy over the initrd + modules
        std::io::copy(&mut initrd, &mut dest)
            .context("failed to write initrd to temporary file")?;
        std::io::copy(&mut modules, &mut dest)
            .context("failed to write modules to temporary file")?;
        // Prepare the output file for our caller
        dest.rewind()
            .context("Failed to seek back to start of combined initrd file")?;
        Ok(dest)
    }
pub fn prepare_initrd_image ( & self ) -> Result < File > { let mut initrd = File :: open ( & self . initrd_path . 0 ) . with_context ( | | format ! ( " " self initrd_path 0 display ( ) ) ) ? ; let mut modules = File :: open ( & self . disk_boot_modules_path . 0 ) . with_context ( | | { format ! ( " " self disk_boot_modules_path 0 display ( ) ) } ) ? ; // Create a temporary FD for the new initrd + modules let memfd = nix :: sys :: memfd :: memfd_create ( & CString :: new ( " " ) . expect ( " " ) , nix :: sys :: memfd :: MemFdCreateFlag :: empty ( ) , ) . context ( " " ) ? ; let mut dest = unsafe { use std :: os :: unix :: io :: FromRawFd ; File :: from_raw_fd ( memfd ) } ; // Copy over the initrd + modules std :: io :: copy ( & mut initrd , & mut dest ) . context ( " " ) ? ; std :: io :: copy ( & mut modules , & mut dest ) . context ( " " ) ? ; // Prepare the output file for our caller dest . rewind ( ) . context ( " " ) ? ; Ok ( dest ) }
Prepare the joined initrd + modules image on disk and return the path to it
Prepare the joined initrd + modules image on disk and return the path to it
&self
&self