Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 745
densha Avatar asked Nov 01 '25 13:11

densha


1 Answers

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"
like image 74
KamilCuk Avatar answered Nov 03 '25 12:11

KamilCuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!