Thursday, March 31, 2022

[SOLVED] How to add a menu entry in Grub to start Ubuntu in command line

Issue

I have a desktop that I sometimes only use remotely through SSH. In these cases, having a graphical interface is useless so it could be great to start the system in text mode.

I'm using Ubuntu and I wanted to add a menu entry in Grub to do what I want (start in text mode, but not everytime). To do that, I added this to the file /etc/grub.d/40_custom:

menuentry 'Ubuntu (text mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-86845fc2-c8a4-4323-a936-497ae09f288c' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part_msdos
    insmod ext2
    set root='hd1,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos1 --hint-efi=hd1,msdos1 --hint-baremetal=ahci1,msdos1  86845fc2-c8a4-4323-a936-497ae09f288c
    else
      search --no-floppy --fs-uuid --set=root 86845fc2-c8a4-4323-a936-497ae09f288c
    fi
    linux   /boot/vmlinuz-3.19.0-59-generic root=UUID=86845fc2-c8a4-4323-a936-497ae09f288c ro  text
    initrd  /boot/initrd.img-3.19.0-59-generic
}

and then ran sudo update-grub.

The problem is that it simply doesn't work: when I use this new line, Ubuntu starts as usual, with the graphical interface and GDM asking to enter my password.

Any idea?


Solution

Thanks to Shubhangi's suggestion (see comments of the question) I found a way to do what I want. Based on this question, the thing I needed is booting Ubuntu in runlevel 3. To do that, we can add 3 in the linux line of the new entry.

More precisely, here is the new content of 40_custom:

menuentry 'Ubuntu (text mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-86845fc2-c8a4-4323-a936-497ae09f288c' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part_msdos
    insmod ext2
    set root='hd1,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos1 --hint-efi=hd1,msdos1 --hint-baremetal=ahci1,msdos1  86845fc2-c8a4-4323-a936-497ae09f288c
    else
      search --no-floppy --fs-uuid --set=root 86845fc2-c8a4-4323-a936-497ae09f288c
    fi
    linux   /vmlinuz root=UUID=86845fc2-c8a4-4323-a936-497ae09f288c 3 ro  text
    initrd  /initrd.img
}

Now reboot, choose your new entry, and you'll be in text mode. :)



Answered By - Jeremy
Answer Checked By - Dawn Plyler (WPSolving Volunteer)