Skip to content

Commit 0397268

Browse files
committed
[WIP] Document and tweaks vmrt (qemu) CLI args
The goal of this PR is to let qemu load root filsystem of the guest as a virtiofs drive (and then successfully boot from it). The provided initramfs file should be tweaked to achieve that!
1 parent 29113b2 commit 0397268

File tree

4 files changed

+34
-40
lines changed

4 files changed

+34
-40
lines changed

runtime/examples/direct.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn spawn_vm<'a, P: AsRef<Path>>(temp_path: P, mount_args: &'a [(&'a str, impl To
9797
let project_dir = get_project_dir();
9898
let init_dir = project_dir.join("init-container");
9999

100+
// QUESTION: I guess this is an outdated example and should be renamed to `vmrt` right?
100101
let mut cmd = Command::new("qemu-system-x86_64");
101102
cmd.current_dir(&init_dir).args([
102103
"-m",

runtime/examples/network.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ fn spawn_vm<P: AsRef<Path>>(temp_path: P) -> Child {
130130
let chardev =
131131
|name, path: &PathBuf| format!("socket,path={},server,nowait,id={}", path.display(), name);
132132

133+
// QUESTION: why not rather use `vmrt::start_vmrt` here?`
133134
let mut cmd = Command::new("vmrt");
134135
cmd.current_dir(runtime_dir).args([
135136
"-m",

runtime/poc/gvmkit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ do_run() {
9898
append="$append apparg=\"$a\""
9999
done
100100
echo $@
101+
# QUESTION: is the plan to rewrite this PoC in Rust?
101102
./vmrt -m "$memory" -nographic -vga none -kernel vmlinuz-virt -initrd initramfs-virt -net none -accel kvm -cpu "host" -smp $(nproc) \
102103
-device virtio-serial,id=ser0 -device virtserialport,chardev=foo,name=org.fedoraproject.port.0 -chardev socket,path=/tmp/foo,server,nowait,id=foo \
103104
-append "console=ttyS0 panic=1 $append" \

runtime/src/vmrt.rs

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ impl RuntimeData {
5454
}
5555
}
5656

57+
/// Starts the VM runtime (vmrt), which is a specialized build of QEMU.
58+
///
59+
/// It sets up communication with the VM through a guest agent and emits runtime events
60+
/// using the provided `EventEmitter`.
5761
pub async fn start_vmrt(
5862
work_dir: PathBuf,
5963
runtime_data: Arc<Mutex<RuntimeData>>,
@@ -81,28 +85,20 @@ pub async fn start_vmrt(
8185
"socket,path={},server=on,wait=off,id=manager_cdev",
8286
manager_sock.display()
8387
);
88+
// TODO: I got that what I've to do is just tweak those args :)
8489
let mut args = vec![
85-
"-nographic",
86-
"-no-reboot",
87-
"-m",
88-
memory_size.as_str(),
89-
"-kernel",
90-
FILE_VMLINUZ,
91-
"-initrd",
92-
FILE_INITRAMFS,
93-
"-enable-kvm",
94-
"-cpu",
95-
"host,-sgx",
96-
"-smp",
97-
cpu_cores.as_str(),
98-
"-device",
99-
"virtio-serial",
100-
"-device",
101-
"virtio-rng-pci",
102-
"-chardev",
103-
manager_sock_path.as_str(),
104-
"-device",
105-
"virtserialport,chardev=manager_cdev,name=manager_port",
90+
"-nographic", // Disable graphical output; run in headless mode.
91+
"-no-reboot", // Prevent the VM from rebooting automatically on failure.
92+
"-m", memory_size.as_str(), // Set the memory size for the VM (e.g., "512M").
93+
"-kernel", FILE_VMLINUZ, // Specify the kernel image to boot.
94+
"-initrd", FILE_INITRAMFS, // Specify the initial RAM disk image.
95+
"-enable-kvm", // Enable KVM (Kernel-based Virtual Machine) for hardware acceleration.
96+
"-cpu", "host,-sgx", // Use the host CPU model but disable Intel SGX (Software Guard Extensions).
97+
"-smp", cpu_cores.as_str(), // Set the number of CPU cores for the VM.
98+
"-device", "virtio-serial", // Add a virtio-serial device for communication between host and guest.
99+
"-device", "virtio-rng-pci", // Add a virtio RNG (random number generator) device for entropy.
100+
"-chardev", manager_sock_path.as_str(), // Define a character device for communication via a Unix socket.
101+
"-device", "virtserialport,chardev=manager_cdev,name=manager_port", // Attach a virtio-serial port to the character device.
106102
];
107103

108104
let rootfs_devices: Vec<(String, String)> = deployment
@@ -114,17 +110,15 @@ pub async fn start_vmrt(
114110
"file={},cache=unsafe,readonly=on,format=raw,id=rootfs-{},if=none",
115111
path.display(),
116112
i
117-
);
118-
let device = format!("virtio-blk-pci,drive=rootfs-{},serial=rootfs-{}", i, i);
113+
); // Define a read-only raw disk image for the root filesystem.
114+
let device = format!("virtio-blk-pci,drive=rootfs-{},serial=rootfs-{}", i, i); // Attach the disk image as a virtio block device.
119115
(drive, device)
120116
})
121117
.collect();
122118

123119
for (drive, device) in rootfs_devices.iter() {
124-
args.push("-drive");
125-
args.push(drive);
126-
args.push("-device");
127-
args.push(device);
120+
args.append(["-drive", drive]); // Add the disk image as a drive.
121+
args.append(["-device", device]); // Attach the drive as a virtio block device.
128122
}
129123

130124
cmd.args(args);
@@ -152,9 +146,9 @@ pub async fn start_vmrt(
152146
"file={},format=qcow2,media=disk,id=vol-{vol_idx},if=none",
153147
img_path.display()
154148
)
155-
.as_str(),
149+
.as_str(), // Add a QCOW2 disk image for storage.
156150
"-device",
157-
format!("virtio-blk-pci,drive=vol-{vol_idx},serial=vol-{vol_idx}").as_ref(),
151+
format!("virtio-blk-pci,drive=vol-{vol_idx},serial=vol-{vol_idx}").as_ref(), // Attach the storage as a virtio block device.
158152
]);
159153
kernel_cmdline.push_str(&format!(" vol-{vol_idx}-path={guest_path}"));
160154
kernel_cmdline.push_str(&format!(" vol-{vol_idx}-errors={errors}"));
@@ -169,12 +163,10 @@ pub async fn start_vmrt(
169163

170164
if let Some(pci_device_id) = &data.pci_device_id {
171165
for device_id in pci_device_id.iter() {
172-
cmd.arg("-device");
173-
cmd.arg(format!("vfio-pci,host={}", device_id).as_str());
166+
cmd.args(["-device", format!("vfio-pci,host={}", device_id).as_str()]); // Pass through a PCI device to the VM.
174167
}
175168
} else {
176-
cmd.arg("-vga");
177-
cmd.arg("none");
169+
cmd.args(["-vga", "none"]); // Disable VGA output.
178170
}
179171

180172
if runtime_dir.join(FILE_NVIDIA_FILES).exists() {
@@ -184,17 +176,17 @@ pub async fn start_vmrt(
184176
"file={},cache=unsafe,readonly=on,format=raw,id=nvidia-files,if=none",
185177
runtime_dir.join(FILE_NVIDIA_FILES).display()
186178
)
187-
.as_str(),
179+
.as_str(), // Add a read-only disk image for NVIDIA files.
188180
"-device",
189181
"virtio-blk-pci,drive=nvidia-files,serial=nvidia-files"
190182
.to_string()
191-
.as_ref(),
183+
.as_ref(), // Attach the NVIDIA files as a virtio block device.
192184
]);
193185
}
194186

195-
kernel_cmdline.push_str(&format!(" hostname={}", deployment.hostname));
187+
kernel_cmdline.push_str(&format!(" hostname={}", deployment.hostname)); // Set the hostname for the VM.
196188

197-
cmd.args(["-append", &kernel_cmdline]);
189+
cmd.args(["-append", &kernel_cmdline]); // Pass the kernel command-line arguments.
198190

199191
if vpn_remote.is_some() || inet_remote.is_some() {
200192
let mut pair = SocketPairConf::default();
@@ -213,12 +205,11 @@ pub async fn start_vmrt(
213205
}
214206

215207
for (idx, volume) in volumes.iter().enumerate() {
216-
cmd.arg("-virtfs");
217-
cmd.arg(format!(
208+
cmd.args(["-virtfs", &format!(
218209
"local,id={tag},path={path},security_model=none,mount_tag={tag}",
219210
tag = format!("mnt{}", idx),
220211
path = work_dir.join(&volume.name).to_string_lossy(),
221-
));
212+
)]); // Add a VirtFS (9p) shared folder for the volume.
222213
}
223214

224215
log::info!("Executing command: {cmd:?}");

0 commit comments

Comments
 (0)