Add a text-only runlevel to Ubuntu Gutsy

| | Comments (9) | TrackBacks (0)

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.

Solution

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.
  • Reboot!

Replace rc-default

Stash a copy of /etc/event.d/rc-default away somewhere and replace it with my version of rc-default.

The Difference

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

Run update-grub

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

Test It

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.

Starting X

From a virtual terminal, you can start a GUI session under the current user account with:

$ startx

Alternatively, you can get a graphical login by starting GDM

$ sudo /etc/init.d/gdm start

0 TrackBacks

Listed below are links to blogs that reference this entry: Add a text-only runlevel to Ubuntu Gutsy.

TrackBack URL for this entry: http://caulfield.info/mt/tb.cgi/7

9 Comments

The version of rc-default provided above caused my Ubuntu 8.04 system to fail to start. However, the version I posted here does work: http://pastebin.mozilla.org/472796

Very Good!
I agree you ideas!
I come from openSUSE.
I feel also there are some bad ideas in Ubuntu incuding the runlevels issue.

I applaud your work. I do agree coming from years of SysV usage myself runlevels are not used as intended in Ubuntu. However, it is my understanding that the runlevel "crutch" in upstart is more a helper for old sysv apps to ease the transition from a runlevel, sysv based init system to an event based system. Perhaps I misunderstood though?

Hi, Thanks for your explanation and fix of ubuntu runlevels. I recently put up a web page on this same subject at http://lwasserm.freeshell.org/ubuntu/runlevel3.shtml and mention and include links to your page. I wanted to make sure this is OK with you and give you an opportunity to comment.

Thanks again.

Larry W

Hi Larry,

Nice job and thanks for the props.

Emmet.

rc-default exits with status 1. Fouled my system up so thoroughly I decided to reinstall rather than try getting it back to the way it was.

Guys, check this out, is in spanish but solves the problem in Ubuntu 9.10

http://www.hipergalaxia.org/blog/2010/01/05/iniciar-linux-ubuntu-9-10-en-modo-solo-texto/

Regards

> Guys, check this out, is in spanish but solves the problem in Ubuntu 9.10

> http://www.hipergalaxia.org/blog/2010/01/05/iniciar-linux-ubuntu-9-10-en-modo-solo-texto/

God! It was it! Thank you!

I'll translate the "quick" way:

Execute
      sudo vi /etc/default/grub

Find
      GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash“
and change it, being left like this:
      GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash text“

Execute:
      sudo update-grub

Of course, if you find "vi" difficult you can use "nano" instead.

Later, if you want to go into the graphical mode, you can execute:
      startx