Ask Your Question
5

How to get to rescue mode when GRUB timeout is 0?

asked 2014-08-21 01:06:25 -0600

abadrinath gravatar image

updated 2014-08-23 04:36:58 -0600

Hey!

I seriously messed up my grub.cfg at /boot/efi/EFI/fedora/grub.cfg and my GRUB timeout is 0 in /etc/default/grub. I have to edit the file, but I do not have any way of accessing the disk. The only ways I can think of that are relevent (I have too many random thoughts :P):

  • Reinstalling (worst idea)
  • LiveUSB (meh, could do that)
  • Rescue mode (easiest) So, any way of a rescue mode.

James

Here is my /etc/grub/default:

GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="vconsole.font=latarcyrheb-sun16 $([ -x /usr/sbin/rhcrashkernel-param ] && /usr/sbin/rhcrashkernel-param || :) rhgb quiet  libahci.ignore_sss=1 raid=noautodetect"
GRUB_DISABLE_RECOVERY="true"
and my grub.cfg (relevent bits):
menuentry 'Fedora, with Linux 3.15.10-200.fc20.x86_64' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.15.10-200.fc20.x86_64-advanced-6b266543-a497-44de-981f-ee460b85590a' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='hd0,gpt9'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt9 --hint-efi=hd0,gpt9 --hint-baremetal=ahci0,gpt9  48ce0f9f-eee1-4f72-b90e-1a28e6a83c8e
        else
          search --no-floppy --fs-uuid --set=root 48ce0f9f-eee1-4f72-b90e-1a28e6a83c8e
        fi
        linuxefi /vmlinuz-3.15.10-200.fc20.x86_64 root=UUID=6b266543-a497-44de-981f-ee460b85590a rw vconsole.font=latarcyrheb-sun16  rhgb quiet libahci.ignore_sss=1 raid=noautodetect
#        initrdefi /initramfs-3.15.10-200.fc20.x86_64.img
}

Now, that I think about it, I have to set root=/dev/sda10 instead of root=UUID=6b266543-a497-44de-981f-ee460b85590a. Any ways to get to a command line (or however else I can fix it)?

Update: I have fixed the issue, but I still want to know a workaround to this in case it happens again. I won't test any of the answers (don't want to mess it up again).

edit retag flag offensive close merge delete

Comments

Would I have to use a LiveUSB? :/

abadrinath gravatar imageabadrinath ( 2014-08-21 01:53:43 -0600 )edit

I used a LiveUSB and fixed it :). BTW, for those who are on UEFI, use the tool Rufus on Windows to burn your iso. It sent me to a dracut, but hey, it works! After you're in:

$ mkdir mount; mount /dev/sda8 /mount; cd /mount; vi fedora/grub.cfg; umount /mount
abadrinath gravatar imageabadrinath ( 2014-08-21 02:48:22 -0600 )edit

BTW, for people who want to know what happened, I took out the initramfs line from grub.cfg :P.

abadrinath gravatar imageabadrinath ( 2014-08-21 02:49:40 -0600 )edit

Late to the party, and totally untested (woohoo). :) I heard about an urban legend of holding the Shift key at a certain point to dismiss the timeout setting. Not like an undocumented feature (actually the GRUB documentation clearly says that this statement is false); but there's an interesting way to write a fallback mode using keystatus, so GRUB might change its timeout setting on runtime if any combination of Ctrl, Alt or Shift is pressed while the little rascal is being invoked. :)

Paulo Cereda gravatar imagePaulo Cereda ( 2014-08-21 06:56:19 -0600 )edit

My keystatus mention was actually hyperlinked, but due to the monospaced font, it doesn't appear like an hyperlink, so here's the corresponding documentation. :)

Paulo Cereda gravatar imagePaulo Cereda ( 2014-08-21 06:57:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-08-22 04:51:59 -0600

updated 2014-08-23 05:02:42 -0600

Disclaimer: Since my comment was accidentally converted to an answer, now I feel the moral obligation to write a proper answer, which ruins my original plan of doing nothing. :) Oh well.

As mentioned in one of my comments, there was an urban legend of holding the Shift key during boot to dismiss the timeout setting. Not like an undocumented feature (actually the GRUB documentation clearly says that this statement is false); but there's an interesting way to write a fallback mode using keystatus (from the amazing documentation):

Command: keystatus [--shift] [--ctrl] [--alt]

Return true if the Shift, Control, or Alt modifier keys are held down, as requested by options. This is useful in scripting, to allow some user control over behaviour without having to wait for a keypress.

Checking key modifier status is only supported on some platforms. If invoked without any options, the keystatus command returns true if and only if checking key modifier status is supported.

The idea is to make GRUB change its timeout setting on runtime if any combination of Ctrl, Alt or Shift is pressed while the little rascal is being invoked. :) Let's see how to achieve this.

First things first, I'm on my Fedora 20, with GRUB2. I do not recommend editing /boot/grub2/grub.cfg at all simply because it will be overwritten every time on a kernel update. The best approach IMHO is to use the proper place to add our custom verification, which is /etc/grub.d/40_custom:

[root@alexandria ~]# cat /etc/grub.d/40_custom 
#!/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.

The file is pretty much self-explanatory. :) We need to introduce our code after the comments. So let's write it:

#!/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.

#       \\_('<  Quack!
#        \___)

# my default timeout value will be zero
set timeout=0

# so far so good, but let's add a trick to allow us to 
# have some air in case something terrible goes on

# GRUB will check if the Shift is pressed now, and
# if so, gives us more time -- you can add any key
# combination you feel like
if keystatus --shift ; then
    set timeout=20
fi

And that's it. :) But that's not all, we need to update GRUB2 using:

[root@alexandria ~]# grub2-mkconfig -o /boot/grub2/grub.conf

or if you have an EFI machine

[root@alexandria ~]# grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

Important: As mentioned in the last paragraph of the documentation, checking key modifier status is only supported on some platforms. I tried it on a virtual machine setup and it didn't work at ... (more)

edit flag offensive delete link more

Comments

thabks., that would help. sorry I'm using a phone right now and accidentally turned your comment into an answer. if need delete it or if you have the answer tell me. :)

abadrinath gravatar imageabadrinath ( 2014-08-22 05:20:08 -0600 )edit

@hello: "answer" updated to a proper answer. Don't you dare converting it back to a comment. :P

Paulo Cereda gravatar imagePaulo Cereda ( 2014-08-22 13:16:21 -0600 )edit

Sorry for the mistake, I hate Androids with their tiny little capacitative sensitive touchscreens. The Quack! +1 and correct answer

abadrinath gravatar imageabadrinath ( 2014-08-22 19:37:36 -0600 )edit

Just one typo, the if forgot to end.

abadrinath gravatar imageabadrinath ( 2014-08-22 19:41:25 -0600 )edit

Thanks man! You're the best! I fixed the answer (just a minor typo) for you. But this time, don't worry, I won't turn it into a comment :P.

abadrinath gravatar imageabadrinath ( 2014-08-22 19:51:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-21 01:06:25 -0600

Seen: 4,210 times

Last updated: Aug 23 '14