QEMU Options
config_groups, QemuOptsList, QemuOpts, QemuOpt?
QEMU 里面有四个层级:
// config groups
static QemuOptsList *vm_config_groups[48];
static QemuOptsList *drive_config_groups[5];
// QemuOptsList (-device virtio-serial -device virtconsole,chardev=virtiocon0)
struct QemuOptsList {
const char *name;
//...
QTAILQ_HEAD(, QemuOpts) head;
};
// QemuOpts (-drive file=/dev/cdrom,media=cdrom)
struct QemuOpts {
char *id;
QemuOptsList *list;
Location loc;
QTAILQ_HEAD(, QemuOpt) head;
//...
};
// QemuOpt (file=/dev/cdrom)
struct QemuOpt {
char *name;
char *str;
union {
bool boolean;
uint64_t uint;
} value;
QemuOpts *opts;
//...
};
-accel
Each accelerator in QEMU is an AccelClass
.
static const TypeInfo kvm_accel_type = {
.name = TYPE_KVM_ACCEL,
.parent = TYPE_ACCEL,
.instance_init = kvm_accel_instance_init,
.class_init = kvm_accel_class_init,
.instance_size = sizeof(KVMState),
};
When will this been called?
void qemu_init(int argc, char **argv)
{
//...
configure_accelerators(argv[0]);
//...
}
static void configure_accelerators(const char *progname)
{
// ...
if (!qemu_opts_foreach(qemu_find_opts("accel"),
do_configure_accelerator, &init_failed, &error_fatal)) {
// ...
}
static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
{
// ...
ret = accel_init_machine(accel, current_machine);
// ...
}
static void kvm_accel_class_init(ObjectClass *oc, void *data)
{
// ...
ac->init_machine = kvm_init;
// ...
}
-object
-kernel
Why QEMU can specify the kernel for an image, isn't the kernel located in the image?
Search "root file system" in my blog.
and, when specifying the -kernel
option, we should also specify the root file system for the kernel to mount, so
- First, we should append a drive device by
-drive
or-hda
; - Second, we should specify which partition the root file system is located on, so we should use
-append "root=/dev/vda1"
.
linux - How to use custom image kernel for ubuntu in qemu? - Stack Overflow
QEMU can also specify -initrd
, what does that mean?
-display none vs. -nographic
-display none
- Do not display video output. This option is different than the -nographic
option. See the man page for more information.
-display none
is preferable to -nographic
which (in addition to disabling graphics output) redirects the serial port to stdio and on OpenBIOS enables the firmware's serial console.
So -nographic
will have output on host console, but -display none
won't.
-no-hpet
-chardev
-chardev backend,id=id[,mux=on|off][,options]
Backend is one of: null
, socket
, udp
, msmouse
, vc
, ringbuf
, file
, pipe
, console
, serial
, pty
, stdio
, braille
, tty
, parallel
, parport
, spicevmc
, spiceport
. The specific backend will determine the applicable options.
All devices must have an id, which can be any string up to 127 characters long. It is used to uniquely identify this device in other command line directives.
A character device may be used in multiplexing mode by multiple front-ends.
Up to four different front ends can be connected to a single multiplexed chardev. (Without multiplexing enabled, a chardev can only be used by a single front end.)
QEMU User Documentation — QEMU documentation
-chardev stdio
Connect to standard input and standard output of the QEMU process.
QEMU Option Parsing Process
First pass:
qemu-options.hx
当你想添加一个新的 option 给 QEMU 时,你可以更改 qemu-options.hx
这个文件。
qemu-options.def
是在 Makefile 中利用 scripts/hxtool 脚本根据 qemu-options.hx
文件生成的,此文件中定义了 QEMU_OPTION_m
。
case QEMU_OPTION_m:
opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), optarg, true);
if (opts == NULL) {
exit(1);
}
break;