densha
densha

Reputation: 175

Run script from GRUB menu entry

I have created a Debian Live DVD following the excellent guide https://willhaley.com/blog/custom-debian-live-environment/.

I would like to be able to great two grub menu enteries when selected auto login and run a script.

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

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

How can I pass from grub menu entry the absolute path of a script to run when I auto login as root?

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

To auto login I have modified /lib/systemd/system/[email protected] to auto login as root using the above menu items.

Upvotes: 4

Views: 3456

Answers (1)

KamilCuk
KamilCuk

Reputation: 140960

Boot with a custom parameter:

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

Then later read /proc/cmdline and parse it in your login shell startup files, ex. in .bashrc for bash shells or .profile:

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

Upvotes: 4

Related Questions