Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm assembling some DR stuff for my Linux boxes. One item that would be really handy would be a GRUB option that would run a script to change my boxes from static IPs to dynamic.

I know we could do a single user mode, run a script, reboot, etc but it would greatly simply things for the other admins (mostly with a Windows background) to select one item and have it complete the process automatically.

I would swear that I've seen configuration settings provided to let Grub do this at one point or another but it's been a while. Not sure what to google for.


I'm aware of the rc.local method, however I don't want this to run on every boot. I want there to be an option listed (line item in grub.conf, probably) which allows for a specific script to be run only when that boot option is selected.

share|improve this question
up vote 1 down vote accepted

Grub itself can't do this. Its filesystem drivers only support reading.

You can make an entry that loads a Linux kernel (and initrd or initramfs as appropriate) and runs a specific command by passing init=/path/to/script on the kernel command line. That script would do all the requisite mounting, user prompting, file modifications, and finally reboot.

You can also make separate entries that pass a custom argument on the kernel command line. Unknown arguments are ignored, the assumption being that it may be used by some driver which is perhaps loaded as a module. So make Grub entries that pass a kernel argument local.network_interfaces=…, and in /etc/rc.local, look up the value of that argument (</proc/cmdline tr ' ' '\n' | sed -n 's/^local.network_interfaces=//p').

share|improve this answer
Perfect. Is there any way to avoid a kernel panic when the script exits using the init method? – Tim Brigham Feb 19 '13 at 21:15
@TimBrigham Yes: don't exit. Either exec (exec /sbin/init, probably) or reboot. – Gilles Feb 19 '13 at 23:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.