5

OK, this is what I'm trying to achieve:

Have a separate menu option in GRUB, so that I can select it and boot straight into the command line - that is: without a desktop manager, but leaving the existing menu item (to boot Ubuntu as usual) intact.

I've looked into /etc/default/grub but there seems nothing to do there. And also /boot/grub/grub.cfg which is auto-generated, so I don't think it would be a good idea to edit it directly.

How should I go about it? Any idea?


Update: The existing answer (suggesting that this question was a duplicate) was obsolete. For the correct solution, please see the accepted answer below, which works beautifully. (at least for 16.04+ as it seems)

7
  • 1
    I think the best place for that is in the /etc/grub.d adding you custom menu entry there, please read the README file in there! Apr 28 '18 at 18:08
  • 1
    Possible duplicate of Add console/text booting mode to grub menu Apr 28 '18 at 18:14
  • @PerlDuck I know this answer, and just tried it, but it didn't work for me. It boots in the GUI as usual. Apr 28 '18 at 18:27
  • Yes, that's because it lacks a crucial point for recent Ubuntu versions.
    – PerlDuck
    Apr 28 '18 at 18:29
  • 1
    I hope so as well. I tested my solution with 16.10, 17.04, and 17.10. The point is the systemd.unit=multi-user.target parameter in the linux line. I described that in my answer.
    – PerlDuck
    Apr 28 '18 at 18:37
6

One

Open the file /boot/grub/grub.cfg and find the section that boots your "regular" Ubuntu.

For me this is:

menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-b8f25f1e-a169-4aaa-9f05-90e49359d865' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
        set root='hd0,gpt2'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  b8f25f1e-a169-4aaa-9f05-90e49359d865
        else
          search --no-floppy --fs-uuid --set=root b8f25f1e-a169-4aaa-9f05-90e49359d865
        fi
        linux   /boot/vmlinuz-4.13.0-39-generic.efi.signed root=UUID=b8f25f1e-a169-4aaa-9f05-90e49359d865 ro  
        initrd  /boot/initrd.img-4.13.0-39-generic
}

Copy that section to a new file, say textmode.txt.

Two

Go to /etc/grub.d and create (or edit) the file 40_custom.

Copy the following "header" to the file:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

Add the menuentry from textmode.txt to the file but change some values (see below):

menuentry 'Ubuntu (text mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-b8f25f1e-a169-4aaa-9f05-90e49359d865' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
        set root='hd0,gpt2'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  b8f25f1e-a169-4aaa-9f05-90e49359d865
        else
          search --no-floppy --fs-uuid --set=root b8f25f1e-a169-4aaa-9f05-90e49359d865
        fi
        linux   /vmlinuz root=UUID=b8f25f1e-a169-4aaa-9f05-90e49359d865 systemd.unit=multi-user.target ro
        initrd  /initrd.img
}

The values that must be changed are:

  • The menuentry text: change it from 'Ubuntu' to 'Ubuntu (text mode)' (or whatever you like to appear in the menu)
  • The linux line: change it to linux /vmlinuz root=UUID=... systemd.unit=multi-user.target ro. Make sure the UUID stays the same.
  • The initrd line: change it to /initrd.img

Make sure you have symlinks in your / directory from /vmlinuz and /initrd.img to the current versions. This is the default, anyway.

Three

Run

sudo update-grub

The difference between this approach and this answer to a very similar question is that in recent versions of Ubuntu the line

linux   /boot/vmlinuz-3.8.0-31-generic root=UUID=... ro quiet splash $vt_handoff

needs to be replaced with

linux   /vmlinuz root=UUID=... systemd.unit=multi-user.target ro

I'm not sure what recent actually means but I guess it's 16.04 when systemd was introduced.

3
  • My friend, you're awesome. It worked! :) The trick was that systemd.unit=multi-user-target part. Now, as a sidenote, I had to leave the linux and initrd parts as they were, because it complained that it couldn't find an image at /vmlinuz, etc. But other than that, simply great. Thanks a lot! :) Apr 28 '18 at 18:46
  • Glad to hear that. I also once noticed that the symlink vmlinuz → boot/vmlinuz-4.13.0-39-generic was missing but after some time (and updates) it appeared. Perhaps it only comes to existence when multiple kernel images are installed.
    – PerlDuck
    Apr 28 '18 at 18:51
  • 1
    hmm, you maybe have a point. Who knows.. Mine is a super fresh install, so chances are all it can see is just one kernel image. Apr 28 '18 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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