This patch implements automatic initrd detection for distro kernels. Unfortunately, it doesn't quite produce a working environment on Fedora: [ 0.588066] Freeing unused kernel memory: 912k freed [ 0.588981] Write protecting the kernel read-only data: 10240k [ 0.593634] Freeing unused kernel memory: 1332k freed [ 0.598900] Freeing unused kernel memory: 1580k freed [ 0.638157] dracut: dracut-009-12.fc15 [ 0.653838] udev[121]: starting version 167 [ 5.689056] dracut: Starting plymouth daemon plymouthd: ply-terminal.c:777: ply_terminal_set_mode: Assertion `terminal != ((void *)0)' failed. [ 5.706055] dracut: error: unexpectedly disconnected from boot status daemon I don't quite understand why udev starts up because we've configured kernel parameters to boot to "/virt/init": [ 0.000000] Command line: notsc noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1 console=ttyS0 earlyprintk=serial i8042.noaux=1 init=/bin/sh root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p init=/virt/init ip=dhcp Reported-by: Gerd Hoffmann <kraxel@xxxxxxxxxx> Cc: Cyrill Gorcunov <gorcunov@xxxxxxxxx> Cc: Sasha Levin <levinsasha928@xxxxxxxxx> Cc: Asias He <asias.hejun@xxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxx> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx> --- tools/kvm/Makefile | 3 +- tools/kvm/builtin-run.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 20389f9..136948e 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -162,7 +162,8 @@ endif WARNINGS += -Wall WARNINGS += -Wcast-align -WARNINGS += -Wformat=2 +WARNINGS += -Wformat +WARNINGS += -Wformat-security WARNINGS += -Winit-self WARNINGS += -Wmissing-declarations WARNINGS += -Wmissing-prototypes diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 2792650..2802e6a 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -562,6 +562,12 @@ static const char *host_kernels[] = { NULL }; +static const char *host_initrds[] = { + "/boot/initramfs-%s.img", + "/boot/initrd.img-%s", + NULL, +}; + static const char *default_kernels[] = { "./bzImage", "../../arch/x86/boot/bzImage", @@ -646,7 +652,6 @@ static const char *find_kernel(void) { const char **k; struct stat st; - struct utsname uts; k = &default_kernels[0]; while (*k) { @@ -658,6 +663,15 @@ static const char *find_kernel(void) return kernel; } + return NULL; +} + +static const char *find_host_kernel(void) +{ + const char **k; + struct stat st; + struct utsname uts; + if (uname(&uts) < 0) return NULL; @@ -676,6 +690,31 @@ static const char *find_kernel(void) return NULL; } +static const char *find_initrd(void) +{ + const char **k; + struct stat st; + struct utsname uts; + + if (uname(&uts) < 0) + return NULL; + + k = &host_initrds[0]; + while (*k) { + static char initrd[PATH_MAX]; + + if (snprintf(initrd, PATH_MAX, *k, uts.release) < 0) + return NULL; + + if (stat(initrd, &st) < 0 || !S_ISREG(st.st_mode)) { + k++; + continue; + } + return initrd; + } + return NULL; +} + static const char *find_vmlinux(void) { const char **vmlinux; @@ -741,6 +780,13 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) kernel_filename = find_kernel(); if (!kernel_filename) { + kernel_filename = find_host_kernel(); + + if (!initrd_filename) + initrd_filename = find_initrd(); + } + + if (!kernel_filename) { kernel_usage_with_options(); return EINVAL; } -- 1.7.6.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html