Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: HowTo: Boot into runlevel 3 (text-only; no X server)

  1. #1
    Join Date
    Jun 2008
    Beans
    1

    HowTo: Boot into runlevel 3 (text-only; no X server)

    Starting a Desktop Install without GDM
    Ubuntu 8.04 Hardy


    ----

    Hi Everyone,

    This took me quite a while to get working (I couldn't find anything on the web) so I thought I'd post here. Stopping and starting the X-server is easiest done with the service commands (sudo /etc/init.d/gdm stop) and (sudo /etc/init.d/gdm start) but I would rather be able to choose from grub (when the computer is booting) whether or not to start the graphics.

    Intro

    "Why would you ever want to do this?" is a very good question which I'll not go into in detail here. I use it on a laptop that I'd like to have start and stop very quickly and with minimal resource use but still have to option of getting into gnome if I want.

    Booting into a different runlevel is usually done by adding the number at the end of the kernal command in grub (more on these terms in a few) but this doesn't seem to work in Ubuntu; it will always get into runlevel 2.

    Runlevels

    A runlevel is used to tell the OS how far up you want it to boot. Generally, we use runlevel 1 for debugging/recovery mode, runlevel 3 for normal text (no graphics mode) and runlevel 5 for normal with graphics. Runlevels 0 and 6 are when the computer is shutting down/restarting. Runlevels 2 and 4 are user-defined and used for doing crazy stuff without modifying the standard 1,3 and 5 runlevels.

    Ubuntu uses runlevel 1 for text mode, as expected, but uses runlevel 2 for full graphical mode. This leaves no room in between for the text mode but the runlevels 3 to 5 are still available to us. Relating to the above paragraph: in Ubuntu, runlevels 2 to 5 are all used as runlevel 5.

    In a more hands-on explanation, we can say that the different runlevels refer to different folders filled with scripts that are called at boot and start up all the different programs that need to be started. Runlevel 1 will have only a few scripts but runlevel 2 will have all of them.

    We have to then modify runlevel 3 to be text-only and update the boot script somehow to point it to runlevel 3 instead of runlevel 2.

    Step 1: Changing Runlevel 3 to Text-Only

    Load up a terminal/console if one isn't already by clicking on Applications->Accessories->Terminal.

    The folders that refer to the different runlevels are called /etc/rcX.d where X is the runlevel so enter and list the runlevel 3 folder by typing in

    Code:
    cd /etc/rc3.d
    ls
    Look for the script that says gdm, it should be S30gdm. If you're running KDE, this might be S30kdm (untested). Remove this script by calling

    Code:
    sudo rm S30gdm
    Step 2: Making Runlevel 3 Accessible from GRUB

    I had to modify the rc-default script to do this. This is extremely dangerous and could make your computer "unbootable". An error can be recovered from using the Live CD so it wouldn't be the end of the world but just be careful to copy exactly and you'll be fine.

    Open up the rc-default script by typing in

    Code:
    sudo gedit /etc/event.d/rc-default
    The script should look like this:

    Code:
    # rc - runlevel compatibility
    #
    # This task guesses what the "default runlevel" should be and starts the
    # appropriate script.
    
    start on stopped rcS
    
    script
    	runlevel --reboot || true
    
    	if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
    	    telinit S
    	elif [ -r /etc/inittab ]; then
    	    RL="$(sed -n -e "/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
    	    if [ -n "$RL" ]; then
    		telinit $RL
    	    else
    		telinit 2
    	    fi
    	else
    	    telinit 2
    	fi
    end script
    If your script doesn't look like above, stop here because I can't guarantee my modifications to work. We're going to add a new elif statement to look for the word text and boot into runlevel 3. Change your script (copy/paste) to look like the following

    Code:
    # rc - runlevel compatibility
    #
    # This task guesses what the "default runlevel" should be and starts the
    # appropriate script.
    
    start on stopped rcS
    
    script
    	runlevel --reboot || true
    
    	if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
    	    telinit S
    	elif grep -q -w -- "-s\|text\|S" /proc/cmdline; then
    	    telinit 3
    	elif [ -r /etc/inittab ]; then
    	    RL="$(sed -n -e "/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
    	    if [ -n "$RL" ]; then
    		telinit $RL
    	    else
    		telinit 2
    	    fi
    	else
    	    telinit 2
    	fi
    end script
    Double-check that everything's exactly identical and move on.

    Step 3a: Booting into Text-Mode Once

    Reboot your computer and enter the GRUB menu. This should be done automatically but in some installs, you have to push the ESC key while a timer's counting down.

    The GRUB screen will give you a few different options, none of which should have changed. To give you an idea of the screen we're looking for, mine lists the following:

    Ubuntu 8.04, kernel 2.6.24-19-generic
    Ubuntu 8.04, kernel 2.6.24-19-generic (recovery mode)
    Ubuntu 8.04, memtest86+


    Highlight the default (should be the very top) option and press the 'e' key for edit (once). Again to make sure we're on the same page, mine lists the following:

    root (hd0,0)
    kernel /boot/vmlinuz-2.6.24-19-generic root=UUID=21c38426-84f0-4946-bee7-318074de0787 ro quiet splash
    initrd /boot/initrd.img-2.6.24-19-generic
    quiet


    Highlight the kernel (second) option and push the 'e' key again. Type in "text" at the end (after splash) so that it looks like this:

    kernel /boot/vmlinuz-2.6.24-19-generic root=UUID=21c38426-84f0-4946-bee7-318074de0787 ro quiet splash text

    Note that your UUID and kernel version may be different and you should not change it. Just add the word "text" to the end of whatever's there. Press the 'b' key to boot into text mode.

    Step 3b: Booting into Text-Mode Always

    Load up a terminal/console if one isn't already by clicking on Applications->Accessories->Terminal.

    Load up the GRUB config by typing in:

    Code:
    sudo gedit /boot/grub/menu.lst
    Near the bottom of this file, you'll see a list of all the different boot options of the GRUB menu. To give a good idea of what you're looking for, one of mine looks like this:

    title Ubuntu 8.04, kernel 2.6.24-19-generic
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.24-19-generic root=UUID=21c38426-84f0-4946-bee7-318074de0787 ro quiet splash
    initrd /boot/initrd.img-2.6.24-19-generic
    quiet


    You might have quite a few of these if you've been following different kernel updates; edit the very top one of these. Add the word "text" to the end of the kernel line, exactly as described in Step 3a so that the above example would look like this:


    title Ubuntu 8.04, kernel 2.6.24-19-generic
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.24-19-generic root=UUID=21c38426-84f0-4946-bee7-318074de0787 ro quiet splash text
    initrd /boot/initrd.img-2.6.24-19-generic
    quiet


    Step 4: Running the Graphical Interface While in Text-Only Mode

    If you're running in text and want to see the graphics stuff again, there are two different ways to go.

    To see the nice login screen like Ubuntu normally boots into , type in:

    Code:
    sudo /etc/init.d/gdm start
    You may have to swap gdm with kdm if you're using KDE (untested). If you just want to see Gnome/KDE (skipping the login part), type in

    Code:
    startx


    RB

  2. #2
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    Code:
    grep -q -w -- "-s\|text\|S" /proc/cmdline
    I'm trying to figure out what the "-s\|" and "\|S" mean. Can you explain?

  3. #3
    Join Date
    Feb 2005
    Beans
    425

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    Quote Originally Posted by unutbu View Post
    Code:
    grep -q -w -- "-s\|text\|S" /proc/cmdline
    I'm trying to figure out what the "-s\|" and "\|S" mean. Can you explain?
    That will accept "-s" or "text" or "S".
    Please use launchpad to search for/report bugs and problems: https://help.ubuntu.com/community/ReportingBugs

  4. #4
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    Yes, thanks. It seems to me the script above should not try to test for "-s" and "S" twice. Perhaps the script should use this instead:

    Code:
    	if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
    	    telinit S
    	elif grep -q -w -- "text" /proc/cmdline; then
    	    telinit 3

  5. #5
    Join Date
    Feb 2005
    Beans
    425

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    Yes, absolutely. I think it must have been a copy-and-paste without understanding the details of the grep pattern.
    Please use launchpad to search for/report bugs and problems: https://help.ubuntu.com/community/ReportingBugs

  6. #6
    Join Date
    Aug 2008
    Beans
    2

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    Hi,

    I think it is not required to remove gdm from /etc/rc3.d

    I followed the initial protocol without removing gdm from rc3.d and it worked fine.

    Additionally, I checked if gdm mode was listed running the lsmod command and I did not find it there, so I suppose gdm is not running.

    BTW, thanks for the script change, very helpful for rookies like me.

  7. #7
    Join Date
    Feb 2005
    Beans
    425

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    This whole thread is now obsolete: There is a boot option "text" that will inhibit gdm from starting. So just add "text" to the kernel line in grub, and the machine will boot up completely except starting gdm.
    Please use launchpad to search for/report bugs and problems: https://help.ubuntu.com/community/ReportingBugs

  8. #8
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    Thank you tormod! I did not know about the "text" boot option.
    I looked in /etc/event.d/rc-default and did not find "text" being handled there. Do you know how it works or where I can find documentation on it?

    Also, for those interested in controlling runlevels at boot time
    there is also this guide:
    http://lwasserm.freeshell.org/ubuntu/runlevel3.shtml
    which describes a slightly more versatile method of selecting any runlevel.

  9. #9
    Join Date
    Feb 2005
    Beans
    425

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    Quote Originally Posted by unutbu View Post
    Thank you tormod! I did not know about the "text" boot option.
    I looked in /etc/event.d/rc-default and did not find "text" being handled there. Do you know how it works or where I can find documentation on it?
    It is dealt with inside /etc/init.d/gdm, with the disadvantage that if you have booted with "text" you can not run "sudo /etc/init.d/gdm start" to start X... But "startx" will work for the logged-in user.
    Please use launchpad to search for/report bugs and problems: https://help.ubuntu.com/community/ReportingBugs

  10. #10
    Join Date
    Aug 2009
    Beans
    2

    Re: HowTo: Boot into runlevel 3 (text-only; no X server)

    I'm sorry about raising this thread from the dead, but if I just add "text" behind the kernel, doesn't that mean I have to manually edit GRUB every time a new kernel arrives? And given that I have updates set on automatic installation, I will not even know immediately if a new kernel (booting into X and gdm) has arrived.

    I use this PC as a server and guest PC, so it must boot into init 3 as text mode but allow me to start gdm. Besides, I often prefer doing things visually even in the server when piping stuff through ssh is too complicated with all the permission failures. I use the latest 32bit Ubuntu as of the date of this message.

    When I used to use Sidux it was as simple as setting the default runlevel in smxi, it's changing one number after smxi has loaded. 60 seconds, done. Unfortunately I do not know what happens behind the scenes and what smxi does, which, even more unfortunately isn't available for Ubuntu.

    Isn't there a more standardized way of setting the default runlevel for Ubuntu _permanently_ without being so scary as this inital howto.

    There's an option "no graphical login manager" in /Administration/Services/, but it comes with a stark warning when trying to uncheck it. Will I be able to start gdm from the boot terminal after unchecking it? Not being able to return to gdm means for me reinstalling and losing all my settings.

    Cheers, Mom

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •