Boot and Hardware Management
Linux Package Management
The course is part of this learning path
"Linux Installation and Package Management" is the third course in this Linux certification series. You'll learn how to control the Linux boot process, how to understand and manage disk partitions and filesystems, and how Linux uses kernel libraries to manage hardware peripherals. We'll also take a closer look at the two most widely used Linux software package management systems: dpkg and rpm.
If you have thoughts or suggestions for this course, please contact Cloud Academy at firstname.lastname@example.org.
In the previous course, we discussed how to edit the Grub menu to control the boot process. Now we're going to take a bit of a step backwards, to learn how to install Grub on a computer from scratch, and to identify and update existing Grub settings. I should note that Grub is a bit of a moving target. Not only have there been different versions, known as Grub Legacy and Grub2, that for awhile at least, existed in parallel with each other, but the configuration files and commands will vary among Linux distributions, and even from one release to the next of a single distribution.
It can be especially confusing trying to figure out what someone means by Grub2. Is it the Grub Stage 2 that we discussed earlier, the launched by either Grub stage 1 or Grub stage 1.5, or is it Grub version 2? We'll do our best to clear things up. One question did originally bother me a bit. If I've got a Linux computer running happily, why should I ever want to install or update Grub? This question is especially strong, considering how good Linux installation processes are at installing Grub automatically. In fact, many users can go for years without even being aware that Grub exists. There are two main answers to this question. First of all, there is always the possibility that you may come across a computer, especially an older application server that isn't booted very often, that's still running an older version of Grub, that is now known to have bugs. Just to be sure, we'll actually reboot the next time, it can be a good idea to install the latest version.
But by far, the most common reason people have for considering Grub updates is to figure out how to recover from a Grub configuration that's become corrupted. Did Windows wipe out your Grub? Did an update go badly? You might well be a candidate for some of what we're going to talk about here.
Managing the grub bootmanager
Okay. First of all, let's check to see if Grub is even installed on a system by querying a package manager. By a Fedora install, use RPM-Q for query, Grub2. Note how Fedora calls it Grub2 and not just Grub. If it's there, RPM will output the current version. If it's not installed, run again on Fedora, Grub2-install /dev/sda, where dev sda is the partition where you'd like it installed. Believe it or not, that is often all you'll need.
If you've already got a living, breathing version of Grub installed, but you'd like to edit the way it works, you need to know about a few files. Grub itself uses a script called Grub.cfg on Ubuntu or Fedora, or menu.lst on SUSE or Debian. These files are kept in the /boot/grub directory, except for Fedora of course, which keeps it in boot/Grub2. The first thing you'll see when you view the file, however, is that editing this file directly won't do you any good. the grub script is, in fact, generated by grub-mkconfig (or grub2.mkconfig for users of you-know-which distribution) using templates from /etc/grub.d and settings from /etc/default/grub.
To be more specific, /etc/grub.d contains files defining available operating systems and allows you to add others for your own custom menu entries. /etc/default/grub is a config file that sets the rules grub will use - like the way the grub menu should appear, how to determine which OS to boot by default, and how long the default timeout should last (before automatically launching the default OS).
So, assuming that we've made some important edit to the settings files, you can update the grub.cfg (or menu.lst) file using something like grub2-mkconfig -o /boot/grub2/grub.cfg (for Fedora, obviously).
You may sometimes come across references to a command called update-grub or update-grub2. As you can see from the contents of /usr/sbin/ on my Ubuntu system, update-grub2 is a symlink to update-grub, and update-grub is nothing more than a script that will run the grub-mkconfig file. So I guess all those rivers lead to the same ocean.
Finally, while this has nothing to do with the LPIC exam, here's a tip that can - and probably will - save your skin someday when you're under pressure. There's a wonderful free Linux package called Boot-Repair that will do just that: repair a broken boot process. I know what you're thinking: if you can't boot your computer, how are you going to load some software package? Boot-Repair thought of that, too. You can easily find simple instructions on creating a USB disk that you can plug into your comptuer and boot right into Boot-Repair. You can also launch a regular live-session of Linux, download Boot-Repair, mount your hard drive, and let Boot-Repair's magic do the rest. You'll definitely thank me for this one day.
Let's review. The current version of grub, sometimes known as grub2, is the replacement for what we now refer to as legacy grub. grub2-install (or grub-install) followed by a target partition will install grub, grub.cfg, grub2.cfg, or menu.lst - all to be found in /boot/grub - are scripts generated by files in /etc/grub.d and /etc/default/grub. the GRUB_DEFAULT setting controls which OS will boot by default (if none is selected before the timeout), other settings you can control include menu color and timeout.
David taught high school for twenty years, worked as a Linux system administrator for five years, and has been writing since he could hold a crayon between his fingers. His childhood bedroom wall has since been repainted.
Having worked directly with all kinds of technology, David derives great pleasure from completing projects that draw on as many tools from his toolkit as possible.
Besides being a Linux system administrator with a strong focus on virtualization and security tools, David writes technical documentation and user guides, and creates technology training videos.
His favorite technology tool is the one that should be just about ready for release tomorrow. Or Thursday.