如何找到正在运行的内核使用的引导参数?


Answers:


69

您可以运行cat /proc/cmdline

例:

[01:31] ~ $ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-2.6.38-7-generic root=UUID=025c4231-b7bb-48bf-93e9-d20c5b5ce123 ro crashkernel=384M-2G:64M,2G-:128M quiet splash bootchart=disable acpi_enforce_resources=lax vga=792 vt.handoff=7

尝试tr ' ' '\n' < /proc/cmdline获取参数之间的换行符。
mwfearnley

10

另一种方法是检查dmesg(此处第5行)的输出:

$ dmesg | grep "Command line"
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.19.0-33-generic root=UUID=81dba11f-f76e-4ed4-8120-e6da6328b1ee ro

但是请注意,如果记录了许多内容(例如,如果计算机已经运行很长时间),则这可能不起作用,因为初始启动行可能已从环形缓冲区中推出。


1

实际上,该参数位于内核之间__setup_start__setup_end内核中。在以下代码中,p->str是参数名称

以下内核代码可以在linux-3.4.5 / init / main.c:388中找到

/* Check for early params. */
static int __init do_early_param(char *param, char *val)
{
    const struct obs_kernel_param *p;
    for (p = __setup_start; p < __setup_end; p++) {
        if ((p->early && parameq(param, p->str)) ||
            (strcmp(param, "console") == 0 &&
             strcmp(p->str, "earlycon") == 0)
        ) {
            if (p->setup_func(val) != 0)
                printk(KERN_WARNING
                       "Malformed early option '%s'\n", param);
        }
    }


    /* We accept everything at this stage. */
    return 0;
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.