12

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
}
6
  • OK, does it work if you replace everything from quiet until the end of the line with text?
    – terdon
    Sep 18, 2015 at 14:22
  • No, the graphical interface starts as usual. I also tried to replicate your first suggestion by simplifying the linux line to linux /boot/vmlinuz-3.16.7-24-desktop root=UUID=179689d2-d2f3-4ec8-9cc3-01ec946c6b11 ro quiet text, whitout any success.
    – Sekhemty
    Sep 18, 2015 at 14:57
  • So, you're hitting E to edit the menu entry on the grub boot screen and then F10 to boot and it still goes to GUI?
    – terdon
    Sep 18, 2015 at 15:09
  • Yes, exactly. I have even tried this on a virtual machine (still with openSUSE) but without any success. As soon as possible I'll try also with another distro.
    – Sekhemty
    Sep 18, 2015 at 15:38
  • Please read my Edit, I have figured it out at least for my Debian and Arch Linux systems. Cheers. Sep 18, 2015 at 15:57

6 Answers 6

30

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.

1
  • Always usefull when your nvidia drivers brick... The solution with using 3 instead of text did actually work. In my case, I had also to remove the resume=... part
    – Felix
    Nov 2, 2017 at 17:10
6

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.

5
  • 1
    This is what I too remembered, but it does not work on either of my sytems, with/out systemd. Sep 18, 2015 at 13:28
  • Unfortunately it doesn't work for me either; if it matters, I'm using openSUSE 13.2, and the linux line is longer and has some more variables; anyway, adding text apparently does nothing on my system.
    – Sekhemty
    Sep 18, 2015 at 13:31
  • @Sekhemty please add the relevant linux line to your question. You can see it in /boot/grub/grub.cfg. I just tried this in an Ubuntu VM and it worked as expected.
    – terdon
    Sep 18, 2015 at 13:35
  • Here it is; please note that the file was in /boot/grub2/
    – Sekhemty
    Sep 18, 2015 at 14:21
  • 1
    ... quiet text didn't work for me (Debian 11), but ... quiet 3 worked
    – kol
    Aug 9, 2022 at 12:54
4

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

1

Please take a look at this article: How to use Grub2 to boot Linux manually

Indirect booting by chainloading

For Grub1 if you want to fire up an OS, which can be any Dos, MS Windows, BSD, Solaris or Linux, installed in the 2nd partition of the 1st disk the Grub Legacy commands will be Code:

root (hd0,1)
chainloader +1
boot

For Grub2 the commands are slightly different and the changes are highlighted in red Code:

set root=(hd0,2)
chainloader +1
boot

Direct booting by naming the kernel and initrd files

...

Say if my Linux has vmlinuz-2.6.18-6-686 and initrd.img-2.6.18-6-686 in /boot subdirectory one can boot up the Linux with Grub1 commands of Code:

root (hd0,1)
kernel  /boot/vmlinuz-2.6.18-6-686 root=/dev/sda11 ro 
initrd   /boot/initrd.img-2.6.18-6-686
boot

For Grub2 the corresponding commands will be Code:

set root=(hd0,2)
linux  /boot/vmlinuz-2.6.18-6-686 root=/dev/sda11  
initrd   /boot/initrd.img-2.6.18-6-686
boot
0

to disable the X server I edit the file /etc/default/grub on the line

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

modifying to

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash init 3"

then just restart and if you want to start in graphical mode, log in and run the startx command

0

Boot (live) linux under systemd without graphical server

Using often Live install images as maintenance tool, in many different situation, I'm sometime interested by booting without starting graphical server and of course without starting graphical login daemon.

For this, as now systemd is installed by default, the correct way I used was:

Of course this work not only for live systems, but also for regular installation. The only difference could be how to edit command line:

At grub menu: Tab, Left, Left, Left, ... upto end of word splash, then Ctrl+w to drop the word splash (care to not remove the space after splash) and replace by:

systemd.mask=gdm

then Return.

Of course, depending on version of live, you could have to replace gdm by one of lightdm, kdm, sddm, or other.

systemd.mask=gdm systemd.mask=kdm systemd.mask=sddm

If you're not sure, you even could mask more daemon than installed! Of course, you will have more hit on keyboard...

Then, you could hit Ctrl+e in order to re-read whole boot command line, before hitting Return to run the kernel.

1
  • Note: Dropping splash is not required! You could just add systemd.mask=gdm at end of boot command line. Feb 5 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .