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
}
  • OK, does it work if you replace everything from quiet until the end of the line with text? – terdon Sep 18 '15 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 '15 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 '15 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 '15 at 15:38
  • Please read my Edit, I have figured it out at least for my Debian and Arch Linux systems. Cheers. – MariusMatutiae Sep 18 '15 at 15:57
up vote 10 down vote accepted

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.

  • 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 '17 at 17:10

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.

  • This is what I too remembered, but it does not work on either of my sytems, with/out systemd. – MariusMatutiae Sep 18 '15 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 '15 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 '15 at 13:35
  • Here it is; please note that the file was in /boot/grub2/ – Sekhemty Sep 18 '15 at 14:21

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

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

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.