mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 03:13:23 +00:00
Bring OSDK's full support of QCOW2 booting
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
c6aa9f9ee8
commit
37e23a16a3
@ -200,18 +200,9 @@ impl Bundle {
|
|||||||
ActionChoice::Test => &config.test,
|
ActionChoice::Test => &config.test,
|
||||||
};
|
};
|
||||||
let mut qemu_cmd = Command::new(&action.qemu.path);
|
let mut qemu_cmd = Command::new(&action.qemu.path);
|
||||||
|
|
||||||
qemu_cmd.current_dir(&config.work_dir);
|
qemu_cmd.current_dir(&config.work_dir);
|
||||||
match shlex::split(&action.qemu.args) {
|
|
||||||
Some(v) => {
|
|
||||||
for arg in v {
|
|
||||||
qemu_cmd.arg(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
error_msg!("Failed to parse qemu args: {:#?}", &action.qemu.args);
|
|
||||||
process::exit(Errno::ParseMetadata as _);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match action.boot.method {
|
match action.boot.method {
|
||||||
BootMethod::QemuDirect => {
|
BootMethod::QemuDirect => {
|
||||||
let aster_bin = self.manifest.aster_bin.as_ref().unwrap();
|
let aster_bin = self.manifest.aster_bin.as_ref().unwrap();
|
||||||
@ -228,22 +219,33 @@ impl Bundle {
|
|||||||
BootMethod::GrubRescueIso => {
|
BootMethod::GrubRescueIso => {
|
||||||
let vm_image = self.manifest.vm_image.as_ref().unwrap();
|
let vm_image = self.manifest.vm_image.as_ref().unwrap();
|
||||||
assert!(matches!(vm_image.typ(), AsterVmImageType::GrubIso(_)));
|
assert!(matches!(vm_image.typ(), AsterVmImageType::GrubIso(_)));
|
||||||
qemu_cmd.arg("-cdrom").arg(self.path.join(vm_image.path()));
|
qemu_cmd.arg("-drive").arg(format!(
|
||||||
|
"file={},index=2,media=cdrom",
|
||||||
|
self.path.join(vm_image.path()).to_string_lossy()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
BootMethod::GrubQcow2 => {
|
BootMethod::GrubQcow2 => {
|
||||||
let vm_image = self.manifest.vm_image.as_ref().unwrap();
|
let vm_image = self.manifest.vm_image.as_ref().unwrap();
|
||||||
assert!(matches!(vm_image.typ(), AsterVmImageType::Qcow2(_)));
|
assert!(matches!(vm_image.typ(), AsterVmImageType::Qcow2(_)));
|
||||||
qemu_cmd.arg("-drive").arg(format!(
|
qemu_cmd.arg("-drive").arg(format!(
|
||||||
"file={},index=0,media=disk,format=qcow2",
|
"file={},index=0,media=disk,format=qcow2",
|
||||||
self.path
|
self.path.join(vm_image.path()).to_string_lossy()
|
||||||
.join(vm_image.path())
|
|
||||||
.into_os_string()
|
|
||||||
.into_string()
|
|
||||||
.unwrap()
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
match shlex::split(&action.qemu.args) {
|
||||||
|
Some(v) => {
|
||||||
|
for arg in v {
|
||||||
|
qemu_cmd.arg(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
error_msg!("Failed to parse qemu args: {:#?}", &action.qemu.args);
|
||||||
|
process::exit(Errno::ParseMetadata as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
info!("Running QEMU: {:#?}", qemu_cmd);
|
info!("Running QEMU: {:#?}", qemu_cmd);
|
||||||
|
|
||||||
let exit_status = qemu_cmd.status().unwrap();
|
let exit_status = qemu_cmd.status().unwrap();
|
||||||
|
@ -72,4 +72,8 @@ impl AsterVmImage {
|
|||||||
sha256sum: self.sha256sum,
|
sha256sum: self.sha256sum,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn aster_version(&self) -> &String {
|
||||||
|
&self.aster_version
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
mod bin;
|
mod bin;
|
||||||
mod grub;
|
mod grub;
|
||||||
|
mod qcow2;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
@ -159,7 +160,7 @@ pub fn do_build(
|
|||||||
);
|
);
|
||||||
|
|
||||||
match boot.method {
|
match boot.method {
|
||||||
BootMethod::GrubRescueIso => {
|
BootMethod::GrubRescueIso | BootMethod::GrubQcow2 => {
|
||||||
info!("Building boot device image");
|
info!("Building boot device image");
|
||||||
let bootdev_image = grub::create_bootdev_image(
|
let bootdev_image = grub::create_bootdev_image(
|
||||||
&osdk_output_directory,
|
&osdk_output_directory,
|
||||||
@ -168,16 +169,18 @@ pub fn do_build(
|
|||||||
config,
|
config,
|
||||||
action,
|
action,
|
||||||
);
|
);
|
||||||
|
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_vm_image(bootdev_image);
|
||||||
|
}
|
||||||
bundle.consume_aster_bin(aster_elf);
|
bundle.consume_aster_bin(aster_elf);
|
||||||
}
|
}
|
||||||
BootMethod::QemuDirect => {
|
BootMethod::QemuDirect => {
|
||||||
let qemu_elf = make_elf_for_qemu(&osdk_output_directory, &aster_elf, build.strip_elf);
|
let qemu_elf = make_elf_for_qemu(&osdk_output_directory, &aster_elf, build.strip_elf);
|
||||||
bundle.consume_aster_bin(qemu_elf);
|
bundle.consume_aster_bin(qemu_elf);
|
||||||
}
|
}
|
||||||
BootMethod::GrubQcow2 => {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle
|
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