How to boot a Linux system without graphical server

I'd like to know what should be done to boot a Linux system on a CLI environment, without also starting the X graphical server.

I'm interested in a temporary-only solution, ideally

  • a command, or a series of commands, that can be run on the Grub terminal (the one that you get when you press C);
  • or by adding an entry on the KDM menu where you select a desktop environment;

rather than a permanent change on the system (the standard behaviour should be to boot with the default graphical interface).


As requested, I'm adding the relevant content of /boot/grub2/grub.cgf

menuentry 'openSUSE 13.2' --class opensuse --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-179689d2-d2f3-4ec8-9cc3-01ec946c6b11' {
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_msdos 
    insmod ext2
    set root='hd0,msdos5'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5 --hint='hd0,msdos5'  179689d2-d2f3-4ec8-9cc3-01ec946c6b11
    else
      search --no-floppy --fs-uuid --set=root 179689d2-d2f3-4ec8-9cc3-01ec946c6b11
    fi
    echo    'Loading Linux 3.16.7-24-desktop ...'
    linux   /boot/vmlinuz-3.16.7-24-desktop root=UUID=179689d2-d2f3-4ec8-9cc3-01ec946c6b11   quiet quiet liveinstall lang=it_IT resume=/dev/disk/by-id/ata-WDC_WD5000BEVT-00A0RT0_WD-WXL1AC0U9725-part7 splash=silent quiet showopts vga=803
    echo    'Loading initial ramdisk ...'
    initrd  /boot/initrd-3.16.7-24-desktop
}

Solution 1:

What you are asking for is not completely clear to me, so I will give you several possible answers, hoping you can find the one you are interested in.

  1. You can disable the X server at the next boot by going to /etc/default/grub, finding the line

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    

    and modifying it into

    GRUB_CMDLINE_LINUX_DEFAULT="text"
    

    Now you need to update grub,

    update-grub
    

    and you are done.

You can do the vice versa to re-enable the X server.

  1. You can disable your Window Manager: assuming you are using systemd, which most Linux distros do nowadays,

    systemctl disable kdm
    

    or gdm, lightdm, whatever you use.

  2. If you think you may wish to change your mind, occasionally, after boot has started, add to the file /etc/grub.d/40_custom the following manual entry:

     menuentry 'Ubuntu (Text mode)' --class ubuntu {
     recordfail
     insmod gzio
     insmod part_msdos
     insmod ext2
     set root='hd0,msdos1'
     linux   /vmlinuz root=/dev/sda1 ro   text
     initrd  /initrd.img
     }
    

    (make sure you adapt /dev/sda1 and msdos1 to your configuration). This produces just an entry in your GRUB2 menu which you may wish to use occasionally.

  3. If all you want is a text login, even when a graphical session has started, remember that the combination Ctrl+Alt+F1 (or F2-F6) will give you just that, a textual login. Furthermore, you can then disable your Window Manager from within this textual login,

    sudo systemctl stop gdm
    

    (ord kdm, lightdm, sddm,, or whatever you use), and there you have a purely textual login, no graphical session running.

  4. Lastly, you may wish to resort to text-only booting when you are hit by some unexpected error in your graphical configuration (an update gone awry?), which has caught you unaware (i.e., without having prepared for solution 3). If you are stuck at the command prompt in grub, you may use Terdon's suggestion suitably modified, because, as it stands, it does not work on my Debian and Arch Linux systems, but the following does: instead of appending text to the linux line in the Grub display as Terdon suggested, type 3 (three) instead; e.g.,

    linux   /boot/vmlinuz-4.0.0-1-amd64 root=UUID=5e285652 ro  quiet 3
    

    This will successfully boot you into runlevel 3, which is CLI with networking but no display manager.

Solution 2:

Well, the simplest approach for a one-time boot to text mode would be to select the kernel entry you want to boot when at the GRUB2 screen, hit E, scroll down to the linux line and add text to the end. For example:

linux   /boot/vmlinuz-4.0.0-1-amd64 root=UUID=5e285652 ro  quiet text

Then, hit F10 or Ctrl+X to boot.

Solution 3:

Copy paste from /etc/inittab:

# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
#

Hence, you can set:

systemctl set-default multi-user.target

to run only CLI