Ubuntu iTOps Tube
Monday, July 11, 2011
Learning how Linux boots up is critical. When you have this information you can use it to alter the type of login screen you get as well as which programs start up. Read on for the details.
The Linux Boot Sequence
You might remember when you installed Linux that the installation process prompted you for a list of partitions and the sizes of each in which your filesystems would be placed.
When allocating disk space for the partitions, the first sector, or data unit, for each partition is always reserved for programmable code used in booting. The very first sector of the hard disk is reserved for the same purpose and is called the master boot record (MBR).
When booting from a hard disk, the PC system BIOS loads and executes the boot loader code in the MBR. The MBR then needs to know which partitions on the disk have boot loader code specific to their operating systems in their boot sectors and then attempts to boot one of them.
Fedora Linux is supplied with the GRUB boot loader which is fairly sophisticated and therefore cannot entirely fit in the 512 bytes of the MBR. The GRUB MBR boot loader merely searches for a special boot partition and loads a second stage boot loader. This then reads the data in the
/boot/grub/grub.confconfiguration file, which lists all the available operating systems and their booting parameters. When this is complete, the second stage boot loader then displays the familiar Fedora branded splash screen that lists all the configured operating system kernels for your choice.
Note: In some operating systems, such as Debian / Ubuntu, the
/boot/grub/grub.conf file may also be referred to by the name
Figure 7-1 shows a typical grub.conf file for a system that can boot both Fedora Linux and Windows 2000. This structure of this file is discussed in Chapter 33, "Modifying the Kernel to Improve Performance".
Figure 7-1 Sample grub.conf file
default=0 timeout=10 splashimage=(hd0,0)/grub/splash.xpm.gz title Fedora Core (2.6.8-1.521) root (hd0,0) kernel /vmlinuz-2.6.8-1.521 ro root=LABEL=/ initrd /initrd-2.6.8-1.521.img title Windows 2000 rootnoverify (hd0,1) chainloader +1
When Linux begins to boot with its kernel, it first runs the /sbin/init program, which does some system checks, such as verifying the integrity of the file systems, and starts vital programs needed for the operating system to function properly. It then inspects the /etc/inittab file to determine Linux's overall mode of operation or runlevel. A listing of valid runlevels can be seen in Table 7-1.
Table 7-1 Linux Runlevels
|Mode||Directory||Run Level Description|
|2||/etc/rc.d/rc2.d||Not used (user-definable)|
|3||/etc/rc.d/rc3.d||Full multi-user mode (no GUI interface)|
|4||/etc/rc.d/rc4.d||Not used (user-definable)|
|5||/etc/rc.d/rc5.d||Full multiuser mode (with GUI interface)|
Based on the selected runlevel, the init process then executes startup scripts located in subdirectories of the
/etc/rc.d directory. Scripts used for runlevels 0 to 6 are located in subdirectories
Here is a directory listing of the scripts in the
[root@bigboy tmp]# ls /etc/rc.d/rc3.d ... ... K75netfs K96pcmcia ... ... ... ... K86nfslock S05kudzu ... ... ... ... K87portmap S09wlan ... ... ... ... K91isdn S10network ... ... ... ... K92iptables S12syslog ... ... ... ... K95firstboot S17keytable ... ... [root@bigboy tmp]#
As you can see, each filename in these directories either starts with an "S" which signifies the script should be run at startup, or a K, which means the script should be run when the system is shutting down. If a script isn't there, it won't be run.
Most Linux packages place their startup script in the
/etc/init.d directory and place symbolic links (pointers) to this script in the appropriate subdirectory of
/etc/rc.d. This makes file management a lot easier. The deletion of a link doesn't delete the file, which can then be used for another day.
The number that follows the K or S specifies the position in which the scripts should be run in ascending order. In our example,
kudzu with a value 05 will be started before
wlan with a value of 09. Fortunately you don't have to be a scripting/symbolic linking guru to make sure everything works right because Fedora comes with a nifty utility called
chkconfig while Debian / Ubuntu uses the
update-rc.d command to do it all for you. This is explained later.
Another popular software installation file format is the tar file, which can frequently be obtained from the Web sites of software developers, and online software libraries such as www.sourceforge.net.
The Linux tar command is used to archive files and typically have a .tar file extension in the file name. These files are also frequently compressed in the gzip format, and when they do, their file extensions will end with .tar.gz or .tgz. The commands to extract the data from either type are similar. When a tar file is uncompressed, the command to extract the data is tar -xvf filename.tar. When the archive is compressed, the command to use is tar -xzvf filename.tar.gz.
The tar file installation process usually requires you first to uncompress and extract the contents of the archive in a local subdirectory, which frequently has the same name as the tar file. The subdirectory will usually contain a file called README or INSTALL, which outlines all the customized steps to install the software.
Here are the initial steps to take to install tar-based software:
1) Issue the tar command to extract the files.
[root@bigboy tmp]# tar -xvzf linux-software-1.3.1.tar.gz linux-software-1.3.1/ linux-software-1.3.1/plugins-scripts/ ... ... ... linux-software-1.3.1/linux-software-plugins.spec [root@bigboy tmp]#
This creates a subdirectory with the installation files inside.
[root@bigboy tmp]# ls linux-software-1.3.1 linux-software-1.3.1.tar.gz [root@bigboy tmp]#
2) Use the cd command to enter the subdirectory and follow the directions listed in the INSTALL and README files:
[root@bigboy tmp]# cd linux-software-1.3.1 [root@bigboy linux-software-1.3.1]# ls COPYING install-sh missing plugins depcomp LEGAL mkinstalldirs plugins-scripts FAQ lib linux-software.spec README Helper.pm Makefile.am linux-software.spec.in REQUIREMENTS INSTALL Makefile.in NEWS subst.in [root@bigboy linux-software-1.3.1]#
Software installation with tar files can be frustrating, frequently requiring the installation of other supporting tar files, each with its own customized installation commands. RPMs, with the single standardized command format, are usually easier to use and may be the better method to use for newer Linux users.
Here is a sample installation of an individual package using yum. In this case the RPM installed is the apache Web server package:
[root@ root@u-bigboy:/tmp# apt-get -y install apache Reading package lists... Done Building dependency tree... Done The following extra packages will be installed: apache-common apache2-utils libapr0 libpcre3 Suggested packages: apache-doc apache-ssl apache-perl The following NEW packages will be installed: apache apache-common apache2-utils libapr0 libpcre3 ... ... ... Creating config file /etc/apache/httpd.conf with new version Creating config file /etc/apache/srm.conf with new version Creating config file /etc/apache/access.conf with new version Creating config file /etc/apache/modules.conf with new version * Starting apache 1.3 web server... ...done. root@u-bigboy:/tmp#
The apt-get utility can be used to simultaneously upgrade all the packages on your system with the upgrade option. When used without listing any packages afterwards, apt-get will attempt to update them all. The apt-get upgrade package-name command updates only a particular DEB package.
It is always advisable to use apt-get after installing Linux to make sure the latest versions of software are installed for the sake of improved security and functionality. Here is an example of output of what to expect; the -y flag causes apt-get to assume "yes" as the answer to all prompts and allows it to run non-interactively:
root@u-bigboy:/tmp# apt-get -y upgrade Reading package lists... Done Building dependency tree... Done The following packages have been kept back: linux-image-386 The following packages will be upgraded: capplets-data desktop-file-utils eog gdm gnome-about ... ... ... Setting up libgtk2.0-bin (2.8.18-0ubuntu1) ... Updating the IM modules list for GTK+-2.4.0...done. Updating the gdk-pixbuf loaders list for GTK+-2.4.0...done. root@u-bigboy:/tmp#
APT uses the /etc/apt/sources.list file to instruct your server as to where to find the required packages on your network. The default file locations in this file refer to a few trusted APT download websites on the Internet.
It is important to periodically resynchronize the APT package index files from the sources listed in the /etc/apt/sources.list file. This updates your system with listings of the most current package versions. This can be done with the apt-get update command as seen here:
root@u-bigboy:/tmp# apt-get update Get:1 http://security.ubuntu.com dapper-security Release.gpg [189B] Get:2 http://us.archive.ubuntu.com dapper Release.gpg [189B] Get:3 http://us.archive.ubuntu.com dapper-updates Release.gpg [189B] ... ... ... Fetched 184kB in 2s (66.1kB/s) Reading package lists... Done root@u-bigboy:/tmp#
Note: If you install Ubuntu without Internet access, only a barebones set of packages will be installed and the URL entries in the /etc/apt/sources.list file will be commented out, but the required packages will be flagged for eventual installation in the dpkg database. When you get Internet access, uncomment the URL entries and upgrade your installation with the apt-get command which will update your system with the full complement of required packages downloaded from the Web.
You can also create an APT server on your own network if you don't want all your Debian / Ubuntu servers to have Internet access. You'll have to update your sources.list file accordingly, but the full configuration steps are beyond the scope of this book.
Sometimes you'll find yourself installing software that terminates with an error requesting the presence of a particular file. In many cases the installation program doesn't state the DEB package in which the file can be found. It is therefore important to be able to determine the origin of certain files, by listing the contents for DEBs in which you suspect the files might reside.
Listing Files for Previously Installed DEBs
As stated previously, listing the files found in a package can be very useful. With dpkg, the --listiles option can provide this information easily. Here we list the files present in the openssh-server package.
root@u-bigboy:~# dpkg --listfiles openssh-server ... ... ... /var/run/sshd /usr/lib/sftp-server /usr/share/doc/openssh-server root@u-bigboy:~#
Listing Files in DEB Files
Download sites often have packages with different functions, but similar names. It is good to be able to list the contents of a DEB package to verify you have the correct one. This can be done with the --contents option for dpkg as can be seen in this example.
root@u-bigboy:/tmp# dpkg --contents openssh-server_4.2p1-7ubuntu3_i386.deb ... ... ... -rw-r--r-- root/root 10444 2006-05-17 17:43:19 ./usr/share/man/man8/sshd.8.gz -rw-r--r-- root/root 1169 2006-05-17 17:43:19 ./usr/share/man/man8/sftp-server.8.gz drwxr-xr-x root/root 0 2006-05-17 17:43:24 ./usr/share/doc/ drwxr-xr-x root/root 0 2006-05-17 17:43:24 ./usr/share/doc/openssh-client/ drwxr-xr-x root/root 0 2006-05-17 17:43:19 ./var/ drwxr-xr-x root/root 0 2006-05-17 17:43:19 ./var/run/ drwxr-xr-x root/root 0 2006-05-17 17:43:19 ./var/run/sshd/ ... ... ... root@u-bigboy:/tmp#
Listing the DEB Package to Which a File Belongs
Searching for the ownership of a particular file is also simple when using the --search option with dpkg. In this example, we see that the /etc/syslog.conf file is a part of the sysklogd package.
root@u-bigboy:~# dpkg --search /etc/syslog.conf sysklogd: /etc/syslog.conf root@u-bigboy:~#
The dpkg --list command will list all the packages installed on your system
root@u-bigboy:~# dpkg --list Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-===================-===================-================================ ii ssh 4.1p1-7ubuntu4 Secure shell client and server ... ... ... root@u-bigboy:~#
The output will be in six columns. The fourth column lists the name of the package, the fifth states the package version, and the sixth and last provides a description.
The first three columns are each only a single character wide and provide very specific information about the package as outlined in Table 6-3.
Table 6-3 Column Formatting for the dpkg command
|Desired State |
|Current State |
|Error State |
|u||Unknown: The package has never been installed|
|i||Installed: A privileged user has requested the installation of the package|
|r||Remove: A privileged user has requested the removal of the package. Configuration files for the package most likely remain.|
|p||Purge: A previously installed package has been removed. Configuration files for the package have probably been removed.|
|h||Hold: A privileged user has requested that the package remain at its current version with no automatic upgrades.|
|n||Not Installed: The package is not installed|
|i||Installed: The package is installed|
|c||Configuration Files Exist: Package was installed, but the configuration files exist.|
|u||Unpacked: Files have been unpacked, but not installed|
|f||Failed: Configuration of the package has failed.|
|h||Halt: The package installation failed to complete|
|h||Enforced Hold: Package upgrade is on hold because another dependent package with a user defined hold requires this package to remain not upgraded.|
|r||Reinstallation: The package is broken and requires a reinstallation.|
|x||The package is both broken and on enforced hold.|
You can specify the desired package in which you are interested after the --list option to get a listing specific to that package. Here we see a single listing for the openssh-server package using this method.
root@u-bigboy:~# dpkg --list openssh-server Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-===================-===================-======================================== ii openssh-server 4.2p1-7ubuntu3 Secure shell server, an rshd replacement root@u-bigboy:~#
You can also pipe the output of this command through the grep command if you are interested in only a specific package. In this example we are looking for all packages containing the string dhcp in the name.
root@u-bigboy:~# dpkg --list | grep dhcp ii dhcp3-client 3.0.2-1ubuntu6 DHCP Client ii dhcp3-common 3.0.2-1ubuntu6 Common files - dhcp3* packages root@u-bigboy:~#
Sometimes the installation of DEB software doesn't go according to plan and you need to take corrective actions. This section shows you how to recover from some of the most common errors you'll encounter.
As should be expected, packages often rely on the existence of other previously installed packages. This will sometimes result in dpkg installations failing with dependency problems errors which really mean that a prerequisite DEB needs to be installed. In the next example we're trying to install the mrtg-contrib package, but it needs the mrtg package to be installed first beforehand.
root@u-bigboy:/tmp# dpkg --install mrtg-contrib_2.12.2-1_all.deb Selecting previously deselected package mrtg-contrib. (Reading database ... 70759 files and directories currently installed.) Unpacking mrtg-contrib (from mrtg-contrib_2.12.2-1_all.deb) ... dpkg: dependency problems prevent configuration of mrtg-contrib: mrtg-contrib depends on mrtg (= 2.12.2-1); however: Package mrtg is not installed. dpkg: error processing mrtg-contrib (--install): dependency problems - leaving unconfigured Errors were encountered while processing: mrtg-contrib root@u-bigboy:/tmp#
After installing the mrtg package, mrtg-contrib was installed correctly. You can automatically install prerequisite packages using the APT utility. This will be covered later in th echapter.
There are generally two ways to install DEB files manually. The first method is by using a file previously downloaded to your hard drive, and the other is to install the DEB from some sort of removable media such as a CD-ROM drive.
Using Downloaded Files
Download the DEBs (which usually have a file extension ending with .deb) into a temporary directory, such as /tmp. The next step is to issue the dpkg --install command to install the package. Here is an example of a typical DEB installation command to install the ndiswrapper utilities package:
root@u-bigboy:~# dpkg --install ndiswrapper-utils_1.8-0ubuntu2_i386.deb Selecting previously deselected package ndiswrapper-utils. (Reading database ... 70221 files and directories currently installed.) Unpacking ndiswrapper-utils (from ndiswrapper-utils_1.8-0ubuntu2_i386.deb) ... Setting up ndiswrapper-utils (1.8-0ubuntu2) ... root@u-bigboy:~#
Installing DEB files from CDROM is similar to that with Fedora / Redhat. The difference is that the CDROM device name is /media/cdrom. The following procedure installs the ndiswrapper DEB that had previously been copied to a disk.:
1. Insert the CD-ROM, check the files in the /media/cdrom directory and then install the DEB.
root@u-bigboy:/tmp# mount /media/cdrom -o unhide mount: block device /dev/hdc is write-protected, mounting read-only root@u-bigboy:/tmp# cd /media/cdrom root@u-bigboy:/media/cdrom# ls ndiswrapper-utils_1.8-ubuntu2_i386.deb root@u-bigboy:/media/cdrom# dpkg --install ndiswrapper-utils_1.8-ubuntu2_i386.deb Selecting previously deselected package ndiswrapper-utils. (Reading database ... 70221 files and directories currently installed.) Unpacking ndiswrapper-utils (from ndiswrapper-utils_1.8-0ubuntu2_i386.deb) ... Setting up ndiswrapper-utils (1.8-0ubuntu2) ... root@u-bigboy:~#
2. When finished, eject the CD-ROM
root@u-bigboy:/media/cdrom# cd /tmp root@u-bigboy:/tmp# umount /media/cdrom root@u-bigboy:/tmp# eject cdrom root@u-bigboy:/tmp#
Note: Unlike the Fedora CD / DVD sets, Ubuntu Linux is distributed on a single CD / DVD. The Ubuntu installation process downloads any additional packages it may need on demand from the Internet. It is for this reason that you may find it easier to install Ubuntu software using the APT utility which automatically download and install most of the packages you desire. The APT utility is covered in a following section.
One of the most universally performed tasks by Linux systems administrators is the downloading of software. It is usually very simple to do and the most commonly used methods are covered in this section.
Getting Software Using Web-Based FTP
There are numerous Web sites that provide links to software you can download. The methodology to get the software is usually the same for all:
- Browse the desired Web site until you find the link to the software package you need.
- Click on the link for the desired software package.
- Save the file to your hard drive
Some web browsers, such as Firefox, will automatically download the file to your desktop, but where is the desktop? In Linux, your desktop is usually a sub-directory named Desktop located in your home or ~ directory. Here we see that the root user's desktop already contains a downloaded RPM file.
[root@bigboy tmp]# cd ~/Desktop/ [root@bigboy Desktop]# ls ElectricFence-2.2.2-20.2.i386.rpm [root@bigboy Desktop]# pwd /root/Desktop [root@bigboy Desktop]#
Getting RPMs Using Command-Line Anonymous FTP
The Web based method above transparently uses anonymous File Transfer Protocol (FTP). Anonymous FTP allows you to log in and download files from a FTP server using the username anonymous or the shorter username ftp and a password that matches your e-mail address. This way anyone can access the data. Let's illustrate this with an example of using anonymous FTP to download the SSH package from download.fedora.redhat.com:
1) First we issue the FTP command targeting download.fedora.redhat.com at the command line.
[root@bigboy tmp]# ftp download.fedora.redhat.com Trying 18.104.22.168... Connected to download.fedora.redhat.com (22.214.171.124). 220 Fedora FTP server ready. All transfers are logged. Name (download.fedora.redhat.com:root): anonymous 331 Please specify the password. Password: 230 Login successful. Have fun. Using binary mode to transfer files. ftp> pwd 257 "/" ftp> ls 227 Entering Passive Mode (66,187,232,35,57,155) 150 Here comes the directory listing. drwxr-xr-x 3 ftp ftp 4096 Oct 29 15:59 pub 226 Directory send OK. ftp>
2) After we've logged in, we can use the help command to see what options we have at our disposal.
ftp> help Commands may be abbreviated. Commands are: ! cr mdir proxy send $ delete mget sendport site account debug mkdir put size append dir mls pwd status ascii disconnect mode quit struct bell form modtime quote system binary get mput recv sunique bye glob newer reget tenex case hash nmap rstatus trace ccc help nlist rhelp type cd idle ntrans rename user cdup image open reset umask chmod lcd passive restart verbose clear ls private rmdir ? close macdef prompt runique cprotect mdelete protect safe ftp>
The commands you'll most likely use are listed in Table 6-2:
Table 6-2 FTP Commands
|binary||Copy files in binary mode|
|cd||Change directory on the FTP server|
|dir||List the names of the files in the current remote directory|
|get||Get a file from the FTP server|
|lcd||Change the directory on the local machine|
|ls||Same as dir|
|mget||Same as get, but you can use wildcards like "*"|
|mput||Same as put, but you can use wildcards like "*"|
|passive||Make the file transfer passive mode|
|put||Put a file from the local machine onto the FTP server|
|pwd||Give the directory name on the local machine|
3) By using the Web browsing feature on the Web site ahead of time, I know that the Fedora Core 2 RPMs are located in the pub/fedora/linux/core/2/i386/os/Fedora/RPMS/ directory and will use the cd command to change my directory to there. We can use the ls command to get a listing of files in this directory.
ftp> cd pub/fedora/linux/core/2/i386/os/Fedora/RPMS/ 250 Directory successfully changed. ftp> ls open* 227 Entering Passive Mode (66,187,232,35,58,3) 150 Here comes the directory listing. ... ... -rw-r--r-- ... ... 184281 Oct 28 23:29 openssh-3.6.1p2-34.i386.rpm ... ... 226 Directory send OK. ftp>
4) Next we get the file we need and place it in the local directory /usr/rpm. The hash command will print "#" hash signs on the screen during the download.
ftp> hash Hash mark printing on (1024 bytes/hash mark). ftp> lcd /usr/rpm Local directory now /usr/rpm ftp> get openssh-3.6.1p2-34.i386.rpm local: openssh-3.6.1p2-34.i386.rpm remote: openssh-3.6.1p2-34.i386.rpm 227 Entering Passive Mode (66,187,232,35,58,25) 150 Opening BINARY mode data connection for openssh-3.6.1p2-34.i386.rpm (184281 bytes). ################################################################################################################################################################################### 226 File send OK. 184281 bytes received in 3.41 secs (53 Kbytes/sec) ftp>
Note: You can also use wildcards to download the RPMs you need using the mget command. You'll be prompted for each of the matching RPM files. In the next example, we just aborted this download by typing n.
ftp> mget openssh-3.6* mget openssh-3.6.1p2-34.i386.rpm? n ftp>
5) Finally we use the exit command to leave FTP.
ftp> exit 221 Goodbye. root@bigboy tmp]#
Getting Software Using wget
The wget command can be used to download files quickly when you already know the URL at which the RPM is located. This is especially convenient if you are logged into your Linux box from another machine running a Web browser. You can browse the download site for the RPM you need, right click on the desired link and select copy shortcut (Windows) or Copy Link Location (Linux). After you have done this, you can then select your SSH/telnet/Linux Terminal login window and type in the command wget URL. Here is an example downloading a DHCP update from Fedora.
[root@bigboy tmp]# wget http://linux.stanford.edu/pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS/dhcp-3.0pl2-6.16.i386.rpm --17:38:36-- ftp://linux.stanford.edu/pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS/dhcp-3.0pl2-6.16.i386.rpm => `dhcp-3.0pl2-6.16.i386.rpm.5' Resolving linux.stanford.edu... done. Connecting to linux.stanford.edu[126.96.36.199]:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD /pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS ... done. ==> PASV ... done. ==> RETR dhcp-3.0pl2-6.16.i386.rpm ... done. Length: 529,890 (unauthoritative) 100%[===============================>] 529,890 889.12K/s ETA 00:00 17:38:36 (889.12 KB/s) - `dhcp-3.0pl2-6.16.i386.rpm.5' saved  [root@bigboy tmp]#