Solved GRUB menu entry to boot to TTY?

Solved issue

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
676
Reaction score
547
Credits
3,969
Can something be added as GRUB menu entry to boot to TTY? Sometimes the system won't boot the desktop due to broken packages and in most cases I know what has been broken but I can't fix it bc the system hangs moments before booting the desktop. So it would be easier if I can simply choose the option from the menu, instead of restoring from backup every time something breaks.
 


f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
5,918
Reaction score
4,408
Credits
43,498
If the graphical environment doesn't load but the system it booted you can just use the ctrl+alt+f? shortcuts to switch to a tty without having to boot from the Arch live environment to chroot into your system to rescue it. Why would you need to add it to a grub menu, if you can switch to a tty at any moment if it's only the graphical environment fails to load?
 

osprey

Well-Known Member
Joined
Apr 15, 2022
Messages
675
Reaction score
562
Credits
6,306
Can something be added as GRUB menu entry to boot to TTY? Sometimes the system won't boot the desktop due to broken packages and in most cases I know what has been broken but I can't fix it bc the system hangs moments before booting the desktop. So it would be easier if I can simply choose the option from the menu, instead of restoring from backup every time something breaks.
As I understand it, the problem here is that the system hangs, so that getting a console with cntl+alt+F#, may not be available due to a freeze of the system, so you may need to reboot.

One could hack the /boot/grub/grub.cfg file to add a copy of one of the menuentries which already exist in the grub.cfg file, to the end of the file but with an added 3 at the end of its linux line, after a space on that line. Then that linux boot option should appear in the grub menu and if selected, boot to a text prompt. It's a hack, so whenever one updates grub, it will be overwritten and not be available. It's possible to write a script that runs after each grub update one might do, to re-include it.

The usual way I deal with it though is to hit e when grub boots, and then navigate down to the linux line and add the 3 there, hit cntl+x and it boots to a prompt. I hope I've understood the issue.

Another route down this track is to investigate the grub customisation process which involves configuring files in /etc/grub.d/.

From the grub manual:
For more detailed customisation of grub-mkconfig’s output, you may edit the scripts
in ‘/etc/grub.d’ directly. ‘/etc/grub.d/40_custom’ is particularly useful for adding entire
custom menu entries; simply type the menu entries you want to add at the end of that file,
making sure to leave at least the first two lines intact.

and from the /etc/grub.d/40_custom file itself:
Code:
#!/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.

You could copy one of the menuentries from /boot/grub/grub.cfg into this file but with the added 3 to have it boot to text. After each config change one needs to update grub of course.

In my own case, that customisation hasn't always been reliable, hence the hack. YMMV.
 
Last edited:
OP
rado84

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
676
Reaction score
547
Credits
3,969
This is the menu entry:
Code:
menuentry "Arch 6.x LTS" --class arcolinux --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-advanced-73719eb1-eb34-4234-9a3e-fd86f6999d54' {
        load_video
        set gfxpayload=keep
        insmod gzio
        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  73719eb1-eb34-4234-9a3e-fd86f6999d54
        else
          search --no-floppy --fs-uuid --set=root 73719eb1-eb34-4234-9a3e-fd86f6999d54
        fi
        echo    'Loading Linux linux-lts ...'
        linux    /boot/vmlinuz-linux-lts root=UUID=73719eb1-eb34-4234-9a3e-fd86f6999d54 rw  acpi=force acpi_enforce_resources=lax intel_pstate=disable
        echo    'Loading initial ramdisk ...'
        initrd    /boot/initramfs-linux-lts.img
}

So where, exactly, do I put the number "3"?
 

osprey

Well-Known Member
Joined
Apr 15, 2022
Messages
675
Reaction score
562
Credits
6,306
rado84 asked:
So where, exactly, do I put the number "3"?
At the end of the linux line after a space ... like so:
Code:
linux    /boot/vmlinuz-linux-lts root=UUID=73719eb1-eb34-4234-9a3e-fd86f6999d54 rw  acpi=force acpi_enforce_resources=lax intel_pstate=disable 3
 
OP
rado84

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
676
Reaction score
547
Credits
3,969
Cool, I'll try that now.
Also, I'm editing grub.cfg directly myself. Not just now but in principle. Arch wiki says (as I have discovered myself, long before I read it) that directly editing grub.cfg doesn't require you to execute update-grub or whatever that command was. Grub.cfg remains the same as what I've made of it, even if the package grub updates.

Edit, 20 seconds later: Yesss, it works! :D Thanks, man, that's a cool hack!
 

osprey

Well-Known Member
Joined
Apr 15, 2022
Messages
675
Reaction score
562
Credits
6,306
Cool, I'll try that now.
Also, I'm editing grub.cfg directly myself. Not just now but in principle. Arch wiki says (as I have discovered myself, long before I read it) that directly editing grub.cfg doesn't require you to execute update-grub or whatever that command was. Grub.cfg remains the same as what I've made of it, even if the package grub updates.
Yes, that's the hack I was referring to, and mentioned that a grub update would nullify it. It's for the other "conventional" means of changing the configs that one needs to update grub.
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Members online


Latest posts

Top