|GRUB2 How To Boot From CLI Mode|
|GNU GRUB's Command Line Interface
(CLI) is one of GRUB's most useful and powerful features. |
GNU GRUB is a boot loader but it is also something close to a miniature operating system in its own right. GNU GRUB can take a rich variety of commands and provide useful feedback to the user. GRUB's CLI Mode is one feature that sets GRUB head and shoulders above all other boot loaders or boot managers.
|GNU GRUB is a work in progress and the information in this website is incomplete and may be wrong and/or out of date. Please consult the official GNU GRUB 1.98-r2692 manual.|
This web page is about how to use GNU GRUB's Command Line Interface Mode to boot from.
We will all need to know how to use the GRand Unified Bootloader's Command Line Interface sooner or later. There are times when we cannot just boot from the menu in the normal way. It could be because we just moved our operating system to a different disk with a dd command. Maybe we re-installed some other operating system and it has taken control of our first hard disk's MBR with an ordinary boot loader. Hopefully, we made a GNU GRUB Rescue CD, USB or floppy disk beforehand so we can boot our operating system easily providing we know the right commands.
You did make your own GRUB2 Rescue Disk didn't you?
If you forgot to make your own GRUB2 Rescue disk, 'shame on you', - but ... you're still not totally out of luck.
You can download a Super Grub2 Disk (with GRUB2 in) it from Super Grub Disk - Super Grub Disk.
Super Grub2 Disk is also included in Parted Magic Live CD, so if you have Parted Magic Live CD you can use that for a rescue disk, Parted Magic Live CD.
How To Enter GRUB's CLI MODE
Your computer should automatically boot into GRUB's Command Line Interface when there is no /boot/grub/grub.cfg file present, or if GRUB can't find a grub.cfg file.
Menu mode is for wimps. Real GNU Linux users know how to use GNU GRUB's Command Line Interface for booting with in an emergency, and for all kinds of special purposes.
It's easy to learn how to use GRUB from the command line, and it should only take a few minutes for most people to get to understand the basics of it. If your computer boots to a GRUB Menu, you can switch into CLI mode instantly by pressing the 'c' key on your keyboard any time you like. To return to your menu, just press 'Esc'.
Summary - in case you're already an expert and you're in a hurry!
There are just three commands necessary for booting a GNU-Linux operating system with GNU-GRUB.
The exact details to include in these commands will vary between one computer and another. If you don't understand the meaning of the above commands, read further down this page for a verbose explanation.
List of Commands for GRUB's Command Line
In case you haven't already seen it, there's a page in this website containing a list of commands we can use, GRUB2 CLI Mode Commands. It's incomplete but you may refer to it while we're waiting for the official GNU GRUB Manual to be completely re-written.
Use the help command
If you have more than one computer available, you can look at this website with one computer while you're working with the other one. I presume most people will be doing that.
If you're stuck somewhere with no internet or there's no other computer handy, you can use GRUB's built in help simply by typing the help command. For help on the help command, type help help.
For more info see: help command. The information in this website mostly came from the help command.
How to turn off a splashimage
If you have a splashimage in the background, it can make some of the text on your screen difficult to see properly. You might want to turn that off and revert to a plain background while you're in CLI Mode.
To turn off your background image, just type the background_image command without specifying any arguements.
Changing Your Text Color
If you still can't see your text, try using the set command to change your menu colors, set command.
TIP: 'Tab completion' is another of GNU GRUB's powerful features. Instead of typing a complete command or file name, we only need to type the first three or so letters, then when we press the 'Tab' key on our keyboard, GRUB will intelligently guess what we're trying to type and complete the rest of the command or file name for us. This is not only helpful for saving the work of typing and preventing spelling errors. It can also be used craftily for finding out what devices GRUB can see in a computer and what files they contain. It's a good idea to get into the habit of using tab completion whenever possible while we're using GRUB in CLI mode.
Taking A Look Around
1) You can use the ls command to take a look around and find out what disks are available, ls command.
2) If you gave your the took the time to set file system labels in your computer, you can use the search command with the -l option to look for your operating system by name, search command.
3) You can also use the chainloader command and the 'tab' key to get a list of disks and then a list of partitions in any of your disks, chainloader command.
How To Boot An Operating System Directly
Direct kernel booting is the most reliable way to boot a GNU LINUX operating system.
If you're doing this from a rescue disk, it doesn't matter if you have GRUB in a CD, USB or some other hard drive partition or whatever, you can bypass all of the possible trouble spots by booting the Linux kernel directly.
This method will work even if the boot loader part of the MBR has been corrupted or overwritten by some other boot loader. This method will also work even if you moved your entire Ubuntu operating system to a different partition with a dd command and haven't updated your grub.cfg yet. It will work if there's a mistake on your grub.cfg, or if boot loader files are corrupt or missing. It will even work if GRUB wasn't installed or has been completely deleted from the operating system you're trying to boot.
As far as I know, GNU GRUB does not boot Windows directly, see How To Chainload and Boot if you're trying to do that.
There are two ways of booting a Gnu-Linux operating system (kernel) directly using GNU GRUB.
One is by using symlinks, (aka 'shortcuts') to the kernel and initrd files.
The other way is by typing in the precise file path and file name for exactly the kernel and initrd you want to specify.
First, we'll try booting by the symlinks because that's the easiest.
We need two vital bits of information before we can perform a direct (kernel) boot.
(i) the location of a kernel and intird.img or symlinks to a kernel and initrd.img files.
(ii) the location of /sbin/init, which will be in the operating system's 'root' file system.
A fast way to find that information will be to use the search command, see search command for more info.
In the example below I typed the search command with the -f option, ('f' for 'file'), and I searched for 'vmlinuz', which is the name of the symlink to our Linux kernel in Ubuntu.Then I made a search for /sbin/init.
TIP: It's also possible to boot with a kernel that's even located in some other disk, such as a USB flash memory drive if you need to for some reason.
The next command we'll use will be the linux command, for loading a kernel,
After the path and name of the kernel or symlink is where we put in kernel options.
The most important kernel option is the root=(path to our /sbin/init), which we found with our search command a few minutes ago. The difference is, here we have converted it to Linux type device numbering. (hd0,1) is equivalent to /dev/sda1.
We can optionally add more kernel options after the root= option. I suggest the same ones we see in our grub.cfg files, 'ro','quiet' and 'splash' if you like.
Other kernel options may be wanted or needed for special purposes, see Common Boot Options - Ubuntu Community Docs, and Kernel Parameters, www.kernel.org for a complete list.
The hard part's done, now just the initrd command,
Finally, the boot command,
This command is implicit (implied) at the end of grub.cfg menu entries, but when we're using GRUB from the Command Line we need to use the boot command to tell GRUB when we're ready to boot.
Press your Enter (or Return) key, and your operating system should boot!
The proper direct kernel boot is the same thing as direct booting via symlinks except we type in the exact filepath and filenames of the specific kernel and initrd.img files, like this,
Now you may have noticed that the commands we use in CLI mode are exactly the same commands we have in our grub.cfg files which GRUB reads and executes automatically. That brings us to our next command, the configfile command.
How To Configfile and Boot
The configfile command tells GRUB to read commands from a specified configuration file.
We can only use the config file command if the file contains commands our GRUB will be able to understand.
If we're using GRUB2 and the config file we load contains GRUB2 commands it should be okay. It's no use trying to load a file full of LiLo commands or Legacy GRUB commands or commands for any other boot loader than GRUB2. Maybe a newer version of GRUB2 will boot an older version, but things might not work the other way around.
Providing the commands in a GNU - Linux operating system's GRUB2 grub.cfg are correct, and they're compatible with the version of GRUB2 we're using, we can use the configfile to load the file and make use of the commands it contains.
Here's an example,
The configfile command will bring up our entire GRUB Menu for whatever operating system happens to be associated with the grub.cfg file we directed GRUB to open.
Now we can select any title from that GRUB Menu and we should be able to boot an operating system or at least run the commands that are associated with that menu title.
An important thing to remember is it's still the same GRUB we started with will be doing the work of booting, and not the operating system's GRUB.
That's the reason why the use of the configfile command is pretty much restricted to only other operating systems with the same version of GRUB as we have, or the same GRUB as in the rescue disk we're using.
We could run into trouble if the GRUB2 we're using in our rescue disk is an older version than the operating system's and doesn't accept the same commands as the operating system's version of GRUB2.
We can't use the configfile command to bring up a menu.lst from GRUB Legacy either, again because the commands will be all different.
What we can do though, is load a file with some other file name than grub.cfg. - such as a backup copy of grub.cfg, if you were careful enough to make one before the last changes you made to your grub.cfg file.
If we used grub-mkconf with the -o option and typed a different path and file name than /boot/grub/grub.cfg we'd be able to find that file and load it instead of our regular grub.cfg file. It could be any file we made ourselves. The other file still needs to have valid GRUB commands in it, or commented lines, which will be compatible with the GRUB we're reading it with.
We can't use the configfile command to boot another boot loader either, it just doesn't work that way.
The chainloader command is the one we use for booting another boot loader.
How To Chainload and Boot
The chainloader command is most commonly directed at either a hard disk's master boot record or the boot sector of a partition.
Actually, we can chainload a file too and there's nothing wrong with doing that if it works, but thats not as well known as chainloading a sector.
If there's code written in the MBR or partition boot sector pointing to a boot loader then we can get GRUB to boot the other boot loader. GRUB can boot just about any other boot loader by chainloading. The other boot loader then takes over and does the booting. We can boot other Gnu - Linux loaders like LiLo or GRUB Legacy, GAG Boot Manager, and we can even boot foreign proprietary boot loaders too. In fact, chainloading is the only way to boot a Microsoft Windows system from GNU GRUB.
There needs to be code in the MBR or boot sector we're trying to chainload for the chainloader command to do any good.
Windows does install code in both the hard disk's MBR and also in the Windows partition boot sector, so it's normally easy to chainload a Windows installation.
We can chainload any disk by the MBR or any partition by its boot sector.
Here's an example of a chainloader command in action,
I could try booting the MBR of any of these disks with the chainloader command.
If I 'm not sure which hard disk I want to boot, or if the operating system I want to boot isn't bootable from and loader installed in the MBR, I could chainload a partition boot sector instead.
First I'll use the 'tab' key again to take a look at my partitions in (hd0), my first hard disk.
I will type: chainloader (hd0, ...and press my 'tab' key.
I have a Windows operating system in (hd0,1), I could chainload that if I wanted to.
I could chainload the other GRUB partition, (hd0,3) and boot from that GRUB.
The unknown file system is probably a swap area.
I'll try chainloading my old Jaunty Jackalope installation in (hd0,5), I remember I have installed GRUB to the partition boot sector in Jaunty Jackalope a while back, so I should be able to chainload it okay.
I'm now using Jaunty Jackalope's GRUB to boot with and I can boot any item in Jaunty Jackalope's GRUB menu. If I had GRUB Legacy in Jaunty Jackalope and I press my 'c' key from Jaunty's GRUB Menu I would need to be prepared to revert to commands for GRUB Legacy's Command Line Interface. GRUB's Command Line Interface.