运行 来自 GRUB 菜单项的脚本

Run script from GRUB menu entry

我按照出色的指南 https://willhaley.com/blog/custom-debian-live-environment/ 创建了一张 Debian Live DVD。

我希望在选择自动登录和 运行 脚本时能够进入两个 grub 菜单条目。

    menuentry "Run Script 1" {
        linux /vmlinuz boot=live quiet nomodeset
        initrd /initrd
    }

    menuentry "Run Script 2" {
        linux /vmlinuz boot=live quiet nomodeset
        initrd /initrd
    }

当我以 root 身份自动登录时,如何将脚本的绝对路径从 grub 菜单项传递到 运行?

/lib/live/mount/medium/scripts/script1.bash

为了自动登录,我修改了 /lib/systemd/system/getty@.service 以使用上述菜单项以 root 身份自动登录。

使用自定义参数启动:

linux /vmlinuz .... my_dummy_param=/lib/live/mount/medium/scripts/script1.bash

然后稍后阅读 /proc/cmdline 并在您的登录 shell 启动文件中解析它,例如。在 .bashrc 中 bash shell 或 .profile:

#!/bin/bash
. /proc/cmdline
echo "Running $my_dummy_param"
"$my_dummy_param"