Ubuntu – Add a grub menu entry that boots into the current install but with a different runlevel

14.10grub2initmenurunlevel

I am running the latest Kubuntu (14.10) and would like to add a grub2 menu entry that allows me to boot straight into a different runlevel? I would like to modify /etc/rc3.d or /etc/rc4.d to boot straight into the command line and not load X. I believe the custom menu entry should be placed in /etc/grub.d/40_custom? I assume I can copy my/the default menu entry in /boot/grub/grub.cfg? but then how do i make this entry boot at a different runlevel?

Can I add the command telinit 3 to the end of the custom menu entry?

any help would be appreciated 🙂

Best Answer

The problem with adding an entry using 40_custom is that the entry is static - the contents are copied as-is to grub.cfg, so a new kernel requires re-editing that file. With very slight tinkering of the 10-linux, you can get update-grub to generate an additional entry for each of the installed kernels. Edit /etc/grub.d/10_linux, and after the lines where it says:

linux_entry "${OS}" "${version}" advanced \
            "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  linux_entry "${OS}" "${version}" recovery \
              "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
fi

Add another call to linux_entry:

linux_entry "${OS}, runlevel 3" "${version}" advanced \
          "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} 3"

(Selecting a runlevel is as simple as tacking on the number at the end of the options, IIRC.)


Effect:

Menu entry in the "Advanced options" sub menu: entry
The contents of that entry: contents

Of course, normally runlevels 2-5 are equivalent, so booting from it made no difference to me, except:

$ runlevel
N 3
Related Question