In this chapter, we will cover:
Downloading CentOS and confirming the checksum on Windows or OS X
Creating USB installation media on Windows or OS X
Performing an installation of CentOS using the graphical installer
Running a netinstall over HTTP
Installing CentOS using a kickstart file
Re-installing the boot loader
Troubleshooting the system in rescue mode
Getting started and customizing the boot loader
Updating the installation and enhancing the minimal install with additional administration and development tools
This chapter is a collection of recipes that covers the basic practice of installing the CentOS 7 operating system. The purpose of this chapter is to show you how quickly you can get CentOS up and running whilst enabling you to customize your installation with a few 'tricks of the trade' thrown in for good measure.
In this recipe, we will learn how to download and confirm the checksum of one or more CentOS 7 disk images using a typical Windows or OS X desktop computer. CentOS is made available in various formats by HTTP, FTP, or the rsync protocol from a series of mirror sites located across the world or via the BitTorrent network. For downloading very important files from the Internet, such as operating system images, it is considered best practices to validate those files' checksum, in order to ensure that any resulting media would function and perform as expected when installing. This also makes certain that the files are genuine and come from the original source.
To complete this recipe, it is assumed that you are using a typical Windows-based (Windows 7, Windows Vista, or similar) or OS X computer with full administration rights. You will need an Internet connection to download the required installation files and also need access to a standard DVD/CD disk burner with the appropriate software, in order to create the relevant installation disks from the image files. For the purpose of this recipe, it is assumed that all the downloads will be stored on Windows in your personal
C:\Users\<username>\Downloads folder, or if using an OS X system, in the
Regardless of the type of installation files you download, the following techniques can be applied to all the image files supplied by the CentOS project:
Let's begin by visiting http://www.centos.org in a web browser and navigate to the button link Get CentOS Now. Then click the link list of the current mirrors in the text.
The mirror sites are categorized, so from the resulting list of links, choose a mirror that is geographically near your current location. For example, if you are in London (UK), you can choose a mirror from EU and United Kingdom. Now choose a mirror site by selecting either the HTTP or the FTP link.
Having made your selection, you will now see a list of directories of all the available CentOS versions. To proceed, simply click the appropriate folder that reads
7. Next, you will see an additional list of directories, such as
cloud, and so on. We proceed by choosing the
CentOS 7 currently only supports the 64-bit architecture, so browse to the only directory available labeled
x86_64, which is a container for the 64-bit version.
You will now be presented with a series of files available for download. Begin by downloading a copy of the valid checksum result identified as
If you are new to CentOS or are intending to follow the recipes found throughout this book, then the minimal installation is ideal. This contains the least amount of packages to have a functional system, so choose the following (
XXXXis the month stamp of this release):
On a Windows-based system only (on Mac, this tool is already available in the system), visit http://mirror.centos.org/centos/dostools/ in your browser and download the program
Now on Windows, open the command prompt (typically found at Start | All Programs | Accessories | Command Prompt) and type the following commands into the window that will open (press the Enter key at the end of all the lines):
cd downloads dir
On OS X, open the program Finder | Applications | Utilities | Terminal, then type the following commands (press the Enter key at the end of all the lines):
cd ~/Downloads ls
You should now see all the files in your download folder (including all the downloaded CentOS installation image files, the md5sum.txt file and on Windows, the md5sum.exe program).
Based on the file names shown, modify the following command in order to check the checksum of your downloaded ISO image file. On Windows, type the following command (change the
XXXXmonth stamp accordingly):
On OS X, use instead:
Press the Return key to proceed and then wait for the command prompt to respond. The response is known as the MD5 sum and the result could look like the following:
Now look at the the sum and compare against the relevant listing for your particular image file in
md5sum.txt(open in a text editor). If both the numbers match, then you can be confident that you have indeed downloaded a valid CentOS image file. If not, your downloaded file is probably corrupted, so please restart this procedure by downloading the image file again.
When you have finished, simply burn your image file(s) to a blank CD-ROM or DVD-ROM using your preferred desktop software, or create a USB installation media from it, as we will show you in the next recipe in this chapter.
The act of downloading a CentOS installation image is just the first step towards building the perfect server. Although this process is very simple, many do forget the need to confirm the checksum. In this book, we will work with the minimal installation image, but you should be aware that there are other installation options available to you, such as NetInstall, DVD, Everything, and various LiveCDs.
In this recipe, we will learn how to create a USB installation media on Windows or OS X. Nowadays, more and more server systems, desktop PCs, and laptops get shipped without any optical drive. Installing a new operating system, such as CentOS Linux using USB devices gets essential for them as no other installation option is available, as there is no other way to boot the installation media. Also, installing CentOS using USB media can be considerably faster than using the CD/DVD approach.
Before we begin, it is assumed that you have followed the previous recipe in which you were shown how to download a minimal CentOS image and confirm the checksum of the relevant image files. It is also assumed that all the downloads (including the downloaded ISO file) are stored on Windows in your
C:\Users\<username>\Downloads folder or if using a OS X system, in the
/Users/<username>/Downloads folder. Next, you will need a free USB device which can be discovered by your operating system, with enough total space, and which is empty or with data on it that can be discarded. The total space of the USB device needed for preparing as an installation media for CentOS 7 for the minimal version must be roughly 700 megabyte. If you are working on a Windows computer, you will need a working Internet connection to download additional software. On OS X, you need an administrator user account.
To begin this recipe, start up your Windows or OS X operating system, then connect a free USB device with enough capacity, and wait until it gets discovered by File Manager under Windows or Finder under OS X.
On a Windows based system, we need to download an additional software called
dd. Visit http://www.chrysocome.net/dd in your favorite browser. Now download the latest
dd-XX.zipfile you can find there, with
XXbeing the latest stable version number. For example,
On Windows, navigate to your
Downloadsfolder using File Manager. Here you will find the
dd-05.zipfile. Right-click on it and click on Extract All, and extract the
dd.exefile without creating any subdirectory.
On Windows, open the command prompt (typically found at Start | All Programs | Accessories | Command Prompt) and type the following commands:
cd downloads dd.exe --list
On OS X, open the program Finder | Applications | Utilities | Terminal, and then type the following commands:
cd ~/Downloads diskutil list
On Windows, to spot the name of the right USB device you want to use as installation media, look into the output of the command under the
removable mediasection. Below that, you should find a line starting with
Mounting onand then a drive letter, for example,
\.\e:. This cryptic written drive letter is the most important part we need in the next step, so please write it down.
On OS X, the device path can be found in the output of the former command and has the format of
numberis a unique identifier of the disk. The disks are numbered, starting with zero (
0is likely to be the OS X recovery disk, and disk
1is likely to be your main OS X installation. To identify your USB device, try to compare the
SIZEcolumns to the specifications of your USB stick. If you have identified the device name, write it down, for example,
On Windows, type the following command, assuming your USB device selected as a installation media has the Windows device name
\\.\e:(change this as required and be careful what you type – this can create tremendous data loss). Also, substitute
XXXXwith the correct
isofile version number in the next command:
dd.exe if=CentOS-7-x86_64-Minimal-XXXX.iso of=\\.\e: bs=1M
On OS X, you need two commands which will ask for the administrator password (replace
disk3with the correct version number and the correct USB device path):
sudo diskutil unmountDisk /dev/disk3 sudo dd if=./CentOS-7-x86_64-Minimal-XXXX.iso of=/dev/disk3 bs=1m
ddprogram finishes, there will be some output statistics on how long it took and how much data has been transferred during the copy process. On OS X, ignore any warning messages about the disk not being readable.
Congratulations! You now have created your first CentOS 7 USB installation media. You now can safely remove the USB drive in Windows or OS X, and physically unplug the device and use it as a boot device for installing CentOS 7 on your target machine.
So what have we learned from this experience?
The purpose of this recipe was to introduce you to the concept of creating an exact copy of a CentOS installation ISO file on a USB device, using the
dd command-line program. The
dd program is a Unix based tool which can be used to copy bits from a source to a destination file. This means that the source gets read bit by bit and written to a destination without considering the content or file allocation; it just involves reading and writing pure raw data. It expects two file name based arguments: input file (
if) and output file (
of). We will use the CentOS image file as our input filename to clone it exactly
1:1 to the USB device, which is accessible through its device file as our output file parameter. The
bs parameter defines the block size, which is the amount of data to be copied at once. Be careful, it is an absolute expert tool and overwrites any existing data on your target while copying data on it without further confirmation or any safety checks. So at least double-check the device drive letters of your target USB device and never confuse them! For example, if you have a second hard disk installed at
D: and your USB device at
E: (on OS X, at
/dev/disk3 respectively) and you confuse the drive letter
/dev/disk2), your second hard disk would be erased with little to no chances of recovering any lost data. So handle with care! If you're in doubt of the correct output file device, never start the
In conclusion, it is fair to say that there are other far more convenient solutions available for creating a USB installation media for CentOS 7 than the
dd command, such as the Fedora Live USB Creator. But the purpose of this recipe was not only to create a ready-to-use CentOS USB installer but also to get you used to the
dd command. It's a common Linux command that every CentOS system administrator should know how to use. It can be used for a broad variety of daily tasks. For example, for securely erasing hard disks, benchmarking network speed, or creating random binary files.
In this recipe, we will learn how to perform a typical installation of CentOS using a new graphical installer interface introduced in CentOS 7. In many respects, this is considered to be the recommended approach to installing your system, as it not only provides you with the ability to create the desired hard disk partitions but also to customize your installation in lots of ways (for example, keyboard layout, package selection, installation type, and so on). Your installation will then form the basis of a server on which you can build, develop, and run any type of service you may want to provide in the future.
Before we begin, it is assumed that you have followed the previous recipe in which you were shown how to download a CentOS image, confirm the checksum of the relevant image files, and create the relevant installation optical disks or USB media. Your system must be a 64 bit (x64_86) architecture, must have at least 406 MB RAM to load the graphical installer 1 GB or more is recommended if installing a graphical window manager such as Gnome), and have at least 10 GB free hard disk space.
To begin this recipe, insert your installation media (CD/DVD or USB device), restart the computer, and press the correct key for selecting the boot device during startup. Then choose the inserted device from the list (for many computers, this can be reached using F11 or F12 but can be different on your system. Please refer to your motherboard's manual).
After loading some initial files, the installer then starts to test the installation media. A single test should take between 30 seconds to five minutes and will report if there are any errors on your installation media. When this process is complete, the system will finally load the graphical installer.
The CentOS installer will now present the graphical installation welcome screen. From this point onwards, you can use your keyboard and mouse (the latter is highly recommended), but remember to enable the number lock on your keyboard if you intend to use the keypad.
On the left side you see the main language category and on the right side, the sub-languages for the installer. You can also search for a language using the textbox on the left bottom. All changes to your language settings will take effect immediately, so when you are ready, choose the Continue button to proceed.
Now we reach the main installation menu, which is called Installation summary.
Most options shown here already have some predefined values and can be used without changing, others which do not have any default value and which need your attention are labeled with a red exclamation mark like the Installation Destination under System category. So let's click on it using the mouse.
After clicking the Installation Destination button, you will see a graphical list of all the hard disk devices currently connected to your computer, which you can use for installing the operating system on. You can select your target hard disk by clicking on the correct hard disk symbol. It will then put a check mark on it. If you are unsure about the right hard disk, try to identify it by comparing its brand and total size shown in the menu. Before the installation can proceed, you must select a hard disk. Be careful and choose your target hard disk wisely as it will erase any existing data on it during the installation. When you are ready, click the Done button.
If your selected hard disk already contained data, then when clicking on Done, you may see what could be described as a warning/error message. The message may read: You don't have enough space available to install CentOS. Don't worry! This is to be expected and the message is simply asking you to re-initialize your hard disk because CentOS can only be installed on an empty disk. In most cases, especially if you have more than one partition on the hard disk, simply click on Reclaim space which will show a new window with a detailed list of all the partitions on this drive. Here just click on Delete All and then again on Reclaim space to discard any data on this disk, which will complete the task of disk initialization and enable you to proceed to the next step. When finished, click the Done button.
Back at the Installation Summary screen, the exclamation mark on the Installation Destination item should be gone now.
Optionally, we can click on Network & Hostname under System category. On the following page, on the left side, you can choose the primary network adapter you would like to connect to the Internet and select it by clicking on it. For the selected device, click on the switch on the right side to enable and connect it automatically using the On position of the switch. Finally, before closing this submenu, change the hostname in its text field to something appropriate. Click Done.
Now back at the Installation Summary screen, all the important settings have been made or have got predefined values, and all the exclamation marks are gone. If you are happy with these settings, click on the Start installation button or change the settings appropriately.
On the next screen, you will be required to create and confirm a root password for the root user while the new system gets installed in the background. Choose a secure password with not less than six characters.
Here on this screen you can also create a standard user account which is highly recommended. If you create a new user do not check Make this user administrator. When you are ready, click Done (if you entered a weak password, you have to confirm this by clicking twice)
CentOS will now partitionate and format your hard disk in the background and resolve any dependencies, and the installer will begin writing to the hard disk. This may take some time, but a progress bar will indicate the status of your installation. When finished, the installer will inform you that the entire process is complete and that the installation was successful. So when you are ready, click on the Reboot button. Now release your installation media from the drive.
Congratulations! You have now installed CentOS 7 on your computer.
In this recipe, you have discovered how to install the CentOS 7 operating system. Having covered the typical approach to the graphical installation process, you are now in a position to develop the server with additional configuration changes and packages that will suit the role you intend the server to fulfill. This graphical installer has been built with the aim to be very intuitive and flexible, and makes installation very easy as it will guide the user through some mandatory tasks that he has to fulfill before the installation of the main system can be started.
In this recipe, we will learn how to initiate the process of running a netinstall over HTTP (using the URL method) in order to install CentOS 7. It is a process in which a small image file is used to boot the computer and let the user select and install only the software packages and services he wants and nothing more over a network connection thus providing great flexibility.
Before we begin, it is assumed that you already know how to download and checksum a CentOS 7 installation image and how to create the relevant installation media from it. For this recipe here, we will need to download and create installation media for the netinstall image (download the latest CentOS-7-x86_64-NetInstall-XXXX.iso file) instead of the minimal ISO shown in another recipe in this chapter. Also, it is assumed that you have at least gone through the graphical installation procedure once to exactly know how to boot from your installation media and work with the installer program.
On the welcome splash screen, the option Test this media & install CentOS 7 is preselected and we will use this option. When you are ready, press the Return key to proceed.
After the tests finish, the graphical installer will load and present the typical graphical installation summary screen.
Before we can install CentOS over the network, we have to make sure that we have a working network connection. Therefore, you should first click on the Network & Host name menu entry and activate one of your network adapters to the connected state. Refer to the normal installation recipe for more details.
Next, click on Installation source to enter the settings. As we will be installing over HTTP (also referred to as the URL method), you should leave the default On the network selected in the Which installation source would you like to use? section.
Now type in the following URL in the standard
http://textfield, which we will use to download all the required installation packages at http://mirror.centos.org/centos/7/os/x86_64/.
Alternatively, you can also use a personal repository which you would have to create in advance (see Chapter 4, Managing Packages with YUM)
When you are ready, click on Done to start the initialization process.
On success, the installer will begin to retrieve the appropriate
install.imgfile. This may take several minutes to complete, but once resolved, a progress bar will indicate all the download activity. When this process finishes successfully, the exclamation mark at the installation source will go away but another one will pop up which will tell the user that it is missing the software selection. Click on it and choose whatever fits your need. As for the purpose of this recipe, just select Minimal install under Base environment and then click on Done.
If the Which installation source would you like to use stays greyed out and cannot be changed, then there are connection problems with your network adapter. If this is the case, go back to configure Network & Hostname and change the network settings until the connected state can be reached.
CentOS 7 will now install the operating system the usual way and will congratulate you when this process finishes. It may be slower than installing from a physical installation media since all the packages have to be retrieved from the Internet.
The purpose of this recipe was to introduce you to the concept of the CentOS network installation process, in order to show you just how simple this approach can be. By completing this recipe you have not only saved time by limiting your initial download to those files that are required by the installation process, but you have also been able to take advantage of the full graphical installation method without the need for a complete DVD suite.
While installing CentOS 7 manually using the graphical installer utility is fine on a single server, doing so on a multiple number of systems can be tedious. Kickstart files can automate the installation process of a server system and here we will show how this can be done. They are simple text based configuration files which provide detailed and exact instructions on how the target system should be set up and installed (for example, which keyboard layout or additional software packages to install).
To successfully complete this recipe, you will need access to an already installed CentOS 7 system to retrieve the kickstart configuration file we want to work with and use for automated installation. On this pre-installed CentOS server, you also need a working Internet connection to download additional software.
Next, we will need to download and create installation media for the DVD or the Everything image (download the latest
CentOS-7-x86_64-Everything-XXXX.iso file), instead of the minimal iso file shown in another recipe in this chapter. Then you need another USB device which must be read and writable on Linux systems (formatted as FAT16, FAT32, EXT2, EXT3, EXT4, or XFS filesystem).
Log in as root on the existing CentOS 7 system and make sure the kickstart configuration file exists by typing the following command and pressing the Return key to execute (this will show you the details of the file):
ls -l /root/anaconda-ks.cfg
Next, physically plug in a USB device and then type the following command, which will give you a list of all the hard disk devices currently connected to the computer:
Try to identify the device name by comparing its size, partitions, and identified filesystems with the specifications of your USB device. The device name will be of kind
Xis an alphabetical character, such as
e, … and so on. If you cannot find the right device name for your USB media using the
fdiskcommand, try the following trick: run
fdisk -ltwice - first with plugged-out and then with plugged-in USB device and compare how the second output changed - it has one device name more than the first output: your device name of interest !
If you have found the right device name in the list, create a directory to mount it to the current filesystem:
Next, actually mount the stick to this folder, assuming that your USB partition of choice is at
/dev/sdc1(change this as required):
mount /dev/sdc1 /mnt/kickstart-usb
Now we will create our working copy of the kickstart file on the USB device for customizing:
cp /root/anaconda-ks.cfg /mnt/kickstart-usb
Next, open the copied kickstart file on the USB device with your favorite text editor (here we will use the editor nano, if you have not installed it yet type
yum install nano):
We will now modify the file for installing CentOS on a new target system. In nano, use the up and down arrow keys to go to the line which starts with (
<your_hostname>will be the name of the hostname you gave during installation e.g.
Now edit the
<your_hostname>string to give it a new unique hostname. For example, add a
-2to the end of any existing name, as shown next:
Next, move the cursor down using the up and down arrow keys until it stops at the line which says
%packages.Append the following lines right below it (you can further customize this and provide additional packages that you want to install automatically):
mariadb-server httpd rsync net-tools
Now save and close the file, to do this in the nano editor use the key combination Ctrl+o (which means, hold down the Ctrl key on the keyboard and then the o key without releasing the Ctrl key) to write the changes. Then press Return to confirm the filename and Ctrl+x to exit the editor.
Next, install the following CentOS package:
yum install system-config-kickstart
Now we validate the syntax of our kickstart file using the
ksvalidatorprogram, which is included in the package we just installed:
configfile is error-free, unmount the USB stick now by using the following commands:
cd umount /mnt/kickstart-usb
When you get a new command prompt again, unplug the USB device with the kickstart file for using on the target machine physically from the system.
Now you need physical access to the target machine you want to install CentOS on, using the kickstart file just created. Disconnect any other external file storage(s) that you do not need during the installation.
Power on the computer and put in your prepared CentOS installation media (must be a CentOS DVD or Everything installation disk image prepared on a CD/DVD disc or a USB device installer). Also connect to the computer the USB stick containing the kickstart file you just created in the earlier steps (if you using a USB drive for installing CentOS then you will need two free USB ports in total to complete this recipe).
After the CentOS installer starts loading, the common standard CentOS 7 installation welcome screen will show up and the option Test this media & install CentOS 7 will be pre-selected by the cursor.
Next, press the Esc key on your keyboard once to switch to the
Now we are ready to start the kickstart installation. To do this, you need to know the exact partition name on the USB device where the kickstart file is located. Type the following command, assuming that your partition is at
/dev/sdc1(change this as required), and press the Return key to start the kickstart installation process:
If you cannot find out the right device and partition name of the USB stick, you have to start the target system in rescue mode (refer to the Troubleshooting the system in rescue mode recipe) to identify the right device name and partition number by comparing its size, partitions, and identified filesystems with the specifications of your stick.
The new system now gets installed automatically using the instructions from the provided kickstart file. You can watch the installation output messages as it is showing the user detailed installation progress.
If the system has finished installing, reboot the system and log in to your new machine to verify that the new system has been setup the way we described using the kickstart file.
In this recipe, you have seen that every server running a CentOS 7 installation keeps the kickstart file in its root directory, which contains detailed information on how the system had been set up during the installation. The kickstart files can be used to automate the installations of multiple systems with the same configuration. This can save a lot of time doing repetitive work as no user interaction during installation is needed. Also, we can use this method if the target machines don't meet the minimum requirement in RAM for graphical based installations but when needed other features the text mode installer does not provide such as custom partitioning of the system. Kickstart configuration files are simple plain text files which can be created manually from scratch. Because there are quite a number of different commands available to construct your system using the kickstart syntax, we used an existing file as a template and customized it to fit our needs, instead of starting out completely new. We did not use the minimal installation image to drive our kickstart installation because we installed some extra packages not included on the minimal ISO file, such as the Apache webserver.
When you turn on your computer, the boot loader is the first program that starts up and is responsible for loading and transferring control to an underlying operating system. Nowadays, almost any modern Linux distribution uses the GRand Unified Bootloader version 2 (GRUB2) for starting the system. It has a lot of flexibility in configuration and supports a lot of different operating systems. In this recipe, we will show how to customize the GRUB2 boot loader by disabling the waiting time of the menu display and therefore improving the time it takes for booting the system.
To complete this recipe, you will require access to an already installed CentOS 7 operating system (minimal or any other CentOS 7 installation type will work) with root privileges. Also, you need to have some basic experiences with a text based editor, such as nano, for changing the configuration files.
We begin this recipe by opening the main GRUB2 configuration file with our text editor of choice and modifying it.
First log in as root into your system and create a copy of the GRUB2 configuration file for backup and rollback, if needed. Press the Return key to finish:
cp /etc/default/grub /etc/default/grub.BAK
Open the main GRUB2 configuration file that we want to edit with the following command and press the Return key (here we will use the editor nano, if you have not installed it yet type
yum install nano):
Press the Return key in the first line where the cursor is at to insert a new line at the top, and then insert the following line:
#sign to the beginning of the following line, as shown:
Now save the file in the nano using Ctrl+o (and Return to confirm the filename to save). Use Ctrl+x to exit the editor and then run the following command:
dmesg | grep -Fq "EFI v"
grub2-mkconfig -o /boot/grub2/grub.cfg
Otherwise, if there is an output, run:
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
grub2-mkconfigis successful, it will print
Done.Now reboot your system using the following command:
During the rebooting process, you will notice that the GRUB2 boot menu will not appear any more and the system will boot up faster.
Having completed this recipe, we now know how to customize the GRUB2 boot loader. In this very easy recipe, we only showed you very basic modifications to the boot loader but it can do much more! It supports a broad variety of filesystems and can boot almost any compatible operating system. This is also particularly useful if you plan to run multiple operating systems on the same machine. To learn more about GRUB2's configuration file syntax type the
info grub2 |
less command and go to the section
6.1 Simple configuration handling (read the recipe Navigating text files with less in Chapter 2, Configuring the System to learn how to browse this document).
We all make mistakes and this is especially true for novice Linux system administrators. Linux can have a steep learning curve and sooner or later there will be a point in your career where your CentOS installation does not start up due to broad number of reasons, including hardware problems or human mistakes such as configuration errors. If this has happened to you then you can use the CentOS rescue mode in order to boot an otherwise unbootable system and try to undo your mistakes or find out the root of the problems. In this recipe, we will show you three common use cases when to use this option:
Accessing the filesystem for recovering important data or undoing changes to configuration files if CentOS is not booting up
Changing the root password if you forgot it
Re-installing the boot loader which can be damaged when installing another operating system on the same harddisk where CentOS is installed
To complete this recipe, you will require a standard installation media (CD/DVD or USB device) of the CentOS 7 operating system. For recovering the data from the system, you will need to connect some sort of external storage device to the system, such as an external hard disk or a working network connection to another computer to copy all your precious data to a different location.
To begin this recipe, you should boot your server from the CentOS installation CD/DVD or the USB device and wait until the first welcome splash screen appears with the cursor waiting at the Test this media & install CentOS 7 menu option.
On the Troubleshooting screen, use the down arrow key to highlight Rescue a CentOS system. When you are ready, press the Return key to proceed.
After some loading time, we enter the rescue screen, which includes various confirmation sub-screens. To begin this section, use the left and right arrow keys to choose Continue and press the Return key to proceed.
On the first sub-screen, choose OK and press the Return key to proceed.
Again, in the following sub-screen, choose OK and press the Return key to proceed.
On the next screen, choose the Start shell and by using the Tab key, highlight OK and press the Return key to proceed.
By completing the preceding steps, you will launch a shell session. You will notice this at the bottom of your display. The current status of the shell session will read as follows:
At the prompt, type the following instruction to change the root filesystem, before pressing the Return key to complete your request:
Congratulations! You just reached the rescue mode. To exit it at any time, simply type the following command and then press the Return key to complete your request (don't do this right now as this will restart the system):
If you are now in the rescue mode and need to backup important files from the filesystem, you need a destination location for the data transfer. For transferring the data we want to recover from the server to another computer please physically connect an external USB device to it. You can also use network storages for the recovery. For example, you could import an NFS server share and copy data to it. Refer to the Working with NFS recipe in Chapter 7, Building a Network.
You now need to find out the right device name with the partition number of your connected device; comparing the total size or the filesystem output of the various devices with the specifications from your stick can help you in this process. You can also try the following trick: run the
fdisk -lcommand twice, first with the plugged-in USB device and then again with the USB device unplugged, and compare the output of both the commands. It should be different by one device name which you are searching for!
If you have found the right device name in the list, create a directory to mount the stick to the filesystem:
Next, mount the disk partition to this folder. Here we assume that the USB device of interest has the device name
sdd1(please change if different on your system):
mount /dev/sdd1 /mnt/hdd-recovery
The original system's hard disk's root partition has been mounted under a specific folder by the rescue system automatically (under
/mnt/sysimage), if you need to access it for example to change configuration files which caused startup problems or make a full or partial backup. For example, if you need to backup your Apache webserver configuration files, use:
cp -r /mnt/sysimage/etc/http /mnt/hdd-recovery
If you need to access the data that lives on partitions other than the currently mounted root partition, use
fdisk -lto identify the partition of interest. Then create a directory and mount the partition to it and change to that directory to access your data similar you did when mounting the USB device.
To finish backing up the files, type:
If you are in the rescue mode for changing the root password, just use the following command and provide a new password:
To complete changing the password, type:
Now run the following command:
dmesg | grep -Fq "EFI v"
If the preceding command does not produce any output look for the
*symbol in the
fdisklisting in the boot column to find the correct start partition, and assuming that your boot disk is on
/dev/sda1(change this as required), type the following:
Otherwise, if there is an output, run instead:
yum reinstall grub2-efi shim
If no error is reported, the console should respond as follows:
# this device map was generated by anaconda (hd0) /dev/sda
The console output from the last step has confirmed that GRUB has now been successfully restored.
There are a broad variety of problems which can be resolved by the tools provided through the rescue mode environment. Often these problems refer to booting problems but can also be from different types, such as forgetting the root password. Rescue mode can be a life-saver and an understanding of it is a very important skill to learn. It was felt that such a recipe should thus remain close at hand.
In this recipe, we will learn how to enhance the minimal install with additional tools that will give you a variety of administrative and development options, which in turn will prove vital during the lifetime of your server and which are essential for some recipes in this book. The minimal install is probably the most efficient way you can install a server, but having said that, a minimal install does require some additional features in order to make it a more compelling model.
To complete this recipe, you will require a minimal installation of the CentOS 7 operating system with root privileges and a connection to the Internet in order to facilitate the download of additional packages.
To update the system, log in as root and type:
yum -y update
CentOS will now search for the relevant updates and, if available, they will be installed. On completion and depending on what was updated (that is, kernel and new security features to name but a few), you can decide to reboot your computer. To do this, type:
Your server will now reboot and return to the login screen. We will now complete this recipe and enhance our current installation with a series of package groups that will prove to be very useful in the future. To do this, log in as root and type:
yum -y groupinstall "Base" "Development Libraries" "Development Tools" yum -y install policycoreutils-python
The purpose of this recipe is to enhance the minimal installation of the CentOS 7 operating system and by doing this you have not only introduced yourself to the Yellowdog Updater Modified (YUM) package manager (something to which we will return to later on in this book), but you now have a system that is capable of running a vast amount of applications right out-of-the-box.
So what have we learned from this experience?
We started the recipe by updating the system in order to ensure that it is up to date. At this stage, it is often a good idea to reboot the system. It is not expected that we will do this very often but it is expected when updating for the first time after the installation of the operating system, as it is most likely that there are major changes available. The reason behind this is typically based on the desire to take advantage of a new kernel or revised security updates. In the next phase, the recipe showed you how to add a series of package groups that may prove to be more than useful in the future. To save time, we wrapped the instruction to install the three main package groups:
Development Libraries, and
Development Tools. The preceding action alone installs over 200 individual packages, thereby giving your server the ability to compile the code and run a vast array of applications out-of -the-box, that you may need over the life time of your server. To see a list of all the packages within a group, for example, from
Base, run the
yum groupinfo Base command. Another package we installed was
policycoreutils-python which provides tools and programs to manage the security enhanced access control to Linux, which we will use quite often throughout the chapters of this book.