mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-19 20:46:35 +00:00
Let OSDK allow specifying additional boot drive options
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
37e23a16a3
commit
74e4623e70
@ -219,17 +219,30 @@ 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(_)));
|
||||||
|
let bootdev_opts = action
|
||||||
|
.qemu
|
||||||
|
.bootdev_append_options
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or(",index=2,media=cdrom");
|
||||||
qemu_cmd.arg("-drive").arg(format!(
|
qemu_cmd.arg("-drive").arg(format!(
|
||||||
"file={},index=2,media=cdrom",
|
"file={},format=raw{}",
|
||||||
self.path.join(vm_image.path()).to_string_lossy()
|
self.path.join(vm_image.path()).to_string_lossy(),
|
||||||
|
bootdev_opts,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
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(_)));
|
||||||
|
// FIXME: this doesn't work for regular QEMU, but may work for TDX.
|
||||||
|
let bootdev_opts = action
|
||||||
|
.qemu
|
||||||
|
.bootdev_append_options
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or(",if=virtio");
|
||||||
qemu_cmd.arg("-drive").arg(format!(
|
qemu_cmd.arg("-drive").arg(format!(
|
||||||
"file={},index=0,media=disk,format=qcow2",
|
"file={},format=qcow2{}",
|
||||||
self.path.join(vm_image.path()).to_string_lossy()
|
self.path.join(vm_image.path()).to_string_lossy(),
|
||||||
|
bootdev_opts,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -309,6 +309,13 @@ pub struct CommonArgs {
|
|||||||
global = true
|
global = true
|
||||||
)]
|
)]
|
||||||
pub boot_method: Option<BootMethod>,
|
pub boot_method: Option<BootMethod>,
|
||||||
|
#[arg(
|
||||||
|
long = "bootdev-append-options",
|
||||||
|
help = "Additional QEMU `-drive` options for the boot device",
|
||||||
|
value_name = "OPTIONS",
|
||||||
|
global = true
|
||||||
|
)]
|
||||||
|
pub bootdev_append_options: Option<String>,
|
||||||
#[arg(
|
#[arg(
|
||||||
long = "display-grub-menu",
|
long = "display-grub-menu",
|
||||||
help = "Display the GRUB menu if booting with GRUB",
|
help = "Display the GRUB menu if booting with GRUB",
|
||||||
|
@ -72,6 +72,9 @@ fn apply_args_before_finalize(action_scheme: &mut ActionScheme, args: &CommonArg
|
|||||||
if let Some(path) = &args.qemu_exe {
|
if let Some(path) = &args.qemu_exe {
|
||||||
qemu.path = Some(path.clone());
|
qemu.path = Some(path.clone());
|
||||||
}
|
}
|
||||||
|
if let Some(bootdev_options) = &args.bootdev_append_options {
|
||||||
|
qemu.bootdev_append_options = Some(bootdev_options.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,20 @@ pub struct QemuScheme {
|
|||||||
/// The additional arguments for running QEMU, in the form of raw
|
/// The additional arguments for running QEMU, in the form of raw
|
||||||
/// command line arguments.
|
/// command line arguments.
|
||||||
pub args: Option<String>,
|
pub args: Option<String>,
|
||||||
|
/// The additional qemu argument after the `-drive` option for the
|
||||||
|
/// boot device, in the form of raw command line arguments, comma
|
||||||
|
/// included. For example, `",if=virtio,media=disk,index=2"`.
|
||||||
|
/// The `format` and the `file` options are not allowed to set.
|
||||||
|
///
|
||||||
|
/// This option only works with [`super::BootMethod::GrubQcow2`] and
|
||||||
|
/// [`super::BootMethod::GrubRescueIso`].
|
||||||
|
///
|
||||||
|
/// This option exist because different firmwares may need
|
||||||
|
/// different interface types for the boot drive.
|
||||||
|
///
|
||||||
|
/// See <https://www.qemu.org/docs/master/system/invocation.html>
|
||||||
|
/// for details about `-drive` option.
|
||||||
|
pub bootdev_append_options: Option<String>,
|
||||||
/// The path of qemu
|
/// The path of qemu
|
||||||
pub path: Option<PathBuf>,
|
pub path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
@ -23,6 +37,11 @@ pub struct QemuScheme {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Qemu {
|
pub struct Qemu {
|
||||||
pub args: String,
|
pub args: String,
|
||||||
|
/// This finalized config has a unorthodox `Option` because
|
||||||
|
/// we cannot provide a default value for it. The default
|
||||||
|
/// value is determined by the final running routine
|
||||||
|
/// [`crate::bundle::Bundle::run`].
|
||||||
|
pub bootdev_append_options: Option<String>,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +49,7 @@ impl Default for Qemu {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Qemu {
|
Qemu {
|
||||||
args: String::new(),
|
args: String::new(),
|
||||||
|
bootdev_append_options: None,
|
||||||
path: PathBuf::from(get_default_arch().system_qemu()),
|
path: PathBuf::from(get_default_arch().system_qemu()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,6 +83,7 @@ impl QemuScheme {
|
|||||||
pub fn finalize(self, arch: Arch) -> Qemu {
|
pub fn finalize(self, arch: Arch) -> Qemu {
|
||||||
Qemu {
|
Qemu {
|
||||||
args: self.args.unwrap_or_default(),
|
args: self.args.unwrap_or_default(),
|
||||||
|
bootdev_append_options: self.bootdev_append_options,
|
||||||
path: self.path.unwrap_or(PathBuf::from(arch.system_qemu())),
|
path: self.path.unwrap_or(PathBuf::from(arch.system_qemu())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user