mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 10:53:25 +00:00
Bring OSDK's full support of QCOW2 booting
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
c6aa9f9ee8
commit
37e23a16a3
@ -2,6 +2,7 @@
|
||||
|
||||
mod bin;
|
||||
mod grub;
|
||||
mod qcow2;
|
||||
|
||||
use std::{
|
||||
ffi::OsString,
|
||||
@ -159,7 +160,7 @@ pub fn do_build(
|
||||
);
|
||||
|
||||
match boot.method {
|
||||
BootMethod::GrubRescueIso => {
|
||||
BootMethod::GrubRescueIso | BootMethod::GrubQcow2 => {
|
||||
info!("Building boot device image");
|
||||
let bootdev_image = grub::create_bootdev_image(
|
||||
&osdk_output_directory,
|
||||
@ -168,16 +169,18 @@ pub fn do_build(
|
||||
config,
|
||||
action,
|
||||
);
|
||||
bundle.consume_vm_image(bootdev_image);
|
||||
if matches!(boot.method, BootMethod::GrubQcow2) {
|
||||
let qcow2_image = qcow2::convert_iso_to_qcow2(bootdev_image);
|
||||
bundle.consume_vm_image(qcow2_image);
|
||||
} else {
|
||||
bundle.consume_vm_image(bootdev_image);
|
||||
}
|
||||
bundle.consume_aster_bin(aster_elf);
|
||||
}
|
||||
BootMethod::QemuDirect => {
|
||||
let qemu_elf = make_elf_for_qemu(&osdk_output_directory, &aster_elf, build.strip_elf);
|
||||
bundle.consume_aster_bin(qemu_elf);
|
||||
}
|
||||
BootMethod::GrubQcow2 => {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
bundle
|
||||
|
40
osdk/src/commands/build/qcow2.rs
Normal file
40
osdk/src/commands/build/qcow2.rs
Normal file
@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use std::process;
|
||||
|
||||
use crate::{
|
||||
bundle::{
|
||||
file::BundleFile,
|
||||
vm_image::{AsterQcow2ImageMeta, AsterVmImage, AsterVmImageType},
|
||||
},
|
||||
error_msg,
|
||||
};
|
||||
|
||||
pub fn convert_iso_to_qcow2(iso: AsterVmImage) -> AsterVmImage {
|
||||
let AsterVmImageType::GrubIso(meta) = iso.typ() else {
|
||||
panic!("Expected a GRUB ISO image, but got: {:?}", iso.typ());
|
||||
};
|
||||
let iso_path = iso.path();
|
||||
let qcow2_path = iso_path.with_extension("qcow2");
|
||||
// Convert the ISO to QCOW2 using `qemu-img`.
|
||||
let mut qemu_img = process::Command::new("qemu-img");
|
||||
qemu_img.args([
|
||||
"convert",
|
||||
"-O",
|
||||
"qcow2",
|
||||
iso_path.to_str().unwrap(),
|
||||
qcow2_path.to_str().unwrap(),
|
||||
]);
|
||||
info!("Converting the ISO to QCOW2 using {:#?}", qemu_img);
|
||||
if !qemu_img.status().unwrap().success() {
|
||||
error_msg!("Failed to convert the ISO to QCOW2: {:?}", qemu_img);
|
||||
process::exit(1);
|
||||
}
|
||||
AsterVmImage::new(
|
||||
qcow2_path,
|
||||
AsterVmImageType::Qcow2(AsterQcow2ImageMeta {
|
||||
grub_version: meta.grub_version.clone(),
|
||||
}),
|
||||
iso.aster_version().clone(),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user