Add console/text booting mode to grub menu

In my research, there are two ways to do this:

Method 1

Hack 10_linux script in /etc/grub.d/ and insert generation codes for text booting menuentry

Advantages:

  • Generates text booting menuentry for all installed kernel versions
  • Takes care of new or redundant menuentries when you install/purge kernels

Downsides:

  • Requires deep understanding of shell scripting
  • The script source file may vary from one grub version to another
  • Edits need to be redone if grub package updates overwrite the modified script

Method 2

Use designated script for adding custom grub menuentry in /etc/grub.d

Advantages:

  • Easiest and least complicated
  • No chance of being overwritten so you do it only once

Downsides:

  • Only if you want each of your installed kernel versions to have text booting menuentry:
    • Lots of work and harder to maintain
    • Leaving behind redundant menuentries when you purge old kernel versions

In this short step, I'm going with method #2 since it's the easiest to explain here and we'll be creating text booting menuentry only for the latest kernel image that you use.

  1. The first thing that you need is the already generated menuentry for your latest kernel. We are going to copy and use it as basis for our custom menuentry, with a little alteration. For that, you need to look in your /boot/grub/grub.cfg file. Locate the first menuentry stanza that points to the latest kernel on your Ubuntu. If you're dual booting with other linux distros, pay extra attention so you wouldn't mix it up with their menuentries.

  2. Once you found it, copy the entire menuentry stanza and paste it into /etc/grub.d/40_custom file. It may look like one below. Let's use this as example:

    menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-a4e6d610-122e-42e2-8497-39eae02816e8' {
      recordfail
      load_video
      gfxmode $linux_gfx_mode
      insmod gzio
      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  a4e6d610-122e-42e2-8497-39eae02816e8
      else
        search --no-floppy --fs-uuid --set=root a4e6d610-122e-42e2-8497-39eae02816e8
      fi
      linux   /boot/vmlinuz-3.8.0-31-generic root=UUID=a4e6d610-122e-42e2-8497-39eae02816e8 ro   quiet splash $vt_handoff
      initrd  /boot/initrd.img-3.8.0-31-generic
    }
    
  3. Now here's few things that you need to edit in this stanza before you can save the file:

    • The menuentry title. Change 'Ubuntu' in menuentry line to 'Ubuntu (text mode)'
    • Path to vmlinuz file in linux line. Substitute /boot/vmlinuz-3.8.0-31-generic with /vmlinuz grub boot parameter at the end of linux line. Substitute quiet splash with text
    • Path to initrd image in initrd line. Substitute /boot/initrd.img-3.8.0-31-generic with /initrd.img
  4. Reason why we do the substitutions in both vmlinuz and initrd lines is to take advantages of the symlinks placed in / which points to their latest version in /boot dir so that our custom menuentry can always point to the most recent kernel and won't need to be changed if a new kernel is introduced.

  5. That's it. Execute sudo update-grub to generate the custom menu and you're done.