CST8207: GNU/Linux Operating Systems I |
Lab Worksheet 13 |
Boot Process and GRUB |
This
Lab Worksheet contains some practical examples that will prepare you
to complete your Assignments.
You do not have to hand in this Lab
Worksheet. Make sure you complete the separate Assignments on time.
Quizzes and tests may refer to work done in this Lab Worksheet; save
your answers.
You must have your own Fedora 12 virtual machine (with root permissions) running to do this lab. You cannot do the lab on the Course Linux Server because you do not have root permissions on that machine.
Use
the on-line help (man
command) for the commands listed below for more information.
The
Class Notes also cover the use of these commands and
the syntax of GRUB pathnames.
df – display space available (optionally inodes available) on all mounted file systems
grub
– GRand
Unified Bootloader (legacy version
0.9x - not
the Version 2 GRUB numbered 1.9x)
The man page is useless. See
this instead:
http://www.dedoimedo.com/computers/grub.html
mount – display a list of all mounted file systems, including devices, types, and mount points
uname – display system name, kernel release and version number, machine, processor, and O/S type
/etc/inittab – documentation on Run Levels; contains the default Run Level
/boot/grub/ – directory containing GRUB configuration files, especially the main GRUB configuration file named (in legacy GRUB 0.9x) grub.conf or menu.lst
/proc/cmdline – a copy of whatever was on the GRUB kernel line at boot time
Since this lab requires you to reboot your Linux virtual machine multiple times, you will find it easier to open this lab document in Open/Libre Office in your Windows host O/S, not inside Fedora where you will have to keep closing it to reboot (and can't read it while you are doing so). Use OO not MSWord!
Take a snapshot of your virtual machine before you begin this lab so that you can recover if needed.
Changing the boot process requires super-user (root) privileges. Use root throughout this lab.
One question in this lab uses the second hard disk attached to your virtual machine in an earlier lab. If you do not have this second disk, you may go back to the previous lab and create one. Verify that the output of fdisk -l /dev/sdb shows the five partitions from the previous labs (1,2,3,5,6).
The Linux kernel and associated files are stored under directory /boot on Linux. The /boot directory may be a subdirectory of the ROOT file system, or it may be its own mounted BOOT partition and file system. Fedora 12 uses a separate BOOT partition, which means GRUB pathnames and Linux pathnames differ.
Give
a two-command bash shell pipeline
that will first display the list of all mounted file systems and
then pipe it into a command that displays only
the line(s) containing the string '/boot'
:
____________________________________________________________________
Give
the one line of output
of the above two-command bash shell pipeline:
____________________________________________________________________
Give
the equivalent GRUB partition name (in parentheses) of the above
mounted /boot
file
system:
____________________________________________________________________
Your Linux kernel has a version number, as in "What version of the kernel are you running?". Unfortunately, the command that displays the kernel version number calls it a kernel release number, because it uses the name version to stand for the kernel compile date. Know that version means release in the documentation for this command. When asked for the "kernel version", interpret that to mean the "kernel release" number.
Give
the command line
that displays only
the version (release) of the Linux kernel are you running:
____________________________________________________________________
Record
your kernel version
number (about 26 characters; begins with the digit 2):
____________________________________________________________________
GRUB is a shell-like utility that has many built-in commands. See the Class Notes for help.
Do GRUB pathnames include the /boot directory prefix on Fedora 12? ____________
Why? ___________________________________________________________________________
Entering and Leaving the GRUB Shell
Start the command-line GRUB shell by typing grub at the root (super-user) BASH shell command prompt. Type help at the grub> prompt to see a partial list of GRUB shell commands. What GRUB shell command exits the GRUB shell and returns you to the BASH prompt? ____________
Finding pathnames
Start GRUB. Enter the following GRUB shell command to find on which disk partition your kernel pathname is located. Where you see Xs, replace those with information from your kernel version number. If you get "File not found", check your typing and permissions and try again until you find it:
grub> find /vmlinuz-2.X.XX.X-XXX.fc12.i686.PAE
Record the actual pathname you used: _________________________________________
Give the GRUB partition output of the above GRUB shell find command: _________________
Look for the pathname /grub/grub.conf and record its GRUB partition: _____________
Displaying Text Files
Use
the GRUB shell cat
command to display the contents of
file /grub/device.map
and record the last line of the file here:
_________________________________________________
Hint:
You will need to find
which partition
the file is on, and prefix
the file name with that partition.
Setting a default (root) disk and partition
The GRUB shell root command can set a disk partition device prefix that will be used in front of pathnames so that you don't have to type the partition name at the start of GRUB pathnames. Type the root command without any arguments and record the current default device name prefix (a floppy disk - not very useful): ____________________________________________________
Use the root command to set the the default partition to be the same as the partition of the grub.conf and device.map files, above. Enter that root GRUB command line here: ____________________________________________________________________
Having set a root device partition prefix, now enter the shortest GRUB shell command line that will display the file /grub/grub.conf: _________________________________________
Confirm
that this command works without needing a partition prefix: cat
/grub/device.map
If it doesn't work, redo the
root
command with the correct partition name prefix.
Disk Information
What GRUB shell command line will display the geometry (partitions) of the first disk? ____________________________________________________________________
Paste the four-line output (showing two partitions) of
the above GRUB shell geometry
command:
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
What GRUB shell command line will display the geometry (partitions) of the second disk (the disk you added in a previous lab)? _______________________________________________
Paste the six-line output (showing four partitions) of
the above GRUB shell geometry command:
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
Exit the GRUB Shell and return to your BASH shell prompt. Command used: _____________
The legacy GRUB configuration file is named /boot/grub/grub.conf on Fedora. It is named menu.lst on some other distributions of Linux, and a symbolic link in the same directory on Fedora gives it both names. Remember to snapshot your virtual machine and/or back up this file before you change it!
Use ls -li on the
absolute pathname of the above symbolic link and give
the output here:
____________________________________________________________________
____________________________________________________________________
If you have not already done so, edit (e.g. using vi/vim) the GRUB configuration file as follows:
Change the timeout from 0 to 30 so that GRUB waits 30 seconds for you before booting.
Comment-out the hiddenmenu command by putting # at the start of the line to disable it.
Save all your work, close your programs, and then reboot your virtual machine.
When the boot process begins, if you correctly disabled the hiddenmenu command in GRUB, you will go directly to the GRUB menu where you should see a one-line list of Fedora systems to boot and at the bottom a 30 second countdown in progress. Interrupt the countdown by pressing an arrow key. (If you didn't disable hiddenmenu, when the countdown is interrupted your system should display the one-entry GRUB menu.)
Now, just as the GRUB menu instructions tell you, press just the single letter 'a' to temporarily (for this boot only) edit the kernel command line arguments but do not press the [Enter] key yet!
After pressing 'a' you will see a line that ends with rhgb quiet. These are both kernel arguments: rhgb = RedHat Graphical Boot – gives a GUI mode booting screen with most of the information hidden while the user sees white and blue bands growing from left to right as Linux boots. quiet = hides the majority of boot messages before rhgb starts.
On this kernel command line you should now backspace over the two words rhgb quiet to erase those two kernel options for this boot only and press [Enter] to continue booting using the new kernel option setting. The changes you make here are temporary for this boot only and are not saved.
Watch the screen during the boot process and notice all the boot process information that is displayed on the screen and no longer hidden. Note the huge difference made by disabling the graphics screen and enabling all system messages. You can diagnose many problems by viewing the full boot message list.
Does using 'a' to change the kernel boot options make a change that affects every reboot? ____
Does using 'a' to change the kernel boot options also change the kernel options saved in the GRUB configuration file on disk? ____
To change a forgotten root password, you can boot your system in a restricted single-user mode that does not start many system daemons and goes directly into a root shell prompt. The system should not be left in single-user mode; many things are not started. You may not even be able to log-in remotely in single-user mode.
To go single-user, reboot the system, enter the GRUB menu, edit any kernel line and remove the rhgb quiet options (as you did in the previous section) and replace them with the single-user option word single on the end of the kernel line and boot that modified entry. The system will come up in black-screen text console mode with a root shell prompt. You can perform any root function, including changing passwords.
Reboot
in single-user mode exactly as given above and record here the last
two lines you see on the black terminal console screen. (The last
line is the root
prompt.) You will have to re-type the two lines; cut and paste will
not work in single-user console mode:
___________________________________________________________________
___________________________________________________________________
To leave single-user mode and start the system in multi-user mode, simply exit the console root shell. This will exit the single-user shell and allow the system to come up to the default Run Level.
The first few lines of the GRUB configuration file give options that affect GRUB. In the bottom half of the file, every title keyword starts a paragraph of lines (four, in most cases) that defines a "boot menu entry". The Fedora 12 file only contains one boot menu entry to start. (Software updates may add more, but you were told not to install any software updates.) We will now add a second boot menu entry. (Where strings are quoted below, do not enter the quotes. The quotes are not part of the string.)
Back-up the GRUB configuration file somewhere safe, so that you can restore it if you make any errors.
In the GRUB configuration file, what keyword begins a "boot menu entry"? _______________
How many lines are in a "boot menu entry" in your own configuration file? _____________
Give the number of lines, words, characters in the GRUB configuration file: ________________
Edit the GRUB configuration file on disk to make these on-disk permanent changes:
On the long line that begins with kernel, remove the two words at the end of the line: “rhgb quiet”. This will allow you to see the kernel boot messages, which are essential to diagnose boot-time problems. (Save the file and confirm that the saved file has two fewer words in it.)
Using four or five command letters in vi/vim, duplicate twice the first and only four-line boot menu entry in the file. Duplicating it twice will add eight more lines to the file, duplicating the first (topmost) existing four-line boot menu section two times to create three identical sections of four lines. The four duplicated lines must each start with a title line. You must have three boot menu entries in total. (Hint for vim: Yank four lines and paste them twice.)
Insert the words "single user" in front of "Fedora" in the title line of the second (middle) boot menu entry. Next, add the correct keyword to this second boot menu entry that will enable single-user mode, just as you did temporarily in a previous section. You make it permanent here.
Insert the words "text only" in front of "Fedora" in the title line of the third (last) boot menu entry. Next, add the digit to this third boot menu entry that will enable the system to enter the full multi-user mode Run Level without X11 graphics. Record the Run Level ________
Save the file. It should have gone from 17 lines to 25 lines because you added 8 lines.
Give the new number of lines, words, characters in the GRUB configuration file (you should see exactly eight more lines compared with the unmodified file): ___________________
Use
grep
to confirm that the new file contains three
different title
lines and paste the three title lines here:
__________________________________________________________
_________________________________________________________________
_________________________________________________________________
Preview the nw GRUB configuration file using the command-line GRUB shell inside Linux
Preview the new configuration file using the command-line GRUB shell inside Linux as follows:
At the Linux shell command line, start the GRUB shell (as root) and use the configfile command inside GRUB to load your changed configuration file. As a file name argument to configfile you will need to specify both the partition and the pathname to the GRUB configuration file you edited above. The errors Invalid device requested and/or Cannot mount selected partition mean you didn't get the partition name correct. The error File not found means you didn't get the pathname correct. The error Selected disk does not exist might mean you don't have enough permissions - read all the words. Keep trying until you get it right. Enter the correct GRUB filename you used to load the file: ___________________________________
When you get the configfile command right, you will see the message: "Press any key to enter the menu". When you see that message, use [Enter] to enter the menu (other keys will not work). (If you correctly disabled the hiddenmenu command in GRUB, you will go directly to the menu without needing to push [Enter].)
Underneath the displayed banner "GNU GRUB version 0.97" you should see three menu entries: the original Fedora menu item and your two additional menu items. If this is not true, break out of the GRUB shell (see below), restore the GRUB configuration file from your saved backup copy, and redo the edits to make it true. You must see three menu entries before continuing:
0: Fedora (2.6.31.5-127.fc12.i686.PAE)
1: single user Fedora (2.6.31.5-127.fc12.i686.PAE)
2: text only Fedora (2.6.31.5-127.fc12.i686.PAE)
Break out of (interrupt) the GRUB shell using ^C (control-C) to return to the BASH prompt. (You cannot actually select and run either of these menu entries without rebooting. If you try, you will get a harmless segmentation fault error from the Linux kernel that you try to load.)
Run the new GRUB configuration file
When you see all three menu entries, as shown above, you are ready to try your new GRUB menu. Reboot the Virtual Machine and interrupt the GRUB countdown to enter the GRUB menu, as you did before. This time, the menu should have three entries. If the menu does not have three entries, go back and try the edits again. Here is a graphic showing what you should see:
Try
the second menu
entry to boot single-user
(Maintenance Mode).
You should boot up to a black text-only screen with a root
shell prompt. This is where you would reset the root
password, if you forget it.
Type "shutdown
-r now" at the
root
prompt to reboot again. (If you exit
the single-user root
shell prompt, your system will continue booting to its default Run
Level.)
As you reboot, enter the GRUB three-item menu again and try the third GRUB menu entry to boot text-only (no X11 graphics). You should boot up to a black text-only screen with a login prompt. Log in as the root account and type telinit followed by the Run Level number that will enable full X11 graphics. Your system will proceed to display the usual GUI graphical login screen.
At the graphical login screen, log in as your userid, become the root user, and run telinit followed by the Run Level number that will reboot the system to the GRUB menu again.
In the GRUB menu, use the arrow keys to move down to select and highlight the second menu option (single user) but do not push the [Enter] key yet:
This time, use the single letter 'e' key to edit the entire menu item. You will open another menu showing all three lines in the boot menu. You can view or edit any of the three lines before booting.
Use the arrow keys to move down to the kernel line and again type the single letter 'e' key to edit that kernel line. You will be sent to the end of the kernel line, where you can confirm that the options “rhgb quiet” have been deleted and replaced with the single-user option keyword. (If this is not true, cancel the edit, continue the boot process, and redo this exercise to fix it.) Give the last option (the single-user option) visible on the kernel line: _______________________
At the end of the kernel line, replace the single-user option keyword with the nonsense word "doghouse" and and then push [Enter] to accept the changes. You will return to the previous three-line menu. Follow the instructions on this menu to boot the system using your changed menu item. What letter boots the system from this menu? ______________________________
The system should boot multi-user with the usual graphical login screen.
At
the graphical login, log in to the system and copy here the output
of:
cat /proc/cmdline
_________________________________________________________________
_________________________________________________________________
Describe what /proc/cmdline contains: _________________________________________
Take a snapshot of your working system (three-item menu) before you try to set passwords in GRUB.
Give the number of lines, words, characters in the GRUB configuration file: ________________
Add the following GRUB option line near the beginning of the GRUB configuration file, anywhere after the comment lines and before any title sections: password sesame
Save the file and give the new number of lines, words, characters in the file (you should see exactly one more line and two more words): ______________________________________
In the command line GRUB shell, load and preview the modified configuration file (as you did before) using the Linux command-line version of GRUB (do not reboot!):
After loading the GRUB configuration file, press [Enter] when you see the message: Press any key to enter the menu (If you correctly disabled the hiddenmenu command in GRUB, you will go directly to the menu without needing to push [Enter].)
At the bottom of the screen starting with the banner "GNU GRUB version 0.97" you should see instructions on using a password with “p”. (If this isn't true, you need to break out and fix the file to ask for a password, first.) You should see this paragraph:
Use the ^ and v keys to select which entry is highlighted.
Press enter to boot the selected OS or 'p' to enter a
password to unlock the next set of features
Type the seven characters psesame (no spaces) and then push [Enter]. (You are typing the command "p" immediately followed by the password with no spaces between.)
The instructions should change to let you use all the GRUB edit commands. If you see "Failed!", you either typed the password command incorrectly (type psesame) or you have entered the wrong password in the GRUB configuration file. Push [Enter] and try the password again, or break out and fix things so that the password works before continuing. Make sure it works at the command line before you reboot the system!
Once you have verified that the password works using GRUB at the shell inside Linux, break out of (interrupt) the GRUB shell using ^C (control-C) to return to the BASH prompt.
Reboot your system and interrupt the GRUB countdown to display the three-item GRUB boot menu, as before. Note that the 'a' and 'e' commands do not work in this password-secured boot menu. Notice also the new instructions at the bottom of this menu, telling you how to enter a password to unlock more features. Follow the instructions to unlock the menu using the sesame password you specified, above.
The unlocked menu now shows all the GRUB commands again. Type the single letter 'c' to open the GRUB shell. This is the boot-time version of the GRUB shell you used at the command line earlier. The difference now is that the machine is running only the GRUB shell. No operating system has been found and loaded yet. GRUB is running stand-alone without any operating system.
TAB completion in GRUB (stand-alone version)
This boot-time version of the GRUB shell has working TAB command, device, and file name completion. (The command-line version of GRUB also should do this, but is broken under Fedora 12.)
Type the letter 'g' and push TAB - GRUB will complete the command geometry for you.
After GRUB types geometry for you, continue by typing an open parenthesis and again push TAB - GRUB will tell you what possible disks you have: geometry (<TAB>
Continue and type hd0 after the parenthesis and again push TAB - GRUB will add a comma.
Continue and push TAB again (after the comma) and GRUB will list all the partitions on the disk hd0 and it will look like this: geometry (hd0,<TAB>
Type ^U (control-U) to erase the line, leaving only the GRUB prompt.
Type root to display the default device. That device name is: ______________________
At the prompt type ca and push TAB - GRUB will complete the command name cat for you.
After GRUB types cat for you, continue by typing a forward slash (the start of a pathname argument to cat) and push TAB - GRUB will list all the possible file name completions for you, starting at the ROOT on the default device and it will look like this: cat /<TAB>
After the slash, type grub/g and push TAB - GRUB will complete the path /grub/grub.conf for you. Let the computer do your typing for you! Use the TAB key!
Push the Escape (Esc) key to return to the GRUB boot menu, pick the first line to boot, and log in.
The password in the GRUB configuration file is visible as plain text. This is not very secure. You can use fully encrypted passwords, using the built-in GRUB shell command md5crypt to encrypt them:
From the command line, start the GRUB shell and run the GRUB command md5crypt (no options or arguments). Respond to the password prompt with a new six-character password: foobar and record the encrypted value here (cut and paste!): __________________________________
In a second
terminal window, edit the GRUB configuration file and replace
the password
line you added earlier with this new line:
password
--md5 encrypted_password
Replace encrypted_password
with the encrypted value you recorded, above. (Cut and
paste!) Save the file. (Check the file; make sure you have the same
number of lines in the file as before you started.)
In the command line GRUB shell, load and preview the modified configuration file (as you did before):
After loading the configuration file, press [Enter] when you see the message: Press any key to enter the menu (If you correctly disabled the hiddenmenu command in GRUB, you will go directly to the menu without needing to push [Enter].)
At the bottom of the screen starting with the banner "GNU GRUB version 0.97" you should see instructions on using a password with “p”. (If this isn't true, you need to break out and fix the file to ask for a password, first.) Type the seven characters pfoobar (no spaces) and then push [Enter]. (You are typing the command "p" immediately followed by the password with no spaces between.)
The instructions should change to let you use all the GRUB edit commands. If you see "Failed!", you either typed the password command incorrectly (type pfoobar) or you have the wrong encrypted password in the GRUB configuration file. Push [Enter] and try the password again, or break out and fix things so that the password works before continuing. Make sure it works at the command line before you reboot the system!
Once you have verified that the password works using GRUB at the shell inside Linux, break out of (interrupt) the GRUB shell using ^C (control-C) to return to the BASH prompt.
Reboot your system and interrupt the GRUB countdown to display the three-item GRUB boot menu, as before. As you did before, verify that the password works at boot time as well.
If you have problems with a forgotten GRUB password locking you out of rebooting, you will need to restore the working snapshot of your Virtual Machine, or alternatively, boot the Virtual Machine into rescue mode with a Linux Install CDROM, and edit the file “/sysimage/boot/grub/grub.conf” to remove the password.
Page |
©2012 Algonquin College Shawn Unger, Todd Kelley, Ian Allen |
Version 13 |