1

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 :)

muru
  • 197,895
  • 55
  • 485
  • 740
sinttx
  • 31
  • 1
  • 4

1 Answers1

5

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
muru
  • 197,895
  • 55
  • 485
  • 740
  • I have just tried this and it works very well :) Thank You @muru Now I am going to do a backup then try modifying '/etc/rc3.d' and remove 'lightdm' – sinttx Oct 07 '14 at 02:33
  • @sinttx Since upstart handles these things now, you should probably be looking at /etc/init/lightdm.conf. – muru Oct 07 '14 at 02:45
  • I might have been working from outdated information :( I will do some research into '/etc/init/lightdm.conf' as described. Thanks again @muru – sinttx Oct 07 '14 at 02:58
  • I have managed to achieve this by updating the 10-linux file.

    Has anyone worked out how /etc/init/lightdm.conf is meant to be used to achieve the same thing (i.e. alternative to start in console only without X)?

    – Batwam Jan 06 '22 at 15:45
  • @hyg53 typiclly you just disable lightdm if you don't want it to start (e.g., systemctl disable lightdm.service, since these days its systemd and not Upstart) – muru Jan 07 '22 at 04:13
  • I see. Not directly what is being asked then as it would require to start x manually each time rather than just have this as an option in grub (for use when the videao drivers are playing up for instannce...). – Batwam Jan 10 '22 at 10:18
  • @hyg53 if that's the case, and you're using recent versions of Debian and Ubuntu, there won't be a /etc/init/lightdm.conf, and you'd just need to boot to runlevel 3 (technically multiuser.target) – muru Jan 12 '22 at 09:18
  • I've used this successfully on Mint 19 through 21.1 - sometimes when I update my nvidia drivers, they break things (as nvidia likes to do for some reason), and this allows me to fix it - Thanks @muru! – EvilSupahFly Feb 16 '23 at 14:03