Ubuntu/gutsy and (apparently) even the venerable Debian have badly broken ideas about runlevels: runlevels 2-5 are the same, all of them start the GUI (via gdm, kdm, or whatever), 2 is the default, and it's ridiculously difficult to get a sane runlevel configuration working. Sorry, Ubuntu, but this is one that RedHat got right at least 11 years ago.
Ubuntu has abandoned inittab in favour of their homegrown upstart, not in itself a bad thing. inittab was cryptic, nobody understood it, and everyone who ever edited their inittab did so with fear and trepidation, but kernel boot options should override defaults, not the other way around.
The “sane runlevels” solution presented herein actually works and has been tested, unlike a lot of what I read, and tried, in “help” forums.
DON'T DO THIS UNLESS YOU KNOW WHAT YOU'RE DOING AND HAVE ANOTHER WAY OF BOOTING YOUR BOX. DON'T BLAME ME IF IT GOES WRONG: IF IT BREAKS, YOU GET TO KEEP BOTH PARTS.
I'm assuming that you already know what runlevels are and how to configure them on something that has ordinary inittab behaviour, like RedHat, CentOS or, it seems, any non-Ubuntu distro.
With that assumption, the solution is easy, you just do the following:
- Replace /etc/event.d/rc-default with my version of rc-default.
- Edit /boot/grub/menu.lst
- Run update-grub
- Install sysv-rc-conf and use it to configure your runlevels.
Stash a copy of /etc/event.d/rc-default away somewhere and replace it with my version of rc-default.
The version presented here scans the kernel command line for a numerical runlevel or "S" after the word init, not just for an instruction to enter single-user mode like the Ubuntu version.
In the Ubuntu shipping version, unfortunately, the presence of an inittab file (only one line of which counts) actually overrides anything on the kernel command-line, which is almost certainly not a good idea.
Edit grub Configuration File
Edit /boot/grub/menu.lst in your favourite editor.
If you're using the Ubuntu way of doing things, just add init 5 to the end of the # defoptions line, so that your default runlevel becomes 5:
# defoptions=quiet splash init 5
Now, find the line altoptions line that configures single-user mode (there's only one by default), change it to say init S (capital letter “S” for sierra), rather than single, and add a new line for text mode, like this:
# altoptions=(text mode) init 3 # altoptions=(recovery mode) init S
Now, make sure to run update-grub as root, so that the grub configuration really changes (the altoptions lines are comments ignored by grub, but are recognised by update-grub which updates the non-comment lines that grub actually uses).
Now is a good time to test. Reboot the machine: it will go into GUI mode as usual. Type runlevel at the shell-prompt: it should tell you that the runlevel is 5, not 2 (Ubuntu's default).
Now, reboot again. This time, hit Esc during the grub countdown at boot-time, and pick “text mode”. It will still boot into the GUI, but runlevel should tell you that you're now in runlevel 3, not 2 or 5. Remember, all the runlevels still behave the same because you haven't changed the symlinks in /etc/rcX.d yet.
Install and Use sysv-rc-conf
Install sysv-rc-conf (with sudo apt-get install sysv-rc-conf). It's a natty little tool which alleviates the tedium of manually renaming the symlinks in the /etc/rcX.d directories with an intuitive curses-based interface. Run it, and you can disable all the GUI-related stuff in runlevel 3. You can configure runlevels 2 and 4 any way you want, but don't touch 0, 1, S, or 6 (unless you really know what you're doing!)
Notes and Tips
Where's The Login Prompt?
In text mode, the gettys (terminal emulators on each virtual terminal) are started pretty early. So, some startup console log messages come after the login prompt. This might give the impression that the boot procedure has hung at the last log message (from rc.local), but it hasn't: you just have to hit Enter and the login prompt will appear.
In fact, if you watch the log messages streaming down the console carefully, you'll see the login prompt being presented and scrolling off the top of the screen.
From a virtual terminal, you can start a GUI session under the current user account with:
Alternatively, you can get a graphical login by starting GDM
$ sudo /etc/init.d/gdm start